Fractol 1.0
A fractal visualization project implemented in C.
|
#include "MLX42/MLX42.h"
#include <limits.h>
#include <stdlib.h>
Go to the source code of this file.
Data Structures | |
struct | s_color |
Represents an RGB color. More... | |
struct | s_data |
Data structure for fractal rendering. More... | |
struct | s_render_vars |
Variables used for fractal rendering calculations. More... | |
struct | s_atod_data |
Helper structure for string-to-double conversion. More... | |
Macros | |
#define | WIDTH 800 |
#define | HEIGHT WIDTH |
#define | ZOOM_IN 1.1 |
#define | ZOOM_OUT 0.9 |
#define | FRACTAL_LIMIT 4.0 |
#define | MAX_ITERATIONS 75 |
#define | RESET "\033[0m" |
#define | LIGHT_RED "\033[38;5;203m" |
#define | LIGHT_GOLD "\033[38;5;220m" |
#define | LIGHT_GREEN "\033[38;5;120m" |
Typedefs | |
typedef enum e_fractal_type | t_fractal_type |
typedef enum e_offset_index | t_offset_index |
Indices for offsets in the x and y directions. | |
typedef enum e_scale_index | t_scale_index |
Indices for scaling factors in the x and y directions. | |
typedef enum e_complex_index | t_complex_index |
Indices for complex numbers (real and imaginary) | |
typedef enum e_number_flags | t_number_flags |
Flags for validating numbers. | |
typedef struct s_color | t_color |
Represents an RGB color. | |
typedef struct s_data | t_data |
Data structure for fractal rendering. | |
typedef struct s_render_vars | t_render_vars |
Variables used for fractal rendering calculations. | |
typedef struct s_atod_data | t_atod_data |
Helper structure for string-to-double conversion. | |
Enumerations | |
enum | e_fractal_type { MANDELBROT , JULIA } |
enum | e_offset_index { OFFSET_X , OFFSET_Y } |
Indices for offsets in the x and y directions. More... | |
enum | e_scale_index { SCALE_X , SCALE_Y } |
Indices for scaling factors in the x and y directions. More... | |
enum | e_complex_index { COMPLEX_RE , COMPLEX_IM } |
Indices for complex numbers (real and imaginary) More... | |
enum | e_number_flags { HAS_DIGIT , HAS_POINT } |
Flags for validating numbers. More... | |
enum | e_err_msg { NO_TYPE , INVALID_TYPE , JULIA_ARGS , JULIA_NUM , MANDELBROT_ARGS } |
Error messages used for input validation. More... | |
Functions | |
void | calculate_scales_and_limits (t_render_vars *vars, t_data *data) |
Calculates scales and limits for rendering fractals. | |
int | precompute_coords (double **c_re, double **c_im, t_render_vars *vars) |
Precomputes coordinates for fractal rendering. | |
int | calculate_color (int iterations) |
Calculates the color based on the number of iterations. | |
double | ft_atod (const char *str) |
Converts a string to a double. | |
int | ft_strcmp (const char *s1, const char *s2) |
Compares two strings. | |
int | fr_putstr_fd (char *s, int fd) |
Writes a string to a file descriptor. | |
void | render_fractal (t_data *data) |
Render the specified fractal. | |
void | render_mandelbrot (t_data *data) |
Render the Mandelbrot fractal. | |
void | render_julia (t_data *data) |
Renders the Julia fractal. | |
void | handle_key (mlx_key_data_t keydata, void *param) |
Handles key inputs. | |
void | handle_scroll (double xdelta, double ydelta, void *param) |
Handles scroll inputs. | |
typedef struct s_atod_data t_atod_data |
Helper structure for string-to-double conversion.
typedef enum e_complex_index t_complex_index |
Indices for complex numbers (real and imaginary)
typedef enum e_fractal_type t_fractal_type |
typedef enum e_number_flags t_number_flags |
Flags for validating numbers.
typedef enum e_offset_index t_offset_index |
Indices for offsets in the x and y directions.
typedef struct s_render_vars t_render_vars |
Variables used for fractal rendering calculations.
typedef enum e_scale_index t_scale_index |
Indices for scaling factors in the x and y directions.
enum e_complex_index |
Indices for complex numbers (real and imaginary)
Enumerator | |
---|---|
COMPLEX_RE | |
COMPLEX_IM |
enum e_err_msg |
Error messages used for input validation.
Enumerator | |
---|---|
NO_TYPE | |
INVALID_TYPE | |
JULIA_ARGS | |
JULIA_NUM | |
MANDELBROT_ARGS |
enum e_fractal_type |
Enumerator | |
---|---|
MANDELBROT | |
JULIA |
enum e_number_flags |
Flags for validating numbers.
Enumerator | |
---|---|
HAS_DIGIT | |
HAS_POINT |
enum e_offset_index |
Indices for offsets in the x and y directions.
Enumerator | |
---|---|
OFFSET_X | |
OFFSET_Y |
enum e_scale_index |
Indices for scaling factors in the x and y directions.
Enumerator | |
---|---|
SCALE_X | |
SCALE_Y |
int calculate_color | ( | int | iterations | ) |
Calculates the color based on the number of iterations.
Calculates the color based on the number of iterations.
This function determines the color of each pixel in the fractal by mapping the iteration count (how many steps we are needed to reach a threshold) to a color gradient.
For non-technical users:
iterations | Number of iterations required for the opint to "escape". |
Definition at line 131 of file calcs.c.
void calculate_scales_and_limits | ( | t_render_vars * | vars, |
t_data * | data | ||
) |
Calculates scales and limits for rendering fractals.
Calculates scales and limits for rendering fractals.
This function determines how the fractal is scaled and positioned on the screen. It computes the scale factors for each pixel and establishes the starting points ffor the real and imaginary part of the fractal based on the zoom level and offsets.
For non-technical users:
vars | Pointer to the rendering variables structure. |
data | Pointer to the main data structure containing fractal information. |
Definition at line 52 of file calcs.c.
int fr_putstr_fd | ( | char * | s, |
int | fd | ||
) |
Writes a string to a file descriptor.
Writes a string to a file descriptor.
Definition at line 109 of file utils.c.
double ft_atod | ( | const char * | str | ) |
Converts a string to a double.
Converts a string to a double.
Definition at line 19 of file utils.c.
int ft_strcmp | ( | const char * | s1, |
const char * | s2 | ||
) |
void handle_key | ( | mlx_key_data_t | keydata, |
void * | param | ||
) |
Handles key inputs.
Definition at line 64 of file utils.c.
void handle_scroll | ( | double | xdelta, |
double | ydelta, | ||
void * | param | ||
) |
Handles scroll inputs.
Handles scroll inputs.
Definition at line 91 of file utils.c.
int precompute_coords | ( | double ** | c_re, |
double ** | c_im, | ||
t_render_vars * | vars | ||
) |
Precomputes coordinates for fractal rendering.
Precomputes coordinates for fractal rendering.
This function calculates the real and imaginary parts of the fractal for each pixel on the screen, storing them in arrays for quick access during rendering. It ensures that every point is prepared for the fractal calculations.
For non-technical users:
c_re | Pointer to the array storing real coordinates. |
c_im | Pointer to the array storing imaginary coordinates. |
vars | Pointer to the rendering variables structure. |
Definition at line 78 of file calcs.c.
void render_fractal | ( | t_data * | data | ) |
Render the specified fractal.
Render the specified fractal.
This function selects the appropiate rendering algorithm based on the fractal type chosen by the user (Julia or Mandelbrot) and renders it on the screen.
For non-technical users:
data | Pointer to the main data structure containing fractal and rendering details. |
Definition at line 108 of file calcs.c.
void render_julia | ( | t_data * | data | ) |
Renders the Julia fractal.
Renders the Julia fractal.
This function handles the full rendering process for the Julia set by iterating through all rows of the screen, rendering each row sequentially.
y
coordinate), the corresponding imaginary coordinate is computed.render_julia_row
, which handles the pixel-by-pixel rendering.data | Pointer to the main fractal data structure, including rendering details such as zoom, offsets, and fractal paarameters. |
Definition at line 165 of file julia.c.
void render_mandelbrot | ( | t_data * | data | ) |
Render the Mandelbrot fractal.
Render the Mandelbrot fractal.
Definition at line 151 of file mandelbrot.c.