Fractol 1.0
A fractal visualization project implemented in C.
Loading...
Searching...
No Matches
fractol.h
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* fractol.h :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: meghribe <meghribe@student.42barcelon +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/12/23 19:53:33 by meghribe #+# #+# */
9/* Updated: 2025/01/04 13:25:50 by meghribe ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#ifndef FRACTOL_H
14# define FRACTOL_H
15
16/* ----------------------------- Includes ----------------------------------- */
17# include "MLX42/MLX42.h"
18# include <limits.h>
19# include <stdlib.h>
20
21/* --------------------------- Enumerations -------------------------------- */
22/* Fractal types */
28
29/**
30 * @brief Indices for offsets in the x and y directions.
31 */
37
38/**
39 * @brief Indices for scaling factors in the x and y directions.
40 */
46
47/**
48 * @brief Indices for complex numbers (real and imaginary)
49 */
55
56/**
57 * @brief Flags for validating numbers.
58 */
64
65/**
66 * @brief Error messages used for input validation.
67 */
76
77/* ------------------------- Structures Definitions ------------------------ */
78/**
79 * @brief Represents an RGB color.
80 */
81typedef struct s_color
82{
83 int r;
84 int g;
85 int b;
87
88/**
89 * @brief Data structure for fractal rendering
90 */
91typedef struct s_data
92{
93 double zoom;
94 double c[2];
95 double offset[2];
96 mlx_t *mlx;
97 mlx_image_t *img;
100
101/**
102 * @brief Variables used for fractal rendering calculations.
103 */
104typedef struct s_render_vars
105{
107 double scale[2];
108 double start[2];
109 double z[2];
110 double z_squared[2];
111 double c_re[2];
113 double c_im;
114 uint32_t *pixels;
115 uint32_t *row;
117
118/**
119 * @brief Helper structure for string-to-double conversion.
120 */
121typedef struct s_atod_data
122{
123 int i;
124 int sign;
125 double result;
126 double divisor;
127 double fraction;
129
130/* ---------------------------- Function Prototypes ------------------------ */
131/**
132 * @brief Calculates scales and limits for rendering fractals.
133 */
135
136/**
137 * @brief Precomputes coordinates for fractal rendering.
138 */
139int precompute_coords(double **c_re, double **c_im, t_render_vars *vars);
140
141/**
142 * @brief Calculates the color based on the number of iterations.
143 */
144int calculate_color(int iterations);
145
146/**
147 * @brief Converts a string to a double.
148 */
149double ft_atod(const char *str);
150
151/**
152 * @brief Compares two strings.
153 */
154int ft_strcmp(const char *s1, const char *s2);
155
156/**
157 * @brief Writes a string to a file descriptor.
158 */
159int fr_putstr_fd(char *s, int fd);
160
161/* Renderers */
162/**
163 * @brief Render the specified fractal.
164 */
165void render_fractal(t_data *data);
166
167/**
168 * @brief Render the Mandelbrot fractal.
169 */
170void render_mandelbrot(t_data *data);
171
172/**
173 * @brief Renders the Julia fractal.
174 */
175void render_julia(t_data *data);
176
177/**
178 * @brief Handles key inputs.
179 */
180void handle_key(mlx_key_data_t keydata, void *param);
181
182/**
183 * @brief Handles scroll inputs.
184 */
185void handle_scroll(double xdelta, double ydelta, void *param);
186
187/* ---------------------------- Constants ---------------------------------- */
188# define WIDTH 800
189# define HEIGHT WIDTH
190# define ZOOM_IN 1.1
191# define ZOOM_OUT 0.9
192# define FRACTAL_LIMIT 4.0
193# define MAX_ITERATIONS 75
194# define RESET "\033[0m"
195# define LIGHT_RED "\033[38;5;203m"
196# define LIGHT_GOLD "\033[38;5;220m"
197# define LIGHT_GREEN "\033[38;5;120m"
198
199#endif
e_fractal_type
Definition fractol.h:24
@ MANDELBROT
Definition fractol.h:25
@ JULIA
Definition fractol.h:26
e_number_flags
Flags for validating numbers.
Definition fractol.h:60
@ HAS_POINT
Definition fractol.h:62
@ HAS_DIGIT
Definition fractol.h:61
int ft_strcmp(const char *s1, const char *s2)
Compares two strings.
Definition utils.c:51
struct s_data t_data
Data structure for fractal rendering.
enum e_offset_index t_offset_index
Indices for offsets in the x and y directions.
enum e_number_flags t_number_flags
Flags for validating numbers.
int fr_putstr_fd(char *s, int fd)
Writes a string to a file descriptor.
Definition utils.c:109
struct s_color t_color
Represents an RGB color.
e_scale_index
Indices for scaling factors in the x and y directions.
Definition fractol.h:42
@ SCALE_Y
Definition fractol.h:44
@ SCALE_X
Definition fractol.h:43
e_err_msg
Error messages used for input validation.
Definition fractol.h:69
@ JULIA_NUM
Definition fractol.h:73
@ INVALID_TYPE
Definition fractol.h:71
@ NO_TYPE
Definition fractol.h:70
@ JULIA_ARGS
Definition fractol.h:72
@ MANDELBROT_ARGS
Definition fractol.h:74
void render_fractal(t_data *data)
Render the specified fractal.
Definition calcs.c:108
struct s_render_vars t_render_vars
Variables used for fractal rendering calculations.
e_offset_index
Indices for offsets in the x and y directions.
Definition fractol.h:33
@ OFFSET_Y
Definition fractol.h:35
@ OFFSET_X
Definition fractol.h:34
enum e_fractal_type t_fractal_type
e_complex_index
Indices for complex numbers (real and imaginary)
Definition fractol.h:51
@ COMPLEX_IM
Definition fractol.h:53
@ COMPLEX_RE
Definition fractol.h:52
int precompute_coords(double **c_re, double **c_im, t_render_vars *vars)
Precomputes coordinates for fractal rendering.
Definition calcs.c:78
void handle_key(mlx_key_data_t keydata, void *param)
Handles key inputs.
Definition utils.c:64
enum e_complex_index t_complex_index
Indices for complex numbers (real and imaginary)
struct s_atod_data t_atod_data
Helper structure for string-to-double conversion.
double ft_atod(const char *str)
Converts a string to a double.
Definition utils.c:19
void render_mandelbrot(t_data *data)
Render the Mandelbrot fractal.
Definition mandelbrot.c:151
void render_julia(t_data *data)
Renders the Julia fractal.
Definition julia.c:165
enum e_scale_index t_scale_index
Indices for scaling factors in the x and y directions.
void handle_scroll(double xdelta, double ydelta, void *param)
Handles scroll inputs.
Definition utils.c:91
void calculate_scales_and_limits(t_render_vars *vars, t_data *data)
Calculates scales and limits for rendering fractals.
Definition calcs.c:52
int calculate_color(int iterations)
Calculates the color based on the number of iterations.
Definition calcs.c:131
Helper structure for string-to-double conversion.
Definition fractol.h:122
double divisor
Definition fractol.h:126
double fraction
Definition fractol.h:127
double result
Definition fractol.h:125
Represents an RGB color.
Definition fractol.h:82
int b
Definition fractol.h:85
int r
Definition fractol.h:83
int g
Definition fractol.h:84
Data structure for fractal rendering.
Definition fractol.h:92
double offset[2]
Definition fractol.h:95
t_fractal_type fractal_type
Definition fractol.h:98
mlx_image_t * img
Definition fractol.h:97
mlx_t * mlx
Definition fractol.h:96
double c[2]
Definition fractol.h:94
double zoom
Definition fractol.h:93
Variables used for fractal rendering calculations.
Definition fractol.h:105
double z_squared[2]
Definition fractol.h:110
double scale[2]
Definition fractol.h:107
uint32_t * row
Definition fractol.h:115
double c_im
Definition fractol.h:113
double c_re[2]
Definition fractol.h:111
double start[2]
Definition fractol.h:108
double c_re_centered
Definition fractol.h:112
uint32_t * pixels
Definition fractol.h:114
double z[2]
Definition fractol.h:109