From 1987bca74aec7b8937e6cc69ebf9c584b0467bad Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 24 Feb 2020 16:14:24 +0100 Subject: Added tricorn fractal --- src/fractals/julia.c | 6 +++--- src/fractals/tricorn.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/fractals/tricorn.c (limited to 'src/fractals') diff --git a/src/fractals/julia.c b/src/fractals/julia.c index d1afb46..136cf13 100644 --- a/src/fractals/julia.c +++ b/src/fractals/julia.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 15:17:38 by cacharle #+# #+# */ -/* Updated: 2020/02/24 15:36:04 by cacharle ### ########.fr */ +/* Updated: 2020/02/24 16:06:57 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,8 +34,8 @@ int julia(t_state *state, t_complex z) break; zi = 2.0 * zr * zi; zr = zr_square - zi_square; - zi += state->julia_const.i; - zr += state->julia_const.r; + zi += state->c.i; + zr += state->c.r; } return (n); } diff --git a/src/fractals/tricorn.c b/src/fractals/tricorn.c new file mode 100644 index 0000000..b40260d --- /dev/null +++ b/src/fractals/tricorn.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* tricorn.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 16:00:46 by cacharle #+# #+# */ +/* Updated: 2020/02/24 16:12:16 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "fractol.h" + +#define TRICORN_MAX_ITERATION 20 +#define TRICORN_ESCAPE_RADIUS_SQUARED 100 + +int tricorn(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 < TRICORN_MAX_ITERATION) + { + zi_square = zi * zi; + zr_square = zr * zr; + if (zr_square + zi_square > TRICORN_ESCAPE_RADIUS_SQUARED) + break; + tmp = zr_square - zi_square + z.r; + zi = -2.0 * zr * zi + z.i; + zr = tmp; + } + return (n); +} -- cgit