Skip to main content

Rendering Parameters

Fract’ol offers several customizable parameters that affect how fractals are rendered. These can be adjusted both at initialization and during runtime.

Color Scheme System

The project uses a psychedelic color palette defined in fractol.h:27-44:
#define BLACK   0x000000
#define WHITE   0xFFFFFF
#define PSYCHEDELIC_RED     0xFF0044  // Bright red with a purple tint
#define PSYCHEDELIC_GREEN   0x00FF33  // Bright green
#define PSYCHEDELIC_BLUE    0x0033FF  // Bright blue
#define PSYCHEDELIC_YELLOW  0xFFFF00  // Bright yellow
#define PSYCHEDELIC_CYAN    0x00FFFF  // Neon cyan
#define PSYCHEDELIC_MAGENTA 0xFF00FF  // Bright magenta
#define PSYCHEDELIC_ORANGE  0xFF7F00  // Neon orange
#define PSYCHEDELIC_PURPLE  0x9B00FF  // Deep purple
#define PSYCHEDELIC_PINK    0xFF1493  // Hot pink
#define PSYCHEDELIC_LIME    0x00FF00  // Neon lime
#define PSYCHEDELIC_TURQUOISE 0x40E0D0  // Turquoise
#define PSYCHEDELIC_PASTEL_PURPLE 0xB23E91  // Pastel purple
#define PSYCHEDELIC_TURQUOISE_BLUE 0x30D5C8  // Turquoise blue
#define PSYCHEDELIC_CORAL 0xFF7F50  // Coral
#define PSYCHEDELIC_LAVENDER 0xE6E6FA  // Lavender
#define PSYCHEDELIC_MINT 0x98FF98  // Mint green
Colors are defined in hexadecimal RGB format: 0xRRGGBB. Each pair of digits represents the intensity (00-FF) of red, green, and blue components.

Current Color Mapping

The default coloring scheme creates a gradient from lime to mint:
void handle_pixel(int x, int y, t_fractol *fractol)
{
    // ... iteration logic ...
    
    if ((z.x * z.x) + (z.y * z.y) > fractol->escape_value)
    {
        // Map iteration count to color gradient
        color = map(i, PSYCHEDELIC_LIME, PSYCHEDELIC_MINT,
                fractol->iterations_definition);
        my_pixel_put(x, y, &fractol->img, color);
        return;
    }
    
    // Points that don't escape are colored white
    my_pixel_put(x, y, &fractol->img, WHITE);
}

Escape Colors

PSYCHEDELIC_LIME → PSYCHEDELIC_MINTGradient from neon lime (0x00FF00) to soft mint (0x98FF98)Fast escapes = bright lime, slow escapes = pale mint

Set Color

WHITE (0xFFFFFF)Points that never escape (in the fractal set)Represents the mathematical set itself

Customizing Colors

To change the color scheme, modify the map function call in fractol_render.c:53-54:

Example Color Schemes

color = map(i, PSYCHEDELIC_ORANGE, PSYCHEDELIC_RED,
        fractol->iterations_definition);
Creates a hot, fiery appearance with orange transitioning to red.
color = map(i, PSYCHEDELIC_CYAN, PSYCHEDELIC_BLUE,
        fractol->iterations_definition);
Cool, underwater feeling with bright cyan fading to deep blue.
color = map(i, PSYCHEDELIC_YELLOW, PSYCHEDELIC_MAGENTA,
        fractol->iterations_definition);
Warm sunset colors transitioning from yellow to vibrant magenta.
color = map(i, PSYCHEDELIC_LAVENDER, PSYCHEDELIC_PURPLE,
        fractol->iterations_definition);
Soft lavender transitioning to deep royal purple.
// In the escape case:
color = map(i, BLACK, BLACK, fractol->iterations_definition);

// For the set:
my_pixel_put(x, y, &fractol->img, WHITE);
Traditional mathematical visualization with black fractals on white.
You can use any combination of the 16 predefined psychedelic colors, or define your own hex color values.

The Iteration Definition Parameter

The iterations_definition controls rendering detail and quality:
typedef struct s_fractol
{
    // ... other fields ...
    int iterations_definition;  // Maximum iterations per pixel
    // ... other fields ...
} t_fractol;

Default Value

void data_init(t_fractol *fractol)
{
    fractol->escape_value = 4;
    fractol->iterations_definition = 30;  // Default: 30 iterations
    fractol->shift_x = 0.0;
    fractol->shift_y = 0.0;
    fractol->zoom = 1;
}

Low (10-30)

Fast renderingGood for explorationLess detail at boundaries

Medium (30-100)

BalancedDefault rangeGood for most viewing

High (100+)

Slow renderingMaximum detailRequired for deep zooms

Runtime Adjustment

Modify during execution using keyboard controls:
int key_handler(int keysym, t_fractol *fractol)
{
    // ... other controls ...
    
    else if (keysym == XK_plus)
        fractol->iterations_definition += 5;  // Add 5 iterations
    else if (keysym == XK_minus)
        fractol->iterations_definition -= 5;  // Remove 5 iterations
    
    fractol_render(fractol);  // Re-render with new value
    return (0);
}
Each press of + or - changes the iteration count by 5. Hold the key for multiple increments.

The Escape Value Parameter

The escape_value determines when a point is considered to have escaped to infinity:
void data_init(t_fractol *fractol)
{
    fractol->escape_value = 4;  // Default: 4
    // ...
}

How It Works

while (i < fractol->iterations_definition)
{
    z = sum_complex(sqare_complex(z), c);  // z = z² + c
    
    // Check if magnitude² exceeds escape_value
    if ((z.x * z.x) + (z.y * z.y) > fractol->escape_value)
    {
        // Point has escaped!
        color = map(i, PSYCHEDELIC_LIME, PSYCHEDELIC_MINT,
                fractol->iterations_definition);
        my_pixel_put(x, y, &fractol->img, color);
        return;
    }
    i++;
}
Why 4? Mathematically, if |z| > 2, the sequence will always diverge. Since we check |z|² = z.x² + z.y², we compare against 4 (which is 2²).

Customizing Escape Value

You can modify escape_value in fractol_init.c:23 to experiment:
fractol->escape_value = 2;
  • Faster escape detection
  • More conservative boundary
  • May miss some detail
  • Faster rendering
fractol->escape_value = 4;
  • Standard mathematical threshold
  • Proven optimal for fractals
  • Best balance of accuracy and speed
fractol->escape_value = 8;
  • Later escape detection
  • More lenient boundary
  • May reveal additional detail
  • Slower rendering

Window and Resolution

The rendering resolution is defined at compile time:
#define WIDTH  2000
#define HEIGHT 1500
To change the window size:
  1. Edit fractol.h:24-25
  2. Recompile the project
  3. Higher resolutions = more detail but slower rendering
  4. Maintain aspect ratio for undistorted fractals
Common resolutions:
  • 800×600 (fast, low detail)
  • 1920×1080 (HD, good balance)
  • 2000×1500 (default, high quality)
  • 3840×2160 (4K, very slow)

Initialization Parameters

All default parameters are set in data_init():
void data_init(t_fractol *fractol)
{
    fractol->escape_value = 4;              // Escape threshold
    fractol->iterations_definition = 30;    // Max iterations
    fractol->shift_x = 0.0;                 // X offset (panning)
    fractol->shift_y = 0.0;                 // Y offset (panning)
    fractol->zoom = 1;                      // Zoom factor
}

Position

shift_x, shift_yStart centered at origin (0, 0)Adjustable with arrow keys/WASD

Zoom

zoomStarts at 1.0 (full view)Adjustable with mouse wheel

Creating Custom Color Functions

For advanced customization, you can implement multi-color gradients by modifying the color mapping logic:
// Example: Multi-stage gradient
int get_custom_color(int i, int max_iter)
{
    if (i < max_iter / 3)
        return map(i, PSYCHEDELIC_BLUE, PSYCHEDELIC_CYAN, max_iter / 3);
    else if (i < 2 * max_iter / 3)
        return map(i - max_iter/3, PSYCHEDELIC_CYAN, 
                   PSYCHEDELIC_YELLOW, max_iter / 3);
    else
        return map(i - 2*max_iter/3, PSYCHEDELIC_YELLOW, 
                   PSYCHEDELIC_RED, max_iter / 3);
}
This creates a three-stage gradient: blue → cyan → yellow → red.

The Mapping Function

All parameter interpolation uses the map function from math_utils.c:15:
double map(double unscaled_num, double new_min, double new_max, double old_max)
{
    double old_min;
    
    old_min = 0;
    return ((new_max - new_min) * (unscaled_num - old_min)
        / (old_max - old_min) + new_min);
}
This function linearly interpolates values from range [0, old_max] to range [new_min, new_max]. It’s used for both coordinate mapping and color gradients.

Performance Tuning

  • iterations_definition: 15-25
  • Resolution: 1280×720 or lower
  • escape_value: 4 (standard)
  • Color: Simple gradient (2 colors)
  • iterations_definition: 30-50
  • Resolution: 2000×1500 (default)
  • escape_value: 4 (standard)
  • Color: Your preferred gradient
  • iterations_definition: 100-500
  • Resolution: 3840×2160 or higher
  • escape_value: 4 (standard)
  • Color: High-contrast gradient
Rendering time scales with WIDTH × HEIGHT × iterations_definition. Doubling any of these approximately doubles render time.

Build docs developers (and LLMs) love