diff options
Diffstat (limited to 'src/state.c')
| -rw-r--r-- | src/state.c | 59 |
1 files changed, 48 insertions, 11 deletions
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); |
