This document provides context and guidelines for AI agents working on the Mandelbrot repository.
This is a high-performance C++26 application that renders the Mandelbrot set in real-time. It leverages:
- Raylib: For windowing, input, and graphics rendering.
- Intel TBB (Threading Building Blocks): As the backend for parallel algorithms (
<execution>). - Modern CMake: With
vcpkgfor package management. - Clang 21.1+: Primary compiler for C++26 support.
- Single-File Implementation: The core logic resides entirely in mandelbrot.cpp.
- Parallel Computation: The
calcfunction usesstd::execution::par_unseqto parallelize the Mandelbrot iteration across pixels. - Data Flow:
- Input: Arrow keys (pan), Numpad +/- (zoom), Numpad 1/2 (fractal exponent).
- Calculation:
mandelRescomputes iterations for a complex coordinate. Results are stored in astd::vector<uint8_t>buffer (heap-allocated). - Rendering:
drawconverts iteration counts to colors and updates a RaylibImage, which is then drawn to the screen.
- Coordinate Mapping:
scaleXandscaleYtransform screen coordinates to the complex plane[-2, 1] x [-1, 1].
The project uses vcpkg in manifest mode (vcpkg.json) and CMake Presets.
- Raylib: Graphics library.
- TBB: Parallelism library.
- Windows: Clang 21.1+ and Ninja build system.
- Linux: GCC 14+/Clang 17+ and Ninja (
sudo apt install build-essential ninja-build). - Common: Git and CMake 3.15+.
- Configure:
cmake --preset clang-release
- Build:
cmake --build --preset clang-release
- Run:
./build/clang-release/Mandelbrot.exe
- Configure:
cmake --preset ninja-release
- Build:
cmake --build --preset ninja-release
- Run:
./build/release/Mandelbrot
Note: The first configure step bootstraps vcpkg and builds dependencies (Raylib, TBB).
- C++ Standard: The codebase targets C++26 with Clang 21.1+.
- Types: Use
ctype(alias forlong double) for high-precision fractal math. Usestd::complex<ctype>for complex numbers. - Optimization:
- Valid optimizations are encouraged (e.g.,
std::normcheck). - The render loop only recalculates
calc()when the state (changedflag) is modified.
- Valid optimizations are encouraged (e.g.,
- Memory Management:
- The pixel buffer (
std::vector<uint8_t>) is heap-allocated to avoid stack overflow.
- The pixel buffer (
- Compiler Flags:
-Werror -Wall -Wextra -pedantic. Code must be warning-free.
- mandelbrot.cpp: Main application logic.
- CMakeLists.txt: Build configuration and compiler flags.
- vcpkg.json: Dependency manifest.
- CMakePresets.json: Build presets configuration.