cslarsen/mandelbrot-js ↗
Created Dec 13, 2020 · View the cslarsen/mandelbrot-js repository page
Fast rendering of the Mandelbrot set in HTML5 canvas using JavaScript
Want this for your repo?
Render a free sample of any GitHub repo in seconds.
About cslarsen/mandelbrot-js
This is a vanilla JavaScript implementation of a fast Mandelbrot set renderer using HTML5 canvas. The project renders the famous fractal by iteratively calculating whether points in the complex plane converge or diverge, then visualizing the results with smooth color gradients based on iteration counts.
The codebase demonstrates numerous performance optimization techniques tailored for JavaScript execution. These include eliminating square root operations by comparing squared magnitudes, exploiting the vertical symmetry of the Mandelbrot set, simplifying the main iteration equation to use additions instead of multiplications where possible, and optimizing pixel array access through sequential indexing rather than calculating offsets for each pixel. The author also employs anti-aliasing through random supersampling to reduce pixel artifacts, especially along the boundary of the set.
The implementation includes detailed documentation explaining both the mathematical theory underlying the Mandelbrot set and the practical engineering decisions made for performance. The smooth coloring technique uses logarithmic interpolation to avoid banding artifacts, and the rendering employs a line-by-line copying strategy to minimize canvas update overhead. The project is released under the Apache License 2.0 and represents a comprehensive study in optimizing computationally intensive graphics rendering within browser constraints.