JS source: docs/appscripts/mandelbrot.js
View the visualization here!
NOT compatible with Firefox/Internet Explorer.
The Mandelbrot Set is the set of complex numbers for which sequences as defined by the following recurrence relation are not divergent (do not tend to infinity):
The script uses an escape algorithm that iterates each point on the complex plane through the recurrence relation until a certain maximum norm is reached, or a maximum number of iterations is reached. The iteration number is then recorded and use to scale the color of each of the points on the canvas.
function EscapeAlgorithm(pointX, pointY) {
// Escape Algorithm
var current = 0;
var x = 0;
var y = 0;
/*
While current iteration number is less than preset limit and norm is
less than its preset limit, repeat algorithm as defined by the mandelbrot
set recurrence relation, and increment iteration number. Return the
iteration number at the end.
*/
while ((current < MAX_ITERATIONS) && (x * x + y * y < MAX_NORM)) {
const xNext = x * x - y * y;
const yNext = 2 * x * y;
x = xNext + pointX;
y = yNext + pointY;
current++;
}
return current;
}
More about the Mandelbrot Set:
- An excellent video from Numberphile featuring Dr. Holly Krieger: https://www.youtube.com/watch?v=NGMRB4O922I
- Wolfram MathWorld's page on the Mandelbrot Set: http://mathworld.wolfram.com/MandelbrotSet.html
Notes of thanks to:
- Dr. Lonce Wyse, my first mentor in all things Javascript and Canvas