A utility for quickly rendering high-quality fractal images.
Currently this library supports five different fractals:
- Mandelbrot Set
- Julia Set (for the 𝑝(𝑧) = 𝑧² + 𝑐 quadratic map)
- Barnsley Fern
- Attractor of the Driven-Damped Pendulum
- Generalized Serpinsky Triangle to support N-sided polygons
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.
Serpinksy "Triangle"
Visualization for the Serpinksy fractal, but generalized to a N-degree polygon. There are many ways to construct this fractal. This approach is implemented by sampling a sampling points from a sequence. Source here.
Julia Quadratic Map
Visualization of the Julia set. 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.
Explore Mode:
The explore
mode is still a bit of a work-in-progress, but the prototype is fun to play around with!
It is quite responsive for both the Mandelbrot and Julia Sets, provided you run with reasonable settings and don't fill up the screen with "max iteration" data. The Driven-Damped Pendulum is much more computationally expensive, so that one is a bit laggy.
I'm actively experimenting with algorithms to dynamically adjust the render parameters for each fractal to hit a target frame rate of 30 Hz.
Both the explore
and render
modes of operation accept the same JSON file format as input, which describes the fractal to be rendered. This JSON file is loaded by serde
into the common::FractalParams
enum, which tells the program what fractal to render, along with what parameters to use.
The examples listed below are designed to run relatively quickly. Within each examples/*
subdirectory you'll find several other parameter files that generate some interesting renders.
Render Mode
Run in release mode, pass the render
argument, followed by a JSON file path:
cargo run --release -- render ./examples/mandelbrot/default.json
cargo run --release -- render ./examples/julia/default.json
cargo run --release -- render ./examples/driven_damped_pendulum/default.json
cargo run --release -- render ./examples/barnsley_fern/default.json
cargo run --release -- render ./examples/serpinsky/triangle.json
Explore Mode:
Explore mode will open a GUI and immediately render the fractal with the specified parameters.
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 to initial viewesc
close the GUIspace
write image to file along with (partial) JSON params
When actively interacting with the fractal, it will render in "fast mode", at a lower resolution. Once interaction has stopped, it will render at progressively higher quality, stopping at the original parameters. This feature is still experimental.
User events received during rendering will be condensed and processed after rendering. Eventually I plan to add the ability to interrupt a slow render with a GUI event.
The calling pattern matches render
, and it uses the same JSON files:
cargo run --release -- explore ./examples/mandelbrot/default.json
cargo run --release -- explore ./examples/julia/default.json
cargo run --release -- explore ./examples/driven_damped_pendulum/ddp_low_res_antialias.json
Note that explore
mode does not support the barnsley fern or serpinsky triangle.
Color-Swatch Mode
The simple "color-swatch" mode is used for debugging and tweaking color map data. It has a slightly different input format.
cargo run --release -- color-swatch examples/color_swatch/rainbow.json
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 via prettier. Rust code is formatted and linted with the standard tooling.
Thanks to the excellent example from the pixel.rs, which was really helpful in getting the GUI working: pixels/examples/conway.