Add check to mandelbrot to for visual correctness
authorLukas Jiriste <ljiriste@student.42prague.com>
Wed, 17 Jan 2024 09:34:55 +0000 (10:34 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Wed, 17 Jan 2024 09:34:55 +0000 (10:34 +0100)
Coordinates too far from the fractal had incorrect color.

main.c

diff --git a/main.c b/main.c
index 4de99726358812917c48fbee6822520868ffdad6..f397d53c63a8dc89ac1237602c9e8cb2247528bf 100644 (file)
--- a/main.c
+++ b/main.c
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/10/27 14:29:26 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/01/16 14:31:25 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/01/17 10:29:34 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -79,6 +79,8 @@ double        mandelbrot(double x, double y, double resolution)
        count = 0;
        z.r = 0;
        z.i = 0;
+       if (complex_norm(c) > 4)
+               return (0.01);
        while (complex_norm(z) < threshold && count < 100 * resolution)
        {
                z = complex_add(complex_mul(z, z), c);