This is a simple demonstration rainbow/arc application that plots values of
z <- z2 + c
for complex numbers z and c.
This formula is the one used to generate the Mandelbrot fractal.
Here is the code to generate the plot:
(def plot (plt c) (with (z 0.0+0.0i n 0 repeats 0) (while (and (small z) (< n 8000) (< repeats 1000)) (assign n (+ n 1) z (+ c (* z z)) repeats (if (apply plt (complex-parts z)) (+ repeats 1) 0)))))
I've used (assign n (+ n 1)) instead of (++ n),
and (assign z (+ c (* z z))) instead of (zap [+ c (* _ _)] z),
because ++ and zap, among other unused but otherwise cool macros,
use atomic internally, which slows things down awfully.
And it's slow enough already ... (each image is dynamically generated on the server on each request, I haven't got around to
caching yet, and I'm not even sure how)
Discussion on the arc forum or the fnargs blog.
Here are some points to get started with:
Static plots - plot the function for a given point, and its neighbours (the nc parameter determines neighbour closeness)
Animations - plot the function for a sequence of points along a line from x+iy to x0+iy0. Warning: some animations are very flashy depending on how chaotic the region you are exploring is. Generally, the more frames you use, the slower the animation will be - it's a bunch of png images animated with javascript, so a 1000-frame animation means a web page with 1000 images on it.
Do It Yourself
This application is written using Rainbow, an implementation of Arc in java. You can get rainbow at http://github.com/conanite/rainbow/tree/master. The app uses a BufferedImage to render each image, and ImageIO to convert this into a PNG stream. To run this yourself, download rainbow from github, compile and run it, type
arc> (start-spiral-app)and go to http://localhost:8085/spiral-intro.html (this page, but on your machine). It is known to work on java5 on macosx and ubuntu, and java6 on ubuntu. To run as a daemon process, remember to specify
-Djava.awt.headless=true.
Portions of this software are copyright (c) Conan Dalton 2008-2009. Permission
to use it is granted under the Perl Foundation's Artistic License 2.0.
This software is based on and uses software that is copyright (c) Paul Graham
and Robert Morris. Permission to use it is granted under the Perl Foundation's
Artistic License 2.0.
Perl Foundation's Artistic License 2.0