A beautiful fractal viewer written in C using the MiniLibX graphics library. This project generates and displays various mathematical fractals including the Mandelbrot set, Julia sets, and Newton fractals with real-time interaction and customizable visualization.
- Multiple Fractal Types:
- Mandelbrot Set
- Julia Sets (with customizable parameters)
- Newton Fractals
- Interactive Visualization:
- Real-time zooming with mouse wheel
- Pan around the fractal using arrow keys
- Dynamic color cycling
- Live Julia set parameter modification
- High-Quality Rendering:
- 800x800 pixel window
- Smooth color gradients
- Multiple coloring algorithms (Standard and Rainbow)
- Optimized calculations for smooth performance
Before compiling, ensure you have the following dependencies installed:
Note: This program requires a graphical display (X11 on Linux, native display on macOS) to run.
sudo apt-get update
sudo apt-get install gcc make git
sudo apt-get install libx11-dev libxext-dev libbsd-dev# Xcode command line tools (for make and gcc)
xcode-select --install-
Clone the repository:
git clone https://github.com/kras2v/fractol.git cd fractol -
Initialize and update submodules:
git submodule update --init --recursive
-
Compile the project:
make
This will:
- Build the MiniLibX graphics library
- Compile the custom libft library
- Create the
fractolexecutable
-
Clean build files (optional):
make clean # Remove object files make fclean # Remove object files and executables make re # Clean rebuild
./fractol <fractal_type> [parameters]./fractol MandelbrotDisplays the classic Mandelbrot set with default zoom and position.
./fractol JuliaDisplays a Julia set with default parameters (c = -0.4 + 0.6i).
./fractol Julia <real> <imaginary>Displays a Julia set with custom complex number parameters.
Examples:
./fractol Julia 0.355 0.355
./fractol Julia -0.7 0.27015
./fractol Julia 0.285 0.01
./fractol Julia -0.4 0.6./fractol NewtonDisplays Newton's method fractal for finding roots of zยณ - 1 = 0.
- ESC - Exit the program
- Arrow Keys - Pan around the fractal
- โ Up
- โ Down
- โ Left
- โ Right
- +/= - Zoom in (centered)
- - - Zoom out (centered)
- C - Cycle between color schemes (Standard โ Rainbow)
- Scroll Up - Zoom in at mouse position
- Scroll Down - Zoom out at mouse position
- Mouse Movement (Julia sets only) - Dynamically change Julia set parameters
fractol/
โโโ Makefile # Build configuration
โโโ fractol.h # Main header file
โโโ main.c # Program entry point
โโโ libft/ # Custom C library
โ โโโ libft.a # Compiled library
โ โโโ ft_printf/ # Custom printf implementation
โโโ minilibx_linux/ # Graphics library (submodule)
โโโ fractal_selector.c # Fractal initialization
โโโ fractal_rendering.c # Main rendering functions
โโโ calculations_julia_mandelbrot.c # Mandelbrot/Julia calculations
โโโ newton.c # Newton fractal calculations
โโโ complex_operations.c # Complex number operations
โโโ fractal_coloring.c # Color generation
โโโ utils_coloring.c # Color utilities
โโโ events_initialization.c # Event handler setup
โโโ key_press_events.c # Keyboard event handling
โโโ mouse_events.c # Mouse event handling
โโโ utils_*.c # Various utility functions
โโโ README.md # This file
- Mandelbrot Set: For each point c in the complex plane, iterate z_{n+1} = z_nยฒ + c starting with z_0 = 0
- Julia Set: Similar iteration but with a fixed parameter c and varying starting points z_0
- Newton Fractal: Uses Newton's method to find roots of zยณ - 1 = 0, coloring by convergence
- Language: C99
- Graphics: MiniLibX (42 School's graphics library)
- Complex Numbers: Custom implementation with basic operations
- Color Schemes: HSV to RGB conversion for smooth gradients
- Optimization: Efficient escape-time algorithms with configurable iteration limits
- Resolution: 800x800 pixels
- Max Iterations: 100 (configurable in source)
- Real-time Rendering: Optimized for interactive frame rates
- Memory Management: Proper cleanup and error handling
Uses escape-time algorithm results to create smooth color transitions.
HSV-based coloring that cycles through the spectrum based on iteration count and complex number magnitude.
The program includes comprehensive error handling for:
- Invalid command-line arguments
- Memory allocation failures
- Graphics initialization errors
- Invalid floating-point parameters
Error messages are displayed with usage instructions.
# Classic dragon fractal
./fractol Julia -0.7 0.27015
# Rabbit fractal
./fractol Julia -0.123 0.745
# Lightning fractal
./fractol Julia -0.75 0.11
# San Marco dragon
./fractol Julia -0.75 0.0- Start with a wide view and use mouse wheel to zoom into interesting areas
- Use arrow keys for fine positioning
- Try different color schemes with the 'C' key
- For Julia sets, move the mouse to see parameter changes in real-time
This is a learning project, but suggestions and improvements are welcome! Please feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
- Share interesting parameter combinations
This project is part of the 42 School curriculum. Feel free to use and modify for educational purposes.
- 42 School for the project specifications and MiniLibX library
- Benoit Mandelbrot for the mathematical foundation
- Gaston Julia for Julia set theory
- Isaac Newton for the numerical method used in Newton fractals
Explore the infinite beauty of mathematical fractals! ๐