42-fract-ol is a high-performance 2D fractal renderer written in C using the MLX42 (GLFW / OpenGL) graphics library. The application renders mathematical fractals—specifically the Mandelbrot set and customizable Julia sets—featuring smooth color palette interpolation and interactive scroll zooming.
Here are captured output renderings generated from execution of the compiled ./fractol binary:
| Fractal Type | Parameters | Output Image |
|---|---|---|
| Mandelbrot Set | Standard | mandelbrot.png |
| Julia Set (Preset 1) | c = -0.4 + 0.6i |
julia1.png |
| Julia Set (Preset 2) | c = -0.8 + 0.156i |
julia2.png |
-
Fractal Types:
-
Mandelbrot Set: Features cardioid & period-2 bulb early rejection optimizations (
is_in_mandelbrot_set). -
Julia Set: Accepts dynamic complex parameters
$c = r + i$ from the command line.
-
Mandelbrot Set: Features cardioid & period-2 bulb early rejection optimizations (
-
Color Palette & Rendering:
- 200 maximum iterations (
DEFAULT_ITERS = 200). - Smooth linear RGB interpolation across 10 cosmic colors (
DEEP_SPACE,NEBULA_PINK,STARDUST_BLUE,SOLAR_ORANGE,PULSAR_GREEN, etc.).
- 200 maximum iterations (
-
Controls & Navigation:
-
Mouse Scroll: Dynamic zoom in/out relative to cursor position (
ZOOM_IN_COEFF = 0.95,ZOOM_OUT_COEFF = 1.05). - Keyboard Esc Key: Clean exit and memory deallocation.
- Window Close Button: Native window termination handling.
-
Mouse Scroll: Dynamic zoom in/out relative to cursor position (
gcc/clang(C Compiler)make&cmakeglfwlibrary (libglfw3-dev/glfw)OpenGLdevelopment headers
Clone the repository and build the project using the provided Makefile:
# Clone the repository
git clone https://github.com/mben-yah/42-fract-ol.git
cd 42-fract-ol
# Compile everything (libft, printf, MLX42, and fractol)
makeAvailable Makefile rules:
make/make all- Compiles libraries and generates thefractolexecutable.make clean- Removes object files (.o).make fclean- Removes object files, libraries, and thefractolbinary.make re- Rebuilds the entire project from scratch.
./fractol <fractal_name> [julia_real] [julia_imaginary]-
Render the Mandelbrot Set:
./fractol mandelbrot
-
Render a Julia Set:
./fractol julia -0.4 0.6
-
Alternative Julia Parameters:
./fractol julia -0.8 0.156 ./fractol julia -0.7 0.27015 ./fractol julia 0.355 0.355
The binary contains strict validation for command-line arguments:
-
No arguments provided:
No arguements Were provided. -------------------------------- You must choose either 'Mandelbrot' or 'Julia'. The next two arguments are for the Julia's parameter. -
Invalid fractal name:
Wrong fractal name. -------------------------------- You must choose either 'Mandelbrot' or 'Julia'. The next two arguments are for the Julia's parameter. -
Missing Julia complex constant:
You must enter the parameters for the C constant. -------------------------------- You must choose either 'Mandelbrot' or 'Julia'. The next two arguments are for the Julia's parameter. -
Non-numeric float parameters:
Wrong format for the complex constant. -------------------------------- You must choose either 'Mandelbrot' or 'Julia'. The next two arguments are for the Julia's parameter.
42-fract-ol/
├── fractol.c # Program entry point & event hooks
├── includes/
│ ├── utils.h # Main project header & data structures
│ ├── ft_printf.h # Printf header
│ └── libft.h # Libft header
├── utils/
│ ├── rendering_utils.c # Fractal escape math & smooth color interpolation
│ ├── drawing_options.c # Mandelbrot & Julia drawing loops
│ ├── validate_input.c # CLI argument parsing
│ ├── zoom_utils.c # Scroll hook handling
│ ├── atod.c # ASCII to double string converter
│ ├── error_utils.c # Error message printer
│ ├── exit_utils.c # Memory cleanup & termination
│ └── utils.c # Math & coordinate rescaling helpers
├── lib/
│ ├── libft/ # Custom C library
│ ├── printf/ # Custom printf implementation
│ └── MLX42/ # MLX42 cross-platform graphics framework
└── Makefile # Build configuration script
Developed by mben-yah as part of the 42 School curriculum. Graphics powered by MLX42.