-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_program.c
98 lines (97 loc) · 3.18 KB
/
init_program.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_program.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abdsalah <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/29 00:42:40 by abdsalah #+# #+# */
/* Updated: 2025/01/03 10:19:27 by abdsalah ### ########.fr */
/* */
/* ************************************************************************** */
#include "fract_ol.h"
/*
** ft_init_fractal
** ---------------
** Initializes the fractal structure with default values.
*/
void ft_init_fractal(t_fractal *fractal)
{
fractal->shift_x = 0.0;
fractal->shift_y = 0.0;
fractal->zoom = 1.0;
fractal->max_iter = MAX_ITER;
fractal->julia_re = -0.512511498387847167;
fractal->julia_im = 0.521295573094847167;
}
/*
** ft_init_graphics_struct
** -----------------------
** Initializes the graphics structure with NULL values.
*/
static void ft_init_graphics_struct(t_graphics *graphics)
{
graphics->mlx = NULL;
graphics->win = NULL;
graphics->img = NULL;
graphics->data = NULL;
graphics->bpp = 0;
graphics->line_len = 0;
graphics->endian = 0;
graphics->fractal = NULL;
}
/*
** ft_free_graphics
** ----------------
** intiliaze the graphics structure with the MLX connection, window, image
** and the data address for the image
** also set graphics->fractal pointer to the fractal structure.
*/
void ft_init_graphics(t_graphics *graphics, t_fractal *fractal)
{
ft_init_graphics_struct(graphics);
graphics->mlx = mlx_init();
if (!graphics->mlx)
ft_error_exit("Failed to initialize MLX");
graphics->win = mlx_new_window(graphics->mlx, WIDTH, HEIGHT, "Fract-ol");
if (!graphics->win)
{
ft_free_graphics(graphics);
ft_error_exit("Failed to create MLX window");
}
graphics->img = mlx_new_image(graphics->mlx, WIDTH, HEIGHT);
if (!graphics->img)
{
ft_free_graphics(graphics);
ft_error_exit("Failed to create MLX image");
}
graphics->data = (int *)mlx_get_data_addr(graphics->img, &graphics->bpp,
&graphics->line_len, &graphics->endian);
if (!graphics->data)
{
ft_free_graphics(graphics);
ft_error_exit("Failed to get image data address");
}
graphics->fractal = fractal;
}
/*
** ft_input_handling
** -----------------
** Validates the command-line arguments and sets the fractal name.
*/
void ft_input_handling(int argc, char **argv, t_fractal *fractal)
{
if (argc != 2)
{
ft_putendl_fd("Usage: ./fractol <fractal_name>", 2);
ft_putendl_fd("Available fractals: mandelbrot, julia, burning_ship", 2);
exit(EXIT_FAILURE);
}
fractal->name = argv[1];
if (ft_strcmp(fractal->name, "mandelbrot") && ft_strcmp(fractal->name,
"julia") && ft_strcmp(fractal->name, "burning_ship"))
{
ft_putendl_fd("Available fractals: mandelbrot, julia, burning_ship", 2);
exit(EXIT_FAILURE);
}
}