Fix halo around the fractals
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 25 Apr 2024 07:32:56 +0000 (09:32 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 25 Apr 2024 07:32:56 +0000 (09:32 +0200)
This halo is caused by returning 0 instead of using the proper formula
for points too far from origin. Setting the return value for such
points to the value of on the inner border of the halo fixes this.

fractals.c

index 3b04f849db7c2f28b341f71dbe9b419a7570d69d..ed428be829331123c59bc9936161c2068cf7ca9f 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/12/05 19:57:50 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/01/19 13:43:01 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/25 09:30:49 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "fractol.h"
 #include <math.h>
 
+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.));
+}
+
 double general_julia(void *zeroth, double resolution,
                                                void (*tested_f)(void *), int (*is_over_thresh)(void *))
 {
@@ -43,7 +48,7 @@ double        mandelbrot(t_set_man *settings, double x, double y)
        z.r = x;
        z.i = y;
        if (complex_norm(c) > 4)
-               return (0);
+               return (normalize_count(1, 4, settings->color_stability));
        while (complex_norm(z) < 256 && count < settings->detail)
        {
                z = complex_add(complex_mul(z, z), c);
@@ -51,7 +56,7 @@ double        mandelbrot(t_set_man *settings, double x, double y)
        }
        if (count == settings->detail)
                return (-1);
-       return (fmod((double)(count + 1 - log(log(complex_norm(z)) / log(2)) / log(2)) / settings->color_stability, 1.));
+       return (normalize_count(count, complex_norm(z), settings->color_stability));
 }
 
 double tricorn(t_set_man *settings, double x, double y)
@@ -66,7 +71,7 @@ double        tricorn(t_set_man *settings, double x, double y)
        z.r = 0;
        z.i = 0;
        if (complex_norm(c) > 4)
-               return (0);
+               return (normalize_count(1, 4, settings->color_stability));
        while (complex_norm(z) < 256 && count < settings->detail)
        {
                z = complex_add(complex_mul(complex_conj(z), complex_conj(z)), c);
@@ -74,5 +79,5 @@ double        tricorn(t_set_man *settings, double x, double y)
        }
        if (count == settings->detail)
                return (-1);
-       return (fmod((double)(count + 1 - log(log(complex_norm(z)) / log(2)) / log(2)) / settings->color_stability, 1.));
+       return (normalize_count(count, complex_norm(z), settings->color_stability));
 }