A utility for rendering and exploring various 2D fractal images.
Currently this library supports six different fractals:
- Mandelbrot Set
- Julia Set (for the 𝑝(𝑧) = 𝑧² + 𝑐 quadratic map)
- Barnsley Fern
- Attractor of the Driven-Damped Pendulum
- Generalized Sierpiński Triangle to support N-sided polygons
- Newton's Method fractals (roots of unity and cosh 𝑧 − 1)
The binary produced by this project primarily supports two modes of operation:
render-- used to render a single image directly to an output fileexplore-- opens an interactive GUI to pan and zoom around the fractal
Driven-Damped Pendulum
Visualization of the basin of attraction for the driven-damped pendulum, where each period in the fractal is one full revolution of the pendulum. Source here.
Barnsley Fern
Visualization of the Barnsley Fern, with the render settings tweaked so that it appears to be shadowed. Source here.
Mandelbrot Set
Visualization of the Mandelbrot Set with a dark blue color map and zoomed in a bit. Source here.
Sierpiński "Triangle"
Visualization for the Sierpiński fractal, but generalized to an N-sided polygon. There are many ways to construct this fractal. This approach is implemented by sampling points from a sequence. Source here.
Julia Quadratic Map
Visualization of the Julia set. Source here.
Newton's Method Basin of Attraction
Visualization of the basin of attraction for each root in a Newton's method solve for various equations. Visualization here is for f(z) = cosh(z) - 1. Source here.
This library is under active development, with plans to add support for more fractals and features over time.
Render Mode:
The render mode of operation is well developed -- it can be used right now to quickly generate high-quality fractal renders. Each render is fully described by a JSON file, making it easy to reproduce and tweak render images.
Explore Mode:
The explore mode enables the user to "fly around exploring the fractal" using the arrow keys to pan and WASD to adjust the instantaneous zoom rate. It supports the Mandelbrot set, Julia set, driven-damped pendulum, and Newton's method fractals. There is also a side-panel for live editing of the color map: a color picker, dynamically adding and removing keyframes, dragging to adjust the width of each gradient segment, and setting the background color used for in-set cells.
The color map edits operate on the cached scalar fields from the fractal, so they are super responsive. During interactive pan and zoom operations, the GUI will dynamically adjust the resolution and solve parameters, attempting to hit a 30 FPS render rate. As soon as interaction is done, it will progressively scale up to full quality renders.
Hitting spacebar during explore mode forces a full-quality render and writes it to file, along with a complete parameter set that reproduces the current view and color map.
This project includes a large collection of examples under the examples/ directory, covering both render-* and explore-* modes of operation, across all of the various types of fractals (*-mandelbrot-*, *-julia-*, *-driven-damped-pendulum-*, *-newton-*, ...). Each example is a Cargo example: a directory containing a lightweight main.rs wrapper plus a params.json file. The wrapper just loads the parameters and calls into the library to do the heavy lifting. To list all available examples, run cargo run --example with no name.
Many of the examples, especially the driven-damped pendulum, are computationally intensive, so it is usually a good idea to run them with the --release flag. This project defines a cargo alias, rex (run --release --example), so cargo rex <name> runs an example in release mode.
Render Mode
Run an example by name. These render a single image to file:
cargo rex render-mandelbrot-default
cargo rex render-julia-spiral
cargo rex render-driven-damped-pendulum
cargo rex render-barnsley-fern
cargo rex render-sierpinski-triangle
cargo rex render-newton-roots-of-unity-4
Explore Mode:
Explore mode opens a GUI and immediately renders the fractal with the specified parameters:
cargo rex explore-mandelbrot-default
cargo rex explore-julia-spiral
cargo rex explore-newton-cosh-minus-one
cargo rex explore-driven-damped-pendulum-quickly
You can interact with the GUI in the following ways:
a/d: rapid zoomw/s: standard zoom- arrow keys: pan
- click: pan to center window on selected point
r: reset the view and color map to their initial stateq(orCtrl+C): close the GUIspace: force a full-quality render and write it to file along with a complete JSON parameter set- click a keyframe to select it;
Deleteremoves the selected keyframe andEscclears the selection
When actively interacting with the fractal, it dynamically adjusts the resolution and convergence parameters to keep the GUI responsive. Once interaction stops, it renders at progressively higher quality, stopping at the original parameters. User events received during a render are condensed and processed once the render completes.
Note that explore mode does not support the Barnsley fern or Sierpiński triangle.
The software for the fractal renderer was written with two goals in mind:
- Be clear, correct, and maintainable
- Render images as fast as possible
Working toward these goals:
- Most of the "inner loops" of the rendering pipeline are parallelized with Rayon
- Much of the core library and examples are covered by unit tests
- There are integration tests for full rendering pipeline
- Core library components are modular, documented, and shared between the different fractals.
- Generics are used extensively to achieve static polymorphism
Refer to CONTRIBUTING.md file if you are interested in contributing to this project.
This project is covered by the MIT LICENSE.
JSON and Markdown formatting uses Prettier. Run npm install once to install it, then npm run fmt to auto-format or npm run fmt:check to verify. Use a current Node.js release with a recent npm version compatible with the committed package-lock.json; if npm install fails on an older setup, upgrade npm (or Node.js, which bundles npm). Rust code is formatted and linted with the standard tooling (cargo fmt, cargo clippy).
The interactive explore-mode GUI is built on the excellent eframe/egui immediate-mode UI toolkit, which made the live color-map editor and render window straightforward to build.





