aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fractals/burningship.c42
-rw-r--r--src/main.c4
-rw-r--r--src/state.c4
3 files changed, 47 insertions, 3 deletions
diff --git a/src/fractals/burningship.c b/src/fractals/burningship.c
new file mode 100644
index 0000000..aa27ab1
--- /dev/null
+++ b/src/fractals/burningship.c
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* burningship.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/24 16:15:49 by cacharle #+# #+# */
+/* Updated: 2020/02/24 16:19:26 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "fractol.h"
+
+#define BURNING_SHIP_MAX_ITERATION 20
+#define BURNING_SHIP_ESCAPE_RADIUS_SQUARED 100
+
+int burningship(t_state *state, t_complex z)
+{
+ int n;
+ double zr;
+ double zi;
+ double zr_square;
+ double zi_square;
+ double tmp;
+
+ (void)state;
+ zr = z.r;
+ zi = z.i;
+ n = -1;
+ while (++n < BURNING_SHIP_MAX_ITERATION)
+ {
+ zi_square = zi * zi;
+ zr_square = zr * zr;
+ if (zr_square + zi_square > BURNING_SHIP_ESCAPE_RADIUS_SQUARED)
+ break;
+ tmp = zr_square - zi_square + z.r;
+ zi = fabs(2.0 * zr * zi + z.i);
+ zr = fabs(tmp);
+ }
+ return (n);
+}
diff --git a/src/main.c b/src/main.c
index 1c4d948..2d897e1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 09:27:44 by cacharle #+# #+# */
-/* Updated: 2020/02/24 16:10:23 by cacharle ### ########.fr */
+/* Updated: 2020/02/24 16:20:48 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,7 +18,7 @@ int main(int argc, char **argv)
if (argc != 2 || state_init(&state, argv[1]) < 0)
{
- ft_putstr("mandelbrot\njulia\ntricorn\n");
+ ft_putstr("mandelbrot\njulia\ntricorn\nburningship\n");
return (0);
}
mlx_hook(state.window_ptr, 17, 0, event_quit, (void*)&state);
diff --git a/src/state.c b/src/state.c
index b614851..589e6c3 100644
--- a/src/state.c
+++ b/src/state.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 09:58:01 by cacharle #+# #+# */
-/* Updated: 2020/02/24 16:12:34 by cacharle ### ########.fr */
+/* Updated: 2020/02/24 16:18:25 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -53,6 +53,8 @@ static int st_state_dispatch_func(t_state *state, char *fractal_name)
}
else if (ft_strcmp(fractal_name, "tricorn") == 0)
state->func = &tricorn;
+ else if (ft_strcmp(fractal_name, "burningship") == 0)
+ state->func = &burningship;
else
return (-1);
state->c.r = NAN;