A fractal generator written in Go, as cli, library and web app.
This is a work in progress. The main goal is to have the full functionality (and more) as my previous project JFractGen.
Some Examples:
- generate Mandelbrot and Julia fractals
- create fractals as png / jpeg
- start a web server for interactive usage in a Web application
- use a presets file to configure the fractal parameters and color palettes
- float64 precision
go build -o fractgen
# for global help and commands:
fractgen --help
# for a specific command:
fractgen [command] --help
fractgen serve
# with a different port / IP binding:
fractgen serve --listen 127.0.0.1:8001
# to list all available options:
fractgen image --help
# generate a Mandelbrot fractal image to "my-image.jpg" with a custom color palette and 1000 iterations:
fractgen image --max-iter=1000 --color-preset=red-alert my-image.jpg
With the flight
command, you can create a flight through a fractal from a start point to an end point.
go run main.go flight --duration 60 --fps 30 \
--width=720 \
--height=405 \
--start-center-cx=1 \
--start-center-cy=0 \
--start-diameter-cx=3 \
--end-center-cx=-0.736882432177663 \
--end-center-cy=0.17482000150317034 \
--end-diameter-cx=2.0116567611694336e-7 \
--color-preset=patchwork \
--palette-repeat=1 \
--palette-length=-1 \
--max-iter=1000 \
output
This generates a series of images in the output
folder. If you want to generate a video from the images, you can use ffmpeg
:
ffmpeg -framerate 30 -pattern_type glob -i '*.jpeg' -c:v libx264 -pix_fmt yuv420p out.mp4
fractgen
comes with a set of built-in color and fractal presets. To list the available presets, run:
fractgen presets
The presets are available in the Web UI, and you can use them with the image generation commands, e.g.:
fractgen image --fractal-preset="Mandelbrot Total" "mandelbrot_total.jpg"
You can define your own presets in a JSON. The preset JSON's structure is as follows:
{
"colorPresets": [
{
"name": "Patchwork",
"ident": "patchwork",
"colors": [
{ "a": 255, "r": 0, "b": 30, "g": 0 },
{ "a": 255, "r": 253, "b": 6, "g": 204 },
{ "a": 255, "r": 186, "b": 15, "g": 84 }
]
},
// .....
],
"fractalPresets": [
{
"maxIterations": 40,
"diameterCX": 4,
"colorPreset": "patchwork",
"juliaKi": 0.6,
"colorPaletteLength": -1,
"iterFunc": "Mandelbrot",
"name": "Mandelbrot Total",
"colorPaletteRepeat": 1,
"centerCY": 0,
"centerCX": -0.7,
"juliaKr": -0.6
},
// .....
]
}
The JSON file can be used with the --presets-file
command line option, e.g.:
fractgen image --presets-file=presets.json --fractal-preset="Mandelbrot Total" "mandelbrot_total.jpg"
- implement missing fractal functions (julia, mandelbrot ^ n, ...)
- Embed default preset.json in binary (using go embed)
- palette inversion (reverse order)
- palette length: bound to max iter (done), or fixed length
- embed fract params in image metadata
- more coloring options:
- orbit traps
-
create a cli app
- create a serve command to start a web server
- create an image command to generate a single image
- create a movie command to generate a series of images / movie
-
create movie / animation from start to end point / zoom level
- Treat the fractal plane as grid: Create a grid-based approach to generate and cache the images, using a Mapping library like OpenLayers to render the tiles. This allows for easy pre-generation and caching of the fractal images as tiles.
- Caching of generated images, using wmts tiles from above, and the necessary metadata as key
- zoom in/out with buttons
- zoom in with double-click
- zoom in with drag a rectangle
- zoom in pinch zoom
- History / Undo stack
- fractal params in URL / as query params, instead of local storage
- export fractal params as JSON
- export fractal params as png / jpeg
- import function: import a preset / a color scheme
- palette editor
IFS=$'\n' jq -r '.fractalPresets.[].name' presets.json | while read preset; do; \
echo "Working on '${preset}'"; \
./fractgen image \
--fractal-preset="${preset}" \
--width=3840 \
--height=2400 \
"output/${preset}.jpg"; \
done
go run main.go flight --duration 60 --fps 60 \
--width=1920 \
--height=1080 \
--start-center-cx=-0.7 \
--start-center-cy=0 \
--start-diameter-cx=3 \
--end-center-cx=-0.736882432177663 \
--end-center-cy=0.17482000150317034 \
--end-diameter-cx=2.0116567611694336e-7 \
--color-preset=patchwork \
--palette-repeat=1 \
--palette-length=-1 \
--max-iter=1000 \
output