Plotting Fractals in WebAssembly
|1: Plotting Fractals||2: Initial Implementation||3: Basic WAT Implementation|
|2.1: Basic Escape-Time Implementation|
2: Initial Implementation
In its simplest form, the algorithm to plot either the Mandelbrot or Julia Sets is just a highly repetitive calculation known as an “escape-time” algorithm. That is, we perform a feedback loop in which we take the number that comes out of the previous iteration and put it back into the next iteration until the value either escapes to infinity, or we exceed some arbitrary time limit.
- The fractal image will be displayed using the 2d context of an HTML
- We require a function that can transform the
(x, y)location of a pixel in the
canvaselement to the corresponding
(x, y)location on the complex plane. To start with, we will simply assume that such a function is available and not care about its implementation
- The escape-time algorithm must be called for every pixel in the image. This algorithm returns a number ranging between 1 and
- To plot the fractal image, we need a function that transforms the number returned by the escape-time algorithm into a colour. Again, we assume that such a function is available and do not care about its implementation.