Program Structure
Fract’ol is built around a core event-driven architecture using the MiniLibX graphics library. The program follows a clear initialization, rendering, and event loop pattern.Main Components
The application consists of four primary modules:- Initialization - Sets up MLX connection, window, and image buffer
- Rendering - Calculates and draws fractal pixels
- Event System - Handles keyboard and mouse interactions
- Mathematical Engine - Complex number operations and coordinate mapping
Program Flow
The execution flow frommain.c follows this sequence:
main.c:15-39
Execution Phases
Module Relationships
Data Flow
- main.c creates the
t_fractolstructure and passes it to all subsystems - fractol_init.c populates the structure with MLX pointers and initial values
- fractol_render.c reads the structure to render pixels, using math_utils.c for calculations
- events.c modifies structure fields (zoom, shift, iterations) and triggers re-renders
Rendering Pipeline
For each pixel at screen coordinates(x, y):
- Map to complex plane: Convert pixel coordinates to complex numbers using
map() - Apply transformations: Account for zoom and pan (shift_x, shift_y)
- Iterate fractal formula: Use
sqare_complex()andsum_complex()up toiterations_definition - Check escape: If magnitude exceeds
escape_value, pixel escapes - Color assignment: Map iteration count to psychedelic color palette
- Write pixel: Store color value in image buffer at calculated offset
Memory Management
The program manages several heap-allocated resources:- MLX connection: Freed on exit via
close_handler() - MLX window: Destroyed before freeing connection
- Image buffer: Destroyed before window destruction
- Display connection: Destroyed after window cleanup
close_handler() (events.c:15-24) ensures proper resource deallocation:
Configuration Constants
Defined infractol.h:24-25:
WIDTH: 2000 pixelsHEIGHT: 1500 pixels
PSYCHEDELIC_LIME(0x00FF00) toPSYCHEDELIC_MINT(0x98FF98) gradientWHITE(0xFFFFFF) for points in the set