aboutsummaryrefslogtreecommitdiff
path: root/src/fractals
diff options
context:
space:
mode:
Diffstat (limited to 'src/fractals')
-rw-r--r--src/fractals/julia.c41
-rw-r--r--src/fractals/mandelbrot.c7
2 files changed, 45 insertions, 3 deletions
diff --git a/src/fractals/julia.c b/src/fractals/julia.c
index e69de29..d1afb46 100644
--- a/src/fractals/julia.c
+++ b/src/fractals/julia.c
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* julia.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/24 15:17:38 by cacharle #+# #+# */
+/* Updated: 2020/02/24 15:36:04 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "fractol.h"
+
+#define JULIA_MAX_ITERATION 20
+#define JULIA_ESCAPE_RADIUS_SQUARED 100
+
+int julia(t_state *state, t_complex z)
+{
+ int n;
+ double zr;
+ double zi;
+ double zr_square;
+ double zi_square;
+
+ zr = z.r;
+ zi = z.i;
+ n = -1;
+ while (++n < JULIA_MAX_ITERATION)
+ {
+ zi_square = zi * zi;
+ zr_square = zr * zr;
+ if (zr_square + zi_square > JULIA_ESCAPE_RADIUS_SQUARED)
+ break;
+ zi = 2.0 * zr * zi;
+ zr = zr_square - zi_square;
+ zi += state->julia_const.i;
+ zr += state->julia_const.r;
+ }
+ return (n);
+}
diff --git a/src/fractals/mandelbrot.c b/src/fractals/mandelbrot.c
index 4211cfa..5283fb5 100644
--- a/src/fractals/mandelbrot.c
+++ b/src/fractals/mandelbrot.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 11:07:41 by cacharle #+# #+# */
-/* Updated: 2020/02/24 13:46:22 by cacharle ### ########.fr */
+/* Updated: 2020/02/24 15:25:17 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,7 @@
#define MANDEL_MAX_ITERATION 20
#define MANDEL_ESCAPE_RADIUS_SQUARED 100
-int mandelbrot(t_complex z)
+int mandelbrot(t_state *state, t_complex z)
{
int n;
double zr;
@@ -23,6 +23,7 @@ int mandelbrot(t_complex z)
double zr_square;
double zi_square;
+ (void)state;
zr = z.r;
zi = z.i;
n = -1;
@@ -31,7 +32,7 @@ int mandelbrot(t_complex z)
zi_square = zi * zi;
zr_square = zr * zr;
if (zr_square + zi_square > MANDEL_ESCAPE_RADIUS_SQUARED)
- return (n);
+ break;
zi = 2.0 * zr * zi;
zr = zr_square - zi_square;
zi += z.i;