Skip to content

C++14 Buddhabrot renderer, based on Alex Boswell's code

Notifications You must be signed in to change notification settings

Quuxplusone/Buddhabrot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Buddhabrot

This is a simple Buddhabrot generator, based on Alex Boswell's C++ code from http://www.steckles.com/buddha/ (circa 2006).

It can render zoomed-in portions of the Buddhabrot, as PPM images.

  • To pick your zoom target, edit main.cpp and adjust TargetProperties.

  • To pick your image width and height, edit main.cpp and adjust BitmapProperties.

  • Run make, then ./buddha. It will run forever, periodically overwriting the files red.pgm, green.pgm, blue.pgm, and color.ppm in the current directory.


To reproduce the above image, very similar to Wikipedia's "Nebulabrot," run the Classic method with target {-0.4, 0, 0.32} and bitmap { 4096, 4096 } for as long as you can tolerate, and then tweak its color levels like this:

convert color.ppm -normalize -level '0,90%' -gamma 0.3 -scale 400x400 nebulabrot.jpg

Metropolis–Hastings versus Classic

You can also edit main.cpp to switch from RenderBuddhabrotMetro() to RenderBuddhabrotClassic().

The classic method simply picks points at random from the whole disk and graphs their trajectories. Its advantage is that it produces a really correct image. Its disadvantage is that when you zoom into a small target, the vast majority of random points will never affect any pixels in the view window at all.

The Metropolis–Hastings method (based on code and math originally by Alex Boswell) begins by selecting a small population of points whose trajectories cross the the view window at least once. Then, it produces new points by mutating the existing population — jiggling these points by small amounts, and discarding them if the jiggles cause them to fall out of the view window. Finally, it introduces new random points fairly often, to reduce the effects of getting "stuck" in one area of the disk and never exploring other areas. Its advantage is that it works great for zooming into a small target. Its disadvantage is that it produces artificially high-contrast images.

Note the visual difference between images generated with the classic algorithm and the Metropolis–Hastings algorithm. Each image is the result of evaluating trajectories for one million candidate points, with bitmap = {640, 480}. The first row uses target = {-0.4, 0, 0.32}; the second row uses target = {-0.657560793, 0.467732884, 70.5} (i.e. target5).

Classic Metro, 100% replacement Metro, 50% replacement Metro, 33% replacement Metro, 25% replacement Metro, 20% replacement
50.3s 43.4s 55.1s 64.4s 80.6s 54.4s
66.9s 58.8s 40.3s 31.3s 34.6s 26.1s

Benedikt Bitterli describes a perhaps more mathematically sound approach using "importance maps" (which are interesting visualizations in themselves), but this repository doesn't contain any code related to that approach.

Other renderers

Other (and perhaps better) Buddhabrot renderers include:

See also

About

C++14 Buddhabrot renderer, based on Alex Boswell's code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published