Skip to content

Latest commit

 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42-fract-ol - Graphical Fractal Renderer

Language Graphics School

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.


📸 Generated Results & Screenshots

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

✨ Features

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

🛠️ Prerequisites & Build Instructions

System Dependencies

  • gcc / clang (C Compiler)
  • make & cmake
  • glfw library (libglfw3-dev / glfw)
  • OpenGL development headers

Compiling the Project

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

Available Makefile rules:

  • make / make all - Compiles libraries and generates the fractol executable.
  • make clean - Removes object files (.o).
  • make fclean - Removes object files, libraries, and the fractol binary.
  • make re - Rebuilds the entire project from scratch.

🚀 Usage Guide

./fractol <fractal_name> [julia_real] [julia_imaginary]

Examples

  1. Render the Mandelbrot Set:

    ./fractol mandelbrot
  2. Render a Julia Set:

    ./fractol julia -0.4 0.6
  3. Alternative Julia Parameters:

    ./fractol julia -0.8 0.156
    ./fractol julia -0.7 0.27015
    ./fractol julia 0.355 0.355

🧪 Error Handling & Input Validation

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.
    

📁 Repository Structure

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

📄 License & Credits

Developed by mben-yah as part of the 42 School curriculum. Graphics powered by MLX42.

About

This is a repository of a 42 project. The project is about using a graphics library to render fractals..

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages