I've written a mandelbrot set explorer for the HTML5 canvas in Hot Cocoa Lisp
git clone git@github.com:olleicua/hcl-canvas-mandelbrot.git
- open hcl-canvas-mandelbrot/mandelbrot.html in a web browser
- use
w
,a
,s
, andd
to move around,q
to zoom in, ande
to zoom out
Install:
npm -g install hot-cocoa-lisp
git clone git@github.com:olleicua/hcl-canvas-mandelbrot.git
cd hcl-canvas-mandelbrot
And compile:
hcl -b mandelbrot.hcl
I'm using two notable optimizations so far:
Without this optimization we would have:
While (zr * zr) + (zi * zi) < 4
zr = (zr * zr) - (zi * zi) + cr
zi = (2 * zr * zi) + ci
Multiplication is expensive and there are six of them here. Instead I used an optimization I found here: http://randomascii.wordpress.com/2011/08/13/faster-fractals-through-algebra/
zrsqr = zr * zr;
zisqr = zi * zi;
While zrsqr + zisqr < 4
zi *= zr
zi += zi
zi += ci;
zr = zrsqr – zisqr + cr
zrsqr = (zr * zr)
zisqr = (zi * zi)
}
I used a technique described here (http://locklessinc.com/articles/mandelbrot/) to check whether the cycle of z
s enters a loop and stop immediately if it does rather than continuing on to maxIter