/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */
-/* Updated: 2024/04/18 09:54:31 by ljiriste ### ########.fr */
+/* Updated: 2024/04/18 11:49:18 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
return ;
}
-t_color get_color(t_session *s, int x, int y)
+void process_pixel_group(t_session *s, int x, int y)
{
- double palette_param;
+ int i;
+ int j;
+ double param;
if (!*(bool *)ft_mat_access(&s->img.calced, y, x))
- {
- palette_param = s->view.fractal(&s->set,
+ param = s->view.fractal(&s->set,
s->view.window_coord.x + s->view.pixel_size.x * x,
s->view.window_coord.y - s->view.pixel_size.y * y);
- return (s->view.palette(palette_param));
- }
else
- {
- return (get_img_pixel_color(&s->img, x, y));
- }
-}
-
-void process_pixel_group(t_session *s, int x, int y)
-{
- int i;
- int j;
- t_color color;
-
- color = get_color(s, x, y);
+ param = *(double *)ft_mat_access(&s->img.base, y, x);
i = 0;
while (i < s->img.undersample && x + i < s->img.width)
{
while (j < s->img.undersample && y + j < s->img.height)
{
if (!*(bool *)ft_mat_access(&s->img.calced, y + j, x + i))
- ft_putpx_img(&s->img, x + i, y + j, color);
+ *(double *)ft_mat_access(&s->img.base, y + j, x + i) = param;
++j;
}
++i;
return ;
}
-void draw_fractal(t_session *s)
+void calculate_base(t_session *s)
{
int x;
int y;
}
x += s->img.undersample;
}
+}
+
+void draw_fractal(t_session *s)
+{
+ int x;
+ int y;
+ double param;
+
+ x = 0;
+ while (x < s->img.width)
+ {
+ y = 0;
+ while (y < s->img.height)
+ {
+ param = *(double *)ft_mat_access(&s->img.base, y, x);
+ if (param >= 0)
+ param = fmod(param + s->view.color_shift, 1.);
+ ft_putpx_img(&s->img, x, y, s->view.palette(param));
+ ++y;
+ }
+ ++x;
+ }
mlx_put_image_to_window(s->mlx, s->win, s->img.img, 0, 0);
+ return ;
}
void erase_calced(t_mat *calced)
{
int x;
int y;
- t_color color;
x = 0;
if (delta_x < 0)
if (0 <= x - delta_x && x - delta_x < img->width &&
0 <= y - delta_y && y - delta_y < img->height)
{
- color = get_img_pixel_color(img, x, y);
- ft_putpx_img(img, x - delta_x, y - delta_y, color);
+ *(double *)ft_mat_access(&img->base, y - delta_y, x - delta_x)
+ = *(double *)ft_mat_access(&img->base, y, x);
*(bool *)ft_mat_access(&img->calced, y - delta_y, x - delta_x) =
*(bool *)ft_mat_access(&img->calced, y, x);
}
return ;
}
-// Something like this function should be added to Libft
-// with maybe additional argument (void *) of the filler
-t_arr_stat construct_mat(t_mat *mat, size_t rows, size_t cols)
-{
- t_vec filler_vec;
- bool filler;
- size_t i;
- t_arr_stat res;
-
- filler = false;
- ft_vec_init(&filler_vec, sizeof(bool));
- i = 0;
- while (i < cols)
- {
- ft_vec_append(&filler_vec, &filler);
- ++i;
- }
- res = ft_mat_insert_row(mat, &filler_vec, rows - 1);
- ft_vec_free(&filler_vec, NULL);
- return (res);
-}
-
void init_session(t_session *s)
{
s->mlx = mlx_init();
s->img.img = mlx_new_image(s->mlx, s->img.width, s->img.height);
s->img.addr = mlx_get_data_addr(s->img.img, &s->img.bpp, &s->img.bpl, &s->img.endian);
ft_mat_init(&s->img.calced, sizeof(bool));
- construct_mat(&s->img.calced, s->img.height, s->img.width);
+ ft_mat_init(&s->img.base, sizeof(double));
+ ft_mat_zeros(&s->img.calced, s->img.height, s->img.width);
+ ft_mat_zeros(&s->img.base, s->img.height, s->img.width);
s->img.undersample = s->img.undersample_max;
}
s->view.palette = tri_color;
s->view.pixel_size.x = 0.01;
s->view.pixel_size.y = 0.01;
+ s->view.color_shift = 0.7;
+ s->view.color_shift_speed = 0.01;
s->view.window_coord.x = -s->img.width / 2 * s->view.pixel_size.x;
s->view.window_coord.y = s->img.height / 2 * s->view.pixel_size.y;
return ;
void cleanup(t_session *s)
{
ft_mat_free(&s->img.calced, NULL);
+ ft_mat_free(&s->img.base, NULL);
mlx_destroy_image(s->mlx, s->img.img);
free_session(s);
+ return ;
}
int main(int argc, char **argv)