Skip to content

kras2v/fractol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

35 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Fract'ol

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.

๐ŸŽฏ Features

  • 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

๐Ÿ› ๏ธ Prerequisites

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.

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install gcc make git
sudo apt-get install libx11-dev libxext-dev libbsd-dev

macOS:

# Xcode command line tools (for make and gcc)
xcode-select --install

๐Ÿš€ Installation

  1. Clone the repository:

    git clone https://github.com/kras2v/fractol.git
    cd fractol
  2. Initialize and update submodules:

    git submodule update --init --recursive
  3. Compile the project:

    make

    This will:

    • Build the MiniLibX graphics library
    • Compile the custom libft library
    • Create the fractol executable
  4. Clean build files (optional):

    make clean      # Remove object files
    make fclean     # Remove object files and executables
    make re         # Clean rebuild

๐Ÿ“– Usage

Basic Syntax

./fractol <fractal_type> [parameters]

Available Fractals

Mandelbrot Set

./fractol Mandelbrot

Displays the classic Mandelbrot set with default zoom and position.

Julia Set (Default Parameters)

./fractol Julia

Displays a Julia set with default parameters (c = -0.4 + 0.6i).

Julia Set (Custom Parameters)

./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

Newton Fractal

./fractol Newton

Displays Newton's method fractal for finding roots of zยณ - 1 = 0.

๐ŸŽฎ Controls

Keyboard Controls

  • 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)

Mouse Controls

  • Scroll Up - Zoom in at mouse position
  • Scroll Down - Zoom out at mouse position
  • Mouse Movement (Julia sets only) - Dynamically change Julia set parameters

๐Ÿ—๏ธ Project Structure

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

๐Ÿ”ง Technical Details

Mathematics

  • 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

Implementation

  • 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

Performance

  • Resolution: 800x800 pixels
  • Max Iterations: 100 (configurable in source)
  • Real-time Rendering: Optimized for interactive frame rates
  • Memory Management: Proper cleanup and error handling

๐ŸŽจ Color Schemes

Standard Coloring

Uses escape-time algorithm results to create smooth color transitions.

Rainbow Coloring

HSV-based coloring that cycles through the spectrum based on iteration count and complex number magnitude.

๐Ÿšจ Error Handling

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.

๐Ÿ“ Examples and Tips

Interesting Julia Set Parameters

# 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

Navigation Tips

  1. Start with a wide view and use mouse wheel to zoom into interesting areas
  2. Use arrow keys for fine positioning
  3. Try different color schemes with the 'C' key
  4. For Julia sets, move the mouse to see parameter changes in real-time

๐Ÿค Contributing

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

๐Ÿ“„ License

This project is part of the 42 School curriculum. Feel free to use and modify for educational purposes.

๐Ÿ™ Acknowledgments

  • 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! ๐ŸŒ€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •