From: Lukas Jiriste Date: Thu, 25 Apr 2024 07:32:56 +0000 (+0200) Subject: Fix halo around the fractals X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=1c7d569650cc4722ade2c03aa437d5644f871564;p=42%2Ffract-ol.git Fix halo around the fractals 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. --- diff --git a/fractals.c b/fractals.c index 3b04f84..ed428be 100644 --- a/fractals.c +++ b/fractals.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -15,6 +15,11 @@ #include "fractol.h" #include +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)); }