diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-02-27 14:47:23 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-02-27 14:47:23 +0100 |
| commit | dab9efb7b745fe884fb72017591dce95978c19c4 (patch) | |
| tree | 67de56f79c67a29f3b916593c8f2ee4ebd5df45d /src/fractals | |
| parent | 7a5632ab67f95c561ce22a19352e963af3077a5b (diff) | |
| download | fractol-dab9efb7b745fe884fb72017591dce95978c19c4.tar.gz fractol-dab9efb7b745fe884fb72017591dce95978c19c4.tar.bz2 fractol-dab9efb7b745fe884fb72017591dce95978c19c4.zip | |
Diffstat (limited to 'src/fractals')
| -rw-r--r-- | src/fractals/burningship.c | 32 | ||||
| -rw-r--r-- | src/fractals/julia.c | 38 | ||||
| -rw-r--r-- | src/fractals/mandelbrot.c | 34 | ||||
| -rw-r--r-- | src/fractals/tricorn.c | 32 |
4 files changed, 61 insertions, 75 deletions
diff --git a/src/fractals/burningship.c b/src/fractals/burningship.c index fb950ed..07baf38 100644 --- a/src/fractals/burningship.c +++ b/src/fractals/burningship.c @@ -6,37 +6,33 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 16:15:49 by cacharle #+# #+# */ -/* Updated: 2020/02/26 13:20:36 by cacharle ### ########.fr */ +/* Updated: 2020/02/27 12:25:24 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "fractol.h" -#define BURNING_SHIP_MAX_ITERATION 20 -#define BURNING_SHIP_ESCAPE_RADIUS_SQUARED 4 +#define BURNING_SHIP_ESCAPE_RADIUS_SQUARED 4.0 -int burningship(t_state *state, t_complex z) +int burningship(t_state *state, t_complex c) { - int n; - double zr; - double zi; - double zr_square; - double zi_square; - double tmp; + int n; + t_complex z; + t_complex z_square; + double tmp; (void)state; - zr = z.r; - zi = z.i; + z = c; n = -1; while (++n < state->iterations) { - zi_square = zi * zi; - zr_square = zr * zr; - if (zr_square + zi_square > BURNING_SHIP_ESCAPE_RADIUS_SQUARED) + z_square.i = z.i * z.i; + z_square.r = z.r * z.r; + if (z_square.r + z_square.i > BURNING_SHIP_ESCAPE_RADIUS_SQUARED) break; - tmp = zr_square - zi_square + z.r; - zi = fabs(2.0 * zr * zi + z.i); - zr = fabs(tmp); + tmp = z_square.r - z_square.i + z.r; + z.i = fabs(2.0 * z.r * z.i + c.i); + z.r = fabs(tmp); } return (n); } diff --git a/src/fractals/julia.c b/src/fractals/julia.c index 8474bb8..a91731c 100644 --- a/src/fractals/julia.c +++ b/src/fractals/julia.c @@ -6,36 +6,34 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 15:17:38 by cacharle #+# #+# */ -/* Updated: 2020/02/25 07:33:43 by cacharle ### ########.fr */ +/* Updated: 2020/02/27 13:44:21 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "fractol.h" -#define JULIA_MAX_ITERATION 20 -#define JULIA_ESCAPE_RADIUS_SQUARED 100 +#define JULIA_ESCAPE_RADIUS_SQUARED 4.0 -int julia(t_state *state, t_complex z) +int julia(t_state *state, t_complex origin_c) { - int n; - double zr; - double zi; - double zr_square; - double zi_square; + int n; + t_complex z; + t_complex z_square; + t_complex c; - zr = z.r; - zi = z.i; + z = origin_c; + c = state->c; + z_square.r = 0.0; + z_square.i = 0.0; n = -1; - while (++n < state->iterations) + while (z_square.r + z_square.i <= JULIA_ESCAPE_RADIUS_SQUARED && ++n < state->iterations) { - 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->c.i; - zr += state->c.r; + z_square.i = z.i * z.i; + z_square.r = z.r * z.r; + z.i = 2.0 * z.r * z.i; + z.r = z_square.r - z_square.i; + z.i += c.i; + z.r += c.r; } return (n); } diff --git a/src/fractals/mandelbrot.c b/src/fractals/mandelbrot.c index 662ea25..312fc71 100644 --- a/src/fractals/mandelbrot.c +++ b/src/fractals/mandelbrot.c @@ -6,37 +6,33 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 11:07:41 by cacharle #+# #+# */ -/* Updated: 2020/02/26 13:12:55 by cacharle ### ########.fr */ +/* Updated: 2020/02/27 14:18:16 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "fractol.h" -#define MANDEL_MAX_ITERATION 20 -#define MANDEL_ESCAPE_RADIUS_SQUARED 4 +#define MANDEL_ESCAPE_RADIUS_SQUARED 4.0 int mandelbrot(t_state *state, t_complex c) { - int n; - double zr; - double zi; - double zr_square; - double zi_square; + int n; + t_complex z; + t_complex z_square; (void)state; - zr = c.r; - zi = c.i; + z = c; n = -1; - while (++n < state->iterations) + z_square.r = 0.0; + z_square.i = 0.0; + while (z_square.r + z_square.i <= MANDEL_ESCAPE_RADIUS_SQUARED && ++n < state->iterations) { - zi_square = zi * zi; - zr_square = zr * zr; - if (zr_square + zi_square > MANDEL_ESCAPE_RADIUS_SQUARED) - break; - zi = 2.0 * zr * zi; - zr = zr_square - zi_square; - zi += c.i; - zr += c.r; + z_square.i = z.i * z.i; + z_square.r = z.r * z.r; + z.i = 2.0 * z.r * z.i; + z.r = z_square.r - z_square.i; + z.i += c.i; + z.r += c.r; } return (n); } diff --git a/src/fractals/tricorn.c b/src/fractals/tricorn.c index 052cc2f..2abe01b 100644 --- a/src/fractals/tricorn.c +++ b/src/fractals/tricorn.c @@ -6,37 +6,33 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 16:00:46 by cacharle #+# #+# */ -/* Updated: 2020/02/25 07:34:01 by cacharle ### ########.fr */ +/* Updated: 2020/02/27 12:24:35 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "fractol.h" -#define TRICORN_MAX_ITERATION 20 -#define TRICORN_ESCAPE_RADIUS_SQUARED 100 +#define TRICORN_ESCAPE_RADIUS_SQUARED 4.0 -int tricorn(t_state *state, t_complex z) +int tricorn(t_state *state, t_complex c) { - int n; - double zr; - double zi; - double zr_square; - double zi_square; - double tmp; + int n; + t_complex z; + t_complex z_square; + double tmp; (void)state; - zr = z.r; - zi = z.i; + z = c; n = -1; while (++n < state->iterations) { - zi_square = zi * zi; - zr_square = zr * zr; - if (zr_square + zi_square > TRICORN_ESCAPE_RADIUS_SQUARED) + z_square.i = z.i * z.i; + z_square.r = z.r * z.r; + if (z_square.r + z_square.i > TRICORN_ESCAPE_RADIUS_SQUARED) break; - tmp = zr_square - zi_square + z.r; - zi = -2.0 * zr * zi + z.i; - zr = tmp; + tmp = z_square.r - z_square.i + z.r; + z.i = -2.0 * z.r * z.i + c.i; + z.r = tmp; } return (n); } |
