diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-02-24 16:14:24 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-02-24 16:14:24 +0100 |
| commit | 1987bca74aec7b8937e6cc69ebf9c584b0467bad (patch) | |
| tree | af79fd5153d9605488f6b0c7a3de988a09994f5e | |
| parent | c6f87a62b31325e91bc8c847de9b20647a9b1cd8 (diff) | |
| download | fractol-1987bca74aec7b8937e6cc69ebf9c584b0467bad.tar.gz fractol-1987bca74aec7b8937e6cc69ebf9c584b0467bad.tar.bz2 fractol-1987bca74aec7b8937e6cc69ebf9c584b0467bad.zip | |
Added tricorn fractal
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | include/fractol.h | 5 | ||||
| -rw-r--r-- | src/event.c | 8 | ||||
| -rw-r--r-- | src/fractals/julia.c | 6 | ||||
| -rw-r--r-- | src/fractals/tricorn.c | 42 | ||||
| -rw-r--r-- | src/main.c | 4 | ||||
| -rw-r--r-- | src/state.c | 13 |
7 files changed, 65 insertions, 18 deletions
@@ -6,7 +6,7 @@ # By: cacharle <marvin@42.fr> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/02/24 09:19:49 by cacharle #+# #+# # -# Updated: 2020/02/24 15:22:40 by cacharle ### ########.fr # +# Updated: 2020/02/24 16:09:04 by cacharle ### ########.fr # # # # **************************************************************************** # @@ -36,7 +36,8 @@ SRC_FILES = main.c \ state.c \ helper.c \ fractals/mandelbrot.c \ - fractals/julia.c + fractals/julia.c \ + fractals/tricorn.c SRC = $(addprefix $(SRC_DIR)/,$(SRC_FILES)) OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) diff --git a/include/fractol.h b/include/fractol.h index e315e6b..c55791a 100644 --- a/include/fractol.h +++ b/include/fractol.h @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 09:28:16 by cacharle #+# #+# */ -/* Updated: 2020/02/24 15:29:50 by cacharle ### ########.fr */ +/* Updated: 2020/02/24 16:09:21 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -86,7 +86,7 @@ typedef struct s_state t_func_fractal func; t_complex center; t_complex plane; - t_complex julia_const; + t_complex c; } t_state; /* @@ -117,6 +117,7 @@ int event_mouse_motion(int x, int y, t_state *state); int mandelbrot(t_state *state, t_complex z); int julia(t_state *state, t_complex z); +int tricorn(t_state *state, t_complex z); /* ** helper.c diff --git a/src/event.c b/src/event.c index 30b5c34..e557435 100644 --- a/src/event.c +++ b/src/event.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 09:52:35 by cacharle #+# #+# */ -/* Updated: 2020/02/24 15:38:06 by cacharle ### ########.fr */ +/* Updated: 2020/02/24 16:06:49 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,7 +68,7 @@ int event_mouse(int button, int x, int y, t_state *state) int event_mouse_motion(int x, int y, t_state *state) { - if (state->julia_const.r == NAN) + if (state->c.r == NAN) return (0); if (x < 0) x = 0; @@ -78,8 +78,8 @@ int event_mouse_motion(int x, int y, t_state *state) y = 0; if (y > WINDOW_HEIGHT - 1) y = WINDOW_HEIGHT - 1; - state->julia_const.r = ((double)x / (double)WINDOW_WIDTH) * 4.0 - 2.0; - state->julia_const.i = ((double)y / (double)WINDOW_HEIGHT) * 4.0 - 2.0; + state->c.r = ((double)x / (double)WINDOW_WIDTH) * 4.0 - 2.0; + state->c.i = ((double)y / (double)WINDOW_HEIGHT) * 4.0 - 2.0; state->updated = false; return (0); } 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 09:27:44 by cacharle #+# #+# */ -/* Updated: 2020/02/24 15:28:40 by cacharle ### ########.fr */ +/* Updated: 2020/02/24 16:10:23 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\n"); + ft_putstr("mandelbrot\njulia\ntricorn\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 40f3d00..b614851 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 15:26:58 by cacharle ### ########.fr */ +/* Updated: 2020/02/24 16:12:34 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,7 @@ static void st_state_init_palette(t_state *state) i = -1; while (++i < PALETTE_SIZE) { + /* tmp.rgb.r = (int)sqrt((double)i / PALETTE_SIZE);//tmp; */ state->palette[i] = tmp; tmp.rgb.r += step_r; tmp.rgb.g += step_g; @@ -46,14 +47,16 @@ static int st_state_dispatch_func(t_state *state, char *fractal_name) else if (ft_strcmp(fractal_name, "julia") == 0) { state->func = &julia; - state->julia_const.r = 0.0; - state->julia_const.i = 0.0; + state->c.r = 0.0; + state->c.i = 0.0; return (0); } + else if (ft_strcmp(fractal_name, "tricorn") == 0) + state->func = &tricorn; else return (-1); - state->julia_const.r = NAN; - state->julia_const.i = NAN; + state->c.r = NAN; + state->c.i = NAN; return (0); } |
