Fractol 1.0
A fractal visualization project implemented in C.
Loading...
Searching...
No Matches
julia.c File Reference
#include "fractol.h"
Include dependency graph for julia.c:

Go to the source code of this file.

Functions

static void julia_iterations (t_render_vars *vars, t_data *data)
 Performs the iterations for a signle point in the Julia set.
 
static void render_julia_row (t_render_vars *vars, t_data *data, int y)
 Renders a single row of the Julia set.
 
void render_julia (t_data *data)
 Renders the Julia set fractal.
 

Function Documentation

◆ julia_iterations()

static void julia_iterations ( t_render_vars vars,
t_data data 
)
static

Performs the iterations for a signle point in the Julia set.

This function applies the Julia set formula iteratively to determine whether a given point escapes the threshold. The number of iterations taken before escape determines the point's color.

  • Core Algorithm: The formula z = z^2 + c is applied, where:
    • z is a complex number, represented by real (z_re) and imaginary (z_im) parts.
    • c is a constant defined by the user (real and imaginary parts).
  • Bounding Condition: The iteerations stop when:
    • The sum of the squares of the real and imaginary parts exceeds 4.0.
    • The maximum number of iterations (MAX_ITERATIONS) is reached.
  • Optimization: Squared values (z_re^2 and z_im^2) are cached to avoid redundant calculations.
Parameters
varsPointer to the structure holding rendering variables (e.g., z and iterations). @params data Pointer to the main fractal data, including the Julia constant (c).

Definition at line 84 of file julia.c.

85{
86 double temp_z_re;
87
88 vars->iterations = 0;
89 while (vars->z_squared[COMPLEX_RE] + vars->z_squared[COMPLEX_IM] <= 4.0 && \
91 {
92 temp_z_re = vars->z_squared[COMPLEX_RE];
93 temp_z_re -= vars->z_squared[COMPLEX_IM];
94 temp_z_re += data->c[COMPLEX_RE];
95 vars->z[COMPLEX_IM] = 2.0 * vars->z[COMPLEX_RE] * \
96 vars->z[COMPLEX_IM] + data->c[COMPLEX_IM];
97 vars->z[COMPLEX_RE] = temp_z_re;
98 vars->z_squared[COMPLEX_RE] = vars->z[COMPLEX_RE] * vars->z[COMPLEX_RE];
99 vars->z_squared[COMPLEX_IM] = vars->z[COMPLEX_IM] * vars->z[COMPLEX_IM];
100 vars->iterations++;
101 }
102}
#define MAX_ITERATIONS
Definition fractol.h:193
@ COMPLEX_IM
Definition fractol.h:53
@ COMPLEX_RE
Definition fractol.h:52
double c[2]
Definition fractol.h:94
double z_squared[2]
Definition fractol.h:110
double z[2]
Definition fractol.h:109
Here is the caller graph for this function:

◆ render_julia()

void render_julia ( t_data data)

Renders the Julia set 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.

  • Setup:
    • Calculates the scaling and starting coordinates based on the zoom level and positional offsets provided by the user.
  • Row-by-Row Rendering:
    • For each row on the screen (y coordinate), the corresponding imaginary coordinate is computed.
    • The row is passed to render_julia_row, which handles the pixel-by-pixel rendering.
  • Full Image Construction:
    • The ffunction processes every row until the entire fractal is rendered.
Parameters
dataPointer to the main fractal data structure, including rendering details such as zoom, offsets, and fractal paarameters.

Definition at line 165 of file julia.c.

166{
167 t_render_vars vars;
168 int y;
169
170 calculate_scales_and_limits(&vars, data);
171 y = 0;
172 while (y < HEIGHT)
173 {
174 vars.c_im = vars.start[COMPLEX_IM] + y * vars.scale[SCALE_Y];
175 render_julia_row(&vars, data, y++);
176 }
177}
void calculate_scales_and_limits(t_render_vars *vars, t_data *data)
Calculates the scales and starting points for the fractal rendering.
Definition calcs.c:52
@ SCALE_Y
Definition fractol.h:44
#define HEIGHT
Definition fractol.h:189
static void render_julia_row(t_render_vars *vars, t_data *data, int y)
Renders a single row of the Julia set.
Definition julia.c:126
Variables used for fractal rendering calculations.
Definition fractol.h:105
double scale[2]
Definition fractol.h:107
double c_im
Definition fractol.h:113
double start[2]
Definition fractol.h:108
Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_julia_row()

static void render_julia_row ( t_render_vars vars,
t_data data,
int  y 
)
static

Renders a single row of the Julia set.

This function processes one row of the pixel in the Juliaa set by iterating through each pixel, applying the Juliaa set formula, and determining its color.

  • Coordinate Mapping:
    • Each pixel is mapped to a complex number (z) based on its position and the scaling factors calculated from the zoom and offsets.
  • Iteration and Coloring:
    • The Julia set formula is applied iteratively for each pixel.
    • The number of iterations is used to calculate the pixel's color.
  • Row Processing: Each pixel in the row is processed sequentially, and the result is stored in the image buffer.
Parameters
varsPointer to the rendering variables structure (e.g., pixel and scaling).
dataPointer to the main fractal data.
yThe current row index being processed (0 for the first row, up to HEIGHT - 1).

Definition at line 126 of file julia.c.

127{
128 int x;
129
130 x = 0;
131 while (x < WIDTH)
132 {
133 vars->c_re[0] = vars->start[COMPLEX_RE] + x * vars->scale[SCALE_X];
134 vars->z[COMPLEX_RE] = vars->c_re[0];
135 vars->z[COMPLEX_IM] = vars->c_im;
136 vars->z_squared[COMPLEX_RE] = vars->z[COMPLEX_RE] * vars->z[COMPLEX_RE];
137 vars->z_squared[COMPLEX_IM] = vars->z[COMPLEX_IM] * vars->z[COMPLEX_IM];
138 julia_iterations(vars, data);
139 vars->row = vars->pixels + y * WIDTH + x;
140 *vars->row = calculate_color(vars->iterations);
141 x++;
142 }
143}
int calculate_color(int iterations)
Calculates the color of a pixel based on how many iterations it takes to "escape".
Definition calcs.c:131
#define WIDTH
Definition fractol.h:188
@ SCALE_X
Definition fractol.h:43
static void julia_iterations(t_render_vars *vars, t_data *data)
Performs the iterations for a signle point in the Julia set.
Definition julia.c:84
uint32_t * row
Definition fractol.h:115
double c_re[2]
Definition fractol.h:111
uint32_t * pixels
Definition fractol.h:114
Here is the call graph for this function:
Here is the caller graph for this function: