ZSH Mandelbrot set generator
Back in 2001 I wrote a ZSH script that generates a Mandelbrot set in a terminal window. I posted it to the ZSH users mailing list and Bart Schaefer helped me optimise and sanitise it a bit. Then I didn’t think any more about it.
Just today, though, I went on a wee search to find it and discovered that it seems to have taken on a miniature life of it’s own on the web, so I figured I’d dig it out and repost it on here, just for the hell of it. So without further ado here is The Most Pointless Use of ZSH:
((columns=COLUMNS-1, lines=LINES))
((colour=0))
for ((b=-1.5;b<=1.5;b+=3.0/lines));do
for ((a=-2.0;a<=1;a+=3.0/columns));do
for (( p=0.0, q=0.0, i=0 ; p*p+q*q < 4 && i < 32 ; i++));do
((pnew=p*p-q*q+a, q=2*p*q+b, p=pnew))
done
((colour=(i/4)%8))
echo -n "\\e[4${colour}m "
done
echo
done
The original mailing list thread starts here and there’s another version with it as a function here There’s also a slightly more complex one out there that does something different with the colours but that doesn’t work for me.
I think that this is my most succesful bit of code ever…