Mandelbrot set viewer

This is a viewer for the Mandelbrot set that I developed to experiment with web assembly (wasm). It's still work-in-progress (web workers might be added). The GUI is rudimentary (surely with some bugs), but good enough to explore the set. There are surely dozens of viewers, here's a more complete one, with better controls: https://math.hws.edu/eck/js/mandelbrot/MB-info.html.

I had never explored the Mandelbrot set before, it was quite a revelation to see how the basic initial pattern (that we see here) repeats millions number of times as we zoom in into the set. The pattern continues to appear clearly all the way to 2**45 magnification with this viewer (getting close to the limit of precision of double floats where pixelization appears), and I presume this continues into infinity. The Wiki article provides more information on the mathematics of the Mandelbrot set.

As a side project, I also experimented with the computer generation of a video, using python tools (opencv-python and PIL) to generate the video, and C code to generate the frames (about 1600). This 52-second video shows a dive into the set to a depth of about 2**42 (nearing the limit of precision of double floats), centered on xOff=-0.16756006268737844, yOff=1.0413332797562471, with a gradual increase in the algorithm parameter "max iterations". The same pattern repeats (presumably into infinity). Once zooming is done (around 0:43), "max iterations" is gradually decreased again from about 100000 down to 5000, showing the effect of this parameter. This is a simple video, there are quite a few really impressive videos on the Web (including a few hour-long videos diving much deeper into the set, down beyond 10**1000).

Run the Mandelbrot set viewer.

Usage notes:

In the parms area, "ppu" is "pixels per unit", ie. how many pixels there are between 0.0 and 1.0 on either axis; xOff and yOff refer to the point at the center of the image; "inset" refers to the percentage of pixels that reached max iterations.

Maximum iterations ("maxit" in the parms area) of the algorithm increase as one zooms in, but possibly not quite enough (keyboard up arrow can be used to increase it, but it will slow the algorithm down significantly).

Magnification is possible up to about 2**45 (~ 10**14); going much further shows pixelization, we have reached the precision limit of double floats.

I've tried various things for the colors. I've tried to show colors that are mathematically meaningful (as opposed to aesthetically pleasing). With the current version, pixels considered to be in the set come out yellow, and pixels that come close to max iterations become reddish. In a previous version, colors were based on the last x,y inside the circle before escaping to set the color. At the right is an example of what this looked like.

Drawing a new frame in the Mandelbrot set can take quite a bit of time (tens of seconds), esp. with high maximum iterations (up arrow or some letter patterns), and/or if the frame contains a lot of pixels that are in the set or close. With Safari on MacOS, I have no issue in such cases, but Chrome may complain that the page is taking too long to display, but nonetheless allows one to continue.

The web assembly code is here. In theory, web assembly (wasm) is supposed to run at near native speeds. On my two Macs, performance of this little app is nearly three times slower on Chrome when compared to Safari. That is quite surprising. Clearly it's not near-native speed on Chrome! Playing with some flags (near chrome://flags/#enable-webassembly-baseline -- I didn't take notes) cut times by a factor of two. It could also be related to developer tools. But it's still significantly slower. Firefox is comparable to Safari. I also compared the Safari times with an equivalent C program (compiled with -O3), and the times are very close, so this little app on Safari does seem to run at near-native speeds. It's worth trying all browsers you have access to if you wish to explore the Mandelbrot set with this page. Note also that web assembly is fairly new technology, it might not work as expected in your environment...

This viewer is based on this blog on programming using web assembly by Alexander Curtis.


Run the Mandelbrot set viewer.