aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/fractol.h33
-rw-r--r--src/event.c6
-rw-r--r--src/fractals/burningship.c4
-rw-r--r--src/fractals/julia.c4
-rw-r--r--src/fractals/mandelbrot.c4
-rw-r--r--src/fractals/tricorn.c4
-rw-r--r--src/render.c10
-rw-r--r--src/state.c59
8 files changed, 96 insertions, 28 deletions
diff --git a/include/fractol.h b/include/fractol.h
index 04e6336..c801576 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 16:18:44 by cacharle ### ########.fr */
+/* Updated: 2020/02/25 08:35:52 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,16 +23,30 @@
# include "libft_math.h"
# define WINDOW_TITLE "fractol"
-# define WINDOW_WIDTH 640
-# define WINDOW_HEIGHT 480
-# define WINDOW_WIDTH_DOUBLE 640.0
-# define WINDOW_HEIGHT_DOUBLE 480.0
+
+# define FRACTOL_RESOLUTION_MEDIUM
+
+# ifdef FRACTOL_RESOLUTION_HIGH
+# define WINDOW_WIDTH 1600
+# define WINDOW_HEIGHT 1200
+# elif defined(FRACTOL_RESOLUTION_MEDIUM)
+# define WINDOW_WIDTH 1024
+# define WINDOW_HEIGHT 768
+# else
+# define FRACTOL_RESOLUTION_LOW
+# define WINDOW_WIDTH 800
+# define WINDOW_HEIGHT 600
+# endif
+// # define WINDOW_WIDTH_DOUBLE 640.0
+// # define WINDOW_HEIGHT_DOUBLE 480.0
# define MLXK_ESC 53
# define MLXK_UP 126
# define MLXK_DOWN 125
# define MLXK_LEFT 123
# define MLXK_RIGHT 124
+# define MLXK_PLUS 24
+# define MLXK_MINUS 27
# define MLX_MOUSE_SCROLL_UP 5
# define MLX_MOUSE_SCROLL_DOWN 4
@@ -40,7 +54,7 @@
# define MLX_LITTLE_ENDIAN 0
# define MLX_BIG_ENDIAN 1
-# define PALETTE_SIZE 21
+# define PALETTE_SIZE 1024
typedef union
{
@@ -87,8 +101,15 @@ typedef struct s_state
t_complex center;
t_complex plane;
t_complex c;
+ int iterations;
} t_state;
+typedef struct
+{
+ t_state *state;
+ int offset;
+} t_render_routine_arg;
+
/*
** state.c
*/
diff --git a/src/event.c b/src/event.c
index e557435..2c59e9d 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 16:06:49 by cacharle ### ########.fr */
+/* Updated: 2020/02/25 07:35:38 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -34,6 +34,10 @@ int event_keydown(int key, t_state *state)
state->center.r -= state->plane.r * MOVE_SPEED;
else if (key == MLXK_RIGHT)
state->center.r += state->plane.r * MOVE_SPEED;
+ else if (key == MLXK_PLUS)
+ state->iterations++;
+ else if (key == MLXK_MINUS)
+ state->iterations--;
else
return (0);
state->updated = false;
diff --git a/src/fractals/burningship.c b/src/fractals/burningship.c
index aa27ab1..252da15 100644
--- a/src/fractals/burningship.c
+++ b/src/fractals/burningship.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 16:15:49 by cacharle #+# #+# */
-/* Updated: 2020/02/24 16:19:26 by cacharle ### ########.fr */
+/* Updated: 2020/02/25 07:33:53 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,7 +28,7 @@ int burningship(t_state *state, t_complex z)
zr = z.r;
zi = z.i;
n = -1;
- while (++n < BURNING_SHIP_MAX_ITERATION)
+ while (++n < state->iterations)
{
zi_square = zi * zi;
zr_square = zr * zr;
diff --git a/src/fractals/julia.c b/src/fractals/julia.c
index 136cf13..8474bb8 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 16:06:57 by cacharle ### ########.fr */
+/* Updated: 2020/02/25 07:33:43 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,7 +26,7 @@ int julia(t_state *state, t_complex z)
zr = z.r;
zi = z.i;
n = -1;
- while (++n < JULIA_MAX_ITERATION)
+ while (++n < state->iterations)
{
zi_square = zi * zi;
zr_square = zr * zr;
diff --git a/src/fractals/mandelbrot.c b/src/fractals/mandelbrot.c
index 5283fb5..92079d1 100644
--- a/src/fractals/mandelbrot.c
+++ b/src/fractals/mandelbrot.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 11:07:41 by cacharle #+# #+# */
-/* Updated: 2020/02/24 15:25:17 by cacharle ### ########.fr */
+/* Updated: 2020/02/25 07:33:35 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,7 +27,7 @@ int mandelbrot(t_state *state, t_complex z)
zr = z.r;
zi = z.i;
n = -1;
- while (++n < MANDEL_MAX_ITERATION)
+ while (++n < state->iterations)
{
zi_square = zi * zi;
zr_square = zr * zr;
diff --git a/src/fractals/tricorn.c b/src/fractals/tricorn.c
index b40260d..052cc2f 100644
--- a/src/fractals/tricorn.c
+++ b/src/fractals/tricorn.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 16:00:46 by cacharle #+# #+# */
-/* Updated: 2020/02/24 16:12:16 by cacharle ### ########.fr */
+/* Updated: 2020/02/25 07:34:01 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,7 +28,7 @@ int tricorn(t_state *state, t_complex z)
zr = z.r;
zi = z.i;
n = -1;
- while (++n < TRICORN_MAX_ITERATION)
+ while (++n < state->iterations)
{
zi_square = zi * zi;
zr_square = zr * zr;
diff --git a/src/render.c b/src/render.c
index 1b93c3a..925e0dc 100644
--- a/src/render.c
+++ b/src/render.c
@@ -6,12 +6,17 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 09:54:59 by cacharle #+# #+# */
-/* Updated: 2020/02/24 15:20:39 by cacharle ### ########.fr */
+/* Updated: 2020/02/25 08:42:34 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
+/* static void *st_render_routine(t_state *state) */
+/* { */
+/* return (NULL); */
+/* } */
+
static void st_render_fractal(t_state *state)
{
int offset;
@@ -19,6 +24,7 @@ static void st_render_fractal(t_state *state)
int j;
t_color color;
t_complex z;
+ /* pthread_t threads[WINDOW_HEIGHT */
color.hexcode = 0xffffff;
offset = 0;
@@ -30,7 +36,7 @@ static void st_render_fractal(t_state *state)
{
z.r = ((double)j / (double)WINDOW_WIDTH) * state->plane.r - (state->plane.r / 2.0) + state->center.r;
z.i = ((double)i / (double)WINDOW_HEIGHT) * state->plane.i - (state->plane.i / 2.0) + state->center.i;
- ((t_color*)state->window.data)[offset] = state->palette[state->func(state, z)];
+ ((t_color*)state->window.data)[offset] = state->palette[(int)(((double)state->func(state, z) / (double)state->iterations) * (double)PALETTE_SIZE) % PALETTE_SIZE];
offset++;
}
}
diff --git a/src/state.c b/src/state.c
index 589e6c3..23a722d 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 16:18:25 by cacharle ### ########.fr */
+/* Updated: 2020/02/25 08:42:51 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,20 +24,56 @@ static void st_state_init_palette(t_state *state)
int step_g;
int step_b;
int i;
+ t_color colors[5];
- tmp.hexcode = PALETTE_START;
- step_r = ft_abs((PALETTE_END >> 16) - (PALETTE_START >> 16) ) / PALETTE_SIZE;
- step_g = ft_abs(((PALETTE_END >> 8) & 0xff) - ((PALETTE_START >> 8) & 0xff)) / PALETTE_SIZE;
- step_b = ft_abs((PALETTE_END & 0xff) - (PALETTE_START & 0xff) ) / PALETTE_SIZE;
+ colors[0].hexcode = 0x0;
+ colors[1].hexcode = 0xffdf00;
+ /* colors[2].hexcode = 0xffffff; */
+ /* colors[3].hexcode = 0x0000ff; */
+ /* colors[4].hexcode = 0x000088; */
+
+ int c1 = 0;
+ int c2 = 1;
+ int block_size = PALETTE_SIZE / 2;
i = -1;
+ double colorDelta = 1.0 / (2 - 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;
- tmp.rgb.b += step_b;
+ double globalRel = (double)i / (PALETTE_SIZE - 1);
+ double localRel = (globalRel - c1 * colorDelta) / colorDelta;
+ if (i % block_size)
+ {
+ c1++;
+ c2++;
+ }
+ int dr = colors[c1].rgb.r - colors[c2].rgb.r;
+ int dg = colors[c1].rgb.g - colors[c2].rgb.g;
+ int db = colors[c1].rgb.b - colors[c2].rgb.b;
+
+ state->palette[i].rgb.r = (int)(colors[c1].rgb.r + localRel * dr);
+ state->palette[i].rgb.g = (int)(colors[c1].rgb.g + localRel * dg);
+ state->palette[i].rgb.b = (int)(colors[c1].rgb.b + localRel * db);
}
+
+
+
+
+
+
+
+ /* tmp.hexcode = PALETTE_START; */
+ /* step_r = ft_abs((PALETTE_END >> 16) - (PALETTE_START >> 16) ) / PALETTE_SIZE; */
+ /* step_g = ft_abs(((PALETTE_END >> 8) & 0xff) - ((PALETTE_START >> 8) & 0xff)) / PALETTE_SIZE; */
+ /* step_b = ft_abs((PALETTE_END & 0xff) - (PALETTE_START & 0xff) ) / PALETTE_SIZE; */
+ /* 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; */
+ /* tmp.rgb.b += step_b; */
+ /* } */
}
static int st_state_dispatch_func(t_state *state, char *fractal_name)
@@ -68,7 +104,7 @@ int state_init(t_state *state, char *fractal_name)
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)
+ 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;
@@ -81,6 +117,7 @@ int state_init(t_state *state, char *fractal_name)
state->center.i = 0.0;
state->plane.r = 4.0;
state->plane.i = 4.0;
+ state->iterations = 20;
st_state_init_palette(state);
state->updated = false;
return (0);