diff options
Diffstat (limited to 'src/state.c')
| -rw-r--r-- | src/state.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/state.c b/src/state.c index 33aa98b..40f3d00 100644 --- a/src/state.c +++ b/src/state.c @@ -6,16 +6,16 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 09:58:01 by cacharle #+# #+# */ -/* Updated: 2020/02/24 12:34:50 by cacharle ### ########.fr */ +/* Updated: 2020/02/24 15:26:58 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "fractol.h" -/* #define PALETTE_START 0x000022 */ -/* #define PALETTE_END 0xd62f2f */ -#define PALETTE_START 0x000000 -#define PALETTE_END 0xffffff +#define PALETTE_START 0x000022 +#define PALETTE_END 0xd62f2f +/* #define PALETTE_START 0x000000 */ +/* #define PALETTE_END 0xffffff */ static void st_state_init_palette(t_state *state) { @@ -39,10 +39,28 @@ static void st_state_init_palette(t_state *state) } } -int state_init(t_state *state, char *fractal_name) +static int st_state_dispatch_func(t_state *state, char *fractal_name) { - (void)fractal_name; + if (ft_strcmp(fractal_name, "mandelbrot") == 0) + state->func = &mandelbrot; + else if (ft_strcmp(fractal_name, "julia") == 0) + { + state->func = &julia; + state->julia_const.r = 0.0; + state->julia_const.i = 0.0; + return (0); + } + else + return (-1); + state->julia_const.r = NAN; + state->julia_const.i = NAN; + return (0); +} +int state_init(t_state *state, char *fractal_name) +{ + if (st_state_dispatch_func(state, fractal_name) < 0) + return (-1); if ((state->mlx_ptr = mlx_init()) == NULL) return (-1); if ((state->window_ptr = mlx_new_window(state->mlx_ptr, 640, 480, WINDOW_TITLE)) == NULL) @@ -54,13 +72,12 @@ int state_init(t_state *state, char *fractal_name) state->window.data = mlx_get_data_addr(state->window.id, &state->window.depth, &state->window.size_line, &state->window.endian); state->running = true; - state->func = &mandelbrot; - state->center.a = 0.0; - state->center.b = 0.0; - state->plane.a = 4.0; - state->plane.b = 4.0; - render_update_window_complex(state); + state->center.r = 0.0; + state->center.i = 0.0; + state->plane.r = 4.0; + state->plane.i = 4.0; st_state_init_palette(state); + state->updated = false; return (0); } |
