/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 19:35:01 by ljiriste #+# #+# */
-/* Updated: 2024/01/17 14:42:38 by ljiriste ### ########.fr */
+/* Updated: 2024/01/18 10:36:06 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
change_zoom(s, (t_vect2){.x = s->img.width / 2, .y = s->img.height / 2}, ZOOM_IN);
else if (keycode == XK_KP_Subtract)
change_zoom(s, (t_vect2){.x = s->img.width / 2, .y = s->img.height / 2}, ZOOM_OUT);
+ else if (keycode == XK_r)
+ erase_calced(&s->img.calced);
if (keycode != XK_Escape)
draw_fractal(s);
return (0);
*/
int no_event_handle(t_session *s)
{
- if (s->img.undersample > 1)
+ if (s && s->win && s->img.undersample > 1)
{
--s->img.undersample;
draw_fractal(s);
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:51:29 by ljiriste #+# #+# */
-/* Updated: 2024/01/18 08:41:34 by ljiriste ### ########.fr */
+/* Updated: 2024/01/18 10:11:39 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
void move_view(t_session *s, float move_amount_right, float move_amount_up);
int close_win(t_session *s);
+void erase_calced(t_mat *calced);
+
#endif
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */
-/* Updated: 2024/01/18 08:46:27 by ljiriste ### ########.fr */
+/* Updated: 2024/01/18 10:44:15 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
int close_win(t_session *s)
{
mlx_destroy_window(s->mlx, s->win);
+ s->win = NULL;
return (0);
}
mlx_put_image_to_window(s->mlx, s->win, s->img.img, 0, 0);
}
-void erase_calced(t_mat *mat)
+void erase_calced(t_mat *calced)
{
size_t i;
size_t j;
i = 0;
- while (i < mat->rows)
+ while (i < calced->rows)
{
j = 0;
- while (j < mat->cols)
+ while (j < calced->cols)
{
- *(bool *)ft_mat_access(mat, i, j) = false;
+ *(bool *)ft_mat_access(calced, i, j) = false;
++j;
}
++i;
return ;
}
+void move_img(t_img *img, int delta_x, int delta_y)
+{
+ int x;
+ int y;
+ t_color color;
+
+ x = 0;
+ if (delta_x < 0)
+ x = img->width - 1;
+ while (0 <= x && x < img->width)
+ {
+ y = 0;
+ if (delta_y < 0)
+ y = img->height - 1;
+ while (0 <= y && y < img->height)
+ {
+ 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);
+ *(bool *)ft_mat_access(&img->calced, x - delta_x, y - delta_y) =
+ *(bool *)ft_mat_access(&img->calced, x, y);
+ }
+ if (!(0 <= x + delta_x && x + delta_x < img->width &&
+ 0 <= y + delta_y && y + delta_y < img->height))
+ *(bool *)ft_mat_access(&img->calced, x, y) = false;
+ y += 1 - 2 * (delta_y < 0);
+ }
+ x += 1 - 2 * (delta_x < 0);
+ }
+ return ;
+}
+
// move_amount is ratio of move distance to length one can see
void move_view(t_session *s, float move_amount_right, float move_amount_up)
{
- s->view.window_coord.x += move_amount_right * s->img.height * s->view.pixel_size.x;
- s->view.window_coord.y += move_amount_up * s->img.height * s->view.pixel_size.y;
- erase_calced(&s->img.calced);
+ int x_pix_change;
+ int y_pix_change;
+
+ x_pix_change = round(move_amount_right * s->img.height);
+ y_pix_change = -round(move_amount_up * s->img.height);
+ s->view.window_coord.x += x_pix_change * s->view.pixel_size.x;
+ s->view.window_coord.y -= y_pix_change * s->view.pixel_size.y;
+ move_img(&s->img, x_pix_change, y_pix_change);
s->img.undersample = s->img.undersample_max;
return ;
}
{
if (argc == 0)
free(argv);
- s->img.width = 50;
- s->img.height = 50;
- s->img.undersample_max = 3;
+ s->img.width = 1000;
+ s->img.height = 1000;
+ s->img.undersample_max = 5;
return ;
}