/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 19:35:01 by ljiriste #+# #+# */
-/* Updated: 2024/04/25 14:13:46 by ljiriste ### ########.fr */
+/* Updated: 2024/04/26 09:38:15 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#define SHIFT_MULT 1.2
#define SHIFT_THRESH 0.0001
+void redraw(t_session *s)
+{
+ erase_calced(&s->img.calced);
+ s->img.undersample = s->img.undersample_max;
+ return ;
+}
+
void change_shift_speed(double *speed, double mult, double thresh)
{
if (-thresh < *speed && *speed < thresh)
return ;
}
-
static void additional_keys(int keycode, t_session *s)
{
if (keycode == XK_KP_Multiply)
if (s->set.detail * DETAIL_MULT > s->set.detail)
{
s->set.detail *= DETAIL_MULT;
- erase_calced(&s->img.calced);
- s->img.undersample = s->img.undersample_max;
+ redraw(s);
}
}
else if (keycode == XK_KP_Divide)
if (s->set.detail >= DETAIL_MULT)
{
s->set.detail /= DETAIL_MULT;
- erase_calced(&s->img.calced);
- s->img.undersample = s->img.undersample_max;
+ redraw(s);
}
}
else if (keycode == XK_KP_Up)
- change_shift_speed(&s->view.color_shift_speed, SHIFT_MULT, SHIFT_THRESH);
+ change_shift_speed(&s->view.color_shift_speed,
+ SHIFT_MULT, SHIFT_THRESH);
else if (keycode == XK_KP_Down)
- change_shift_speed(&s->view.color_shift_speed, -SHIFT_MULT, SHIFT_THRESH);
+ change_shift_speed(&s->view.color_shift_speed,
+ -SHIFT_MULT, SHIFT_THRESH);
}
int handle_key_press(int keycode, t_session *s)
else if (keycode == XK_Right || keycode == XK_d)
move_view(s, MOVE_AMOUNT, 0);
else if (keycode == XK_KP_Add)
- change_zoom(s, (t_vect2){.x = s->img.width / 2, .y = s->img.height / 2}, ZOOM_IN);
+ 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);
+ 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);
- s->img.undersample = s->img.undersample_max;
- }
+ redraw(s);
else
additional_keys(keycode, s);
if (keycode != XK_Escape)
calculate_base(s);
}
draw_fractal(s);
- s->view.color_shift = fmod(s->view.color_shift + s->view.color_shift_speed, 1.);
+ s->view.color_shift
+ = fmod(s->view.color_shift + s->view.color_shift_speed, 1.);
if (s->view.color_shift < 0)
s->view.color_shift += 1;
}
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */
-/* Updated: 2024/04/26 08:52:24 by ljiriste ### ########.fr */
+/* Updated: 2024/04/26 09:41:56 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
void draw_fractal(t_session *s)
{
- int x;
- int y;
+ int x;
+ int y;
double param;
x = 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)
+ if (0 <= x - delta_x && x - delta_x < img->width
+ && 0 <= y - delta_y && y - delta_y < img->height)
{
*(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);
}
- if (!(0 <= x + delta_x && x + delta_x < img->width &&
- 0 <= y + delta_y && y + delta_y < img->height))
+ 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, y, x) = false;
y += 1 - 2 * (delta_y < 0);
}
s->mlx = mlx_init();
s->win = mlx_new_window(s->mlx, s->img.width, s->img.height, "Fract-ol");
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);
+ 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));
ft_mat_init(&s->img.base, sizeof(double));
ft_mat_zeros(&s->img.calced, s->img.height, s->img.width);
int parse_arg(char **argv, t_session *s, int *i)
{
- if (!ft_strcmp(argv[*i], "-w") && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
- s->img.width = ft_atoi(argv[++*i]);
- else if (!ft_strcmp(argv[*i], "-h") && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
- s->img.height = ft_atoi(argv[++*i]);
- else if (!ft_strcmp(argv[*i], "-u") && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i]) >= 0 )
- s->img.undersample_max = ft_atoi(argv[++*i]);
- else if (!ft_strcmp(argv[*i], "-d") && ft_isint(argv[*i + 1]))
- s->set.detail = ft_atoi(argv[++*i]);
- else if (!ft_strcmp(argv[*i], "-f") && to_fractal(argv[*i + 1]) != NULL)
- s->view.fractal = to_fractal(argv[++*i]);
- else if (!ft_strcmp(argv[*i], "-s") && ft_isint(argv[*i + 1]))
- s->view.color_shift_speed = ft_atoi(argv[++*i]) / 1000.;
- else if (!ft_strcmp(argv[*i], "-c") && ft_isint(argv[*i + 1]))
- s->set.color_stability = 10000 / ft_atoi(argv[++*i]);
- else if (!ft_strcmp(argv[*i], "-i") && is_correct_input(argv[*i + 1], s->view.fractal))
- s->set.input = parse_input(argv[++*i], s->view.fractal);
- else
- return (1);
- return (0);
+ if (!ft_strcmp(argv[*i], "-w")
+ && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
+ s->img.width = ft_atoi(argv[++*i]);
+ else if (!ft_strcmp(argv[*i], "-h")
+ && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
+ s->img.height = ft_atoi(argv[++*i]);
+ else if (!ft_strcmp(argv[*i], "-u")
+ && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) >= 0)
+ s->img.undersample_max = ft_atoi(argv[++*i]);
+ else if (!ft_strcmp(argv[*i], "-d") && ft_isint(argv[*i + 1]))
+ s->set.detail = ft_atoi(argv[++*i]);
+ else if (!ft_strcmp(argv[*i], "-f") && to_fractal(argv[*i + 1]) != NULL)
+ s->view.fractal = to_fractal(argv[++*i]);
+ else if (!ft_strcmp(argv[*i], "-s") && ft_isint(argv[*i + 1]))
+ s->view.color_shift_speed = ft_atoi(argv[++*i]) / 1000.;
+ else if (!ft_strcmp(argv[*i], "-c") && ft_isint(argv[*i + 1]))
+ s->set.color_stability = 10000 / ft_atoi(argv[++*i]);
+ else if (!ft_strcmp(argv[*i], "-i")
+ && is_correct_input(argv[*i + 1], s->view.fractal))
+ s->set.input = parse_input(argv[++*i], s->view.fractal);
+ else
+ return (1);
+ return (0);
}
int parse_args(int argc, char **argv, t_session *s)
return (0);
}
-static const char *help_str =
- "This is the help for fractol by Lukáš Jiřiště\n"
- "You can call the program as follows:\n\n"
- "fractol -f <fractal name> [<option> <value>]\n"
- "\nOptions:\n"
- "\t-f\tOne of these fractals:\n"
- "\t\t\tman[delbrot]\n"
- "\t\t\ttri[corn]\n"
- "\t\t\tju[lia]\n"
- "\t-w\tWidth of window in pixels\n"
- "\t-h\tHeight of window in pixels\n"
- "\t-u\tMaximum undersample in pixels\n"
- "\t-d\tDetail in maximum iterations\n"
- "\t-i\tInput for selected fractal.\n"
- "\t\t\tmandelbrot\t- no input\n"
- "\t\t\ttricorn\t\t- no input\n"
- "\t\t\tjulia\t\t- a complex number in the form real,complex\n"
- "\t\t\t\t\t- the complex number will be divided by 1000 after input\n"
- "\t-s\tSpeed of color change (negative values reverse the direction)\n"
- "\t-c\tColorfulness\n"
- "\nControls:\n"
- "\tArrow keys and wasd can be used for movement.\n"
- "\tOne can zoom in with + and zoom out with - keypad.\n"
- "\tZoom can also be controlled with scrollwheel on the mouse.\n"
- "\tThe detail is controlled by * (increase) and / (decrease) keys.\n"
- "\tThe color change can be sped up and down with 8 and 2 keys.\n";
-
void print_help(void)
{
- ft_printf(help_str);
- return ;
+ ft_printf("This is the help for fractol by Lukáš Jiřiště\n"
+ "You can call the program as follows:\n\n"
+ "fractol -f <fractal name> [<option> <value>]\n"
+ "\nOptions:\n"
+ "\t-f\tOne of these fractals:\n"
+ "\t\t\tman[delbrot]\n"
+ "\t\t\ttri[corn]\n"
+ "\t\t\tju[lia]\n"
+ "\t-w\tWidth of window in pixels\n"
+ "\t-h\tHeight of window in pixels\n"
+ "\t-u\tMaximum undersample in pixels\n"
+ "\t-d\tDetail in maximum iterations\n"
+ "\t-i\tInput for selected fractal.\n"
+ "\t\t\tmandelbrot\t- no input\n"
+ "\t\t\ttricorn\t\t- no input\n"
+ "\t\t\tjulia\t\t- a complex number in the form real,complex\n"
+ "\t\t\t\t\t- the complex number will be divided by 1000 after input\n"
+ "\t-s\tSpeed of color change (negative values reverse the direction)\n"
+ "\t-c\tColorfulness\n"
+ "\nControls:\n"
+ "\tArrow keys and wasd can be used for movement.\n"
+ "\tOne can zoom in with + and zoom out with - keypad.\n"
+ "\tZoom can also be controlled with scrollwheel on the mouse.\n"
+ "\tThe detail is controlled by * (increase) and / (decrease) keys.\n"
+ "\tThe color change can be sped up and down with 8 and 2 keys.\n");
}
void cleanup(t_session *s)