aboutsummaryrefslogtreecommitdiff
path: root/src/fractals/burningship.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fractals/burningship.c')
-rw-r--r--src/fractals/burningship.c42
1 files changed, 42 insertions, 0 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);
+}