Fix halo by tuning the fractal parameters
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 25 Apr 2024 09:15:59 +0000 (11:15 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 25 Apr 2024 09:15:59 +0000 (11:15 +0200)
I don't really know why the halo still lived but changing the
the number from which to count seems to resolve it.

event_handling.c
fractals.c

index 4b9d22eca59b84b8cb91f9e0ad855c3171e6f26e..95e72b8a6de4ccc5bd483b73cdfd4a1eb3cc87f6 100644 (file)
@@ -6,10 +6,11 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/12/05 19:35:01 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/04/18 11:47:43 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/25 10:35:46 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
+#include <math.h>
 #include <X11/X.h>
 #include <X11/keysym.h>
 #include <mlx.h>
@@ -70,7 +71,9 @@ int   no_event_handle(t_session *s)
                        calculate_base(s);
                }
                draw_fractal(s);
-               s->view.color_shift += s->view.color_shift_speed;
+               s->view.color_shift = fmod(s->view.color_shift + s->view.color_shift_speed, 1.);
+               if (s->view.color_shift < 0)
+                       s->view.color_shift += 1;
        }
        return (0);
 }
index 0cd8ffed7ee0eb655e86cc640ac2789f87a93307..069fc4cd160c11b80f9f20d72656ae5b6f9d8ce7 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/12/05 19:57:50 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/04/25 09:43:26 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/25 11:13:38 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -15,6 +15,8 @@
 #include "fractol.h"
 #include <math.h>
 
+#define THRESHOLD 256
+
 double normalize_count(int count, double norm, double color_stability)
 {
        return (fmod((double)(count + 1 - log(log(norm) / log(2)) / log(2)) / color_stability, 1.));
@@ -44,12 +46,12 @@ double      mandelbrot(t_set *settings, double x, double y)
 
        c.r = x;
        c.i = y;
-       count = 1;
+       count = 4;
        z.r = x;
        z.i = y;
-       if (complex_norm(c) > 4)
-               return (normalize_count(1, 4, settings->color_stability));
-       while (complex_norm(z) < 256 && count < settings->detail)
+       if (complex_norm(c) > THRESHOLD)
+               return (normalize_count(count, THRESHOLD, settings->color_stability));
+       while (complex_norm(z) <= THRESHOLD && count < settings->detail)
        {
                z = complex_add(complex_mul(z, z), c);
                ++count;
@@ -67,12 +69,12 @@ double      tricorn(t_set *settings, double x, double y)
 
        c.r = x;
        c.i = y;
-       count = 0;
+       count = 4;
        z.r = 0;
        z.i = 0;
-       if (complex_norm(c) > 4)
-               return (normalize_count(1, 4, settings->color_stability));
-       while (complex_norm(z) < 256 && count < settings->detail)
+       if (complex_norm(c) > THRESHOLD)
+               return (normalize_count(count + 1, THRESHOLD, settings->color_stability));
+       while (complex_norm(z) <= THRESHOLD && count < settings->detail)
        {
                z = complex_add(complex_mul(complex_conj(z), complex_conj(z)), c);
                ++count;