Fractol 1.0
A fractal visualization project implemented in C.
|
Fractol is a fractal visualization tool written in C that leverages the MLX42 graphics library for rendering complex and stunning fractals. The project supports the generation of the Mandelbrot and Julia sets, with interactive controls for zooming, panning, and exploring these fascinating mathematical structures.
Fractals are infinitely complex patterns that are self-similar across different scales. They are created by repeating a simple mathematical process over and over in an ongoing feedback loop. Fractol uses this principle to generate visually captivating fractal images.
z_(n+1) = z_n^2 + c
, starting with z_0 = 0
.c
, iterating over z_(n+1) = z_n^2 + c
.Fractals rely on complex numbers, which have two components:
Complex numbers can be represented as z = a + bi
, where:
a
is the real component.b
is the imaginary component.i
is the square root of -1.The fundamental concept in fractal generation is iteration:
z_0
.z_(n+1) = z_n^2 + c
.z
, given by |z|^2
, is greater than 4 (escape condition) or if the maximum number of iterations is reached.The number of iterations before escape determines the color of a pixel, creating the fractal's intricate patterns.
The fractal exists in the complex plane, but pixels are rendered in a 2D screen coordinate system. Fractol maps each pixel to a corresponding complex number based on:
main.c
: Program entry point, argument validation, and MLX42 initialization.calcs.c
: Core calculations for fractal scaling, limits, and color determination.julia.c
: Logic for rendering the Julia set.mandelbrot.c
: Logic for rendering the Mandelbrot set.utils.c
: Helper functions for input handling, number parsing, and string comparison.fractol.h
: Header file containing declarations, structures, and constants.calculate_scales_and_limits
function determines the scales and starting points for each axis of the fractal.precompute_coords
function calculates the complex coordinates for each pixel row in advance, improving efficiency.render_julia
) and Mandelbrot set (render_mandelbrot
), Fractol iterates through each pixel, computes whether it escapes, and assigns a color based on the number of iterations.The color of each pixel is determined by the number of iterations before escape. A smooth gradient effect is applied using:
make
: <c_re> <c_im>
: Generates a Julia set with the given complex number.Fractol dynamically adjusts the scale of the fractal based on the zoom level and screen resolution, ensuring high-detail rendering at any zoom level.
The Mandelbrot implementation includes early escape checks for points within known regions of the set, significantly speeding up rendering.
To maintain precision during deep zoom levels, calculations are performed using double-precision floating-point numbers.