aboutsummaryrefslogtreecommitdiff
path: root/src/state.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.c')
-rw-r--r--src/state.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/state.c b/src/state.c
index a02547b..4e6ee09 100644
--- a/src/state.c
+++ b/src/state.c
@@ -6,19 +6,20 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 09:58:01 by cacharle #+# #+# */
-/* Updated: 2020/02/26 18:08:49 by cacharle ### ########.fr */
+/* Updated: 2020/02/27 14:43:39 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
-void state_update_palette(t_state *state)
+void state_update_palette(t_state *state)
{
int i;
t_color_hsl hsl;
free(state->palette);
- if ((state->palette = malloc(sizeof(t_color) * (state->iterations + 1))) == NULL)
+ if ((state->palette = malloc(
+ sizeof(t_color) * (state->iterations + 1))) == NULL)
{
state->running = false;
return ;
@@ -40,7 +41,6 @@ void state_shift_palette(t_state *state)
t_color_hsl hsl;
int shift_size;
- /* printf("yo\n"); */
i = -1;
shift_size = 255 / state->iterations;
while (++i < state->iterations)
@@ -74,26 +74,28 @@ static int st_state_dispatch_func(t_state *state, char *fractal_name)
return (0);
}
-int state_init(t_state *state, char *fractal_name)
+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, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)) == NULL)
+ if ((state->window_ptr = mlx_new_window(state->mlx_ptr,
+ WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)) == NULL)
return (state_destroy(state));
state->window.width = WINDOW_WIDTH;
state->window.height = WINDOW_HEIGHT;
- if ((state->window.id = mlx_new_image(state->mlx_ptr, state->window.width, state->window.height)) == NULL)
+ if ((state->window.id = mlx_new_image(state->mlx_ptr,
+ state->window.width, state->window.height)) == NULL)
return (state_destroy(state));
- state->window.data = mlx_get_data_addr(state->window.id, &state->window.depth,
- &state->window.size_line, &state->window.endian);
+ state->window.data = (t_color*)mlx_get_data_addr(state->window.id,
+ &state->window.depth, &state->window.size_line, &state->window.endian);
state->running = true;
state->center.r = 0.0;
state->center.i = 0.0;
state->plane.r = 4.0;
state->plane.i = 4.0;
- state->iterations = 10;
+ state->iterations = 30;
state->palette = NULL;
state->samples = 1.0;
state_update_palette(state);
@@ -101,13 +103,13 @@ int state_init(t_state *state, char *fractal_name)
return (0);
}
-int state_destroy(t_state *state)
+int state_destroy(t_state *state)
{
if (state == NULL)
return (-1);
if (state->mlx_ptr != NULL && state->window.id != NULL)
- mlx_destroy_image(state->mlx_ptr, state->window.id);
+ mlx_destroy_image(state->mlx_ptr, state->window.id);
if (state->mlx_ptr != NULL && state->window_ptr != NULL)
- mlx_destroy_window(state->mlx_ptr, state->window_ptr);
- return (-1);
+ mlx_destroy_window(state->mlx_ptr, state->window_ptr);
+ return (-1);
}