home
ZSH Julia set
I was bored and was messing with my Mandelbrot generator when I thought “why not try a Julia set?”, and why not indeed? It’s a fairly simple change to the Mandelbrot set algorithm.
((columns=COLUMNS-1, lines=LINES))
((colour=0))
if [[ ! $# -eq 2 ]]; then
((ci=1, cr=0))
elif [[ $# -eq 2 ]]; then
((ci=$1, cr=$2))
fi
for ((b=-2.0;b<=2;b+=4.0/lines));do
for ((a=-2.0;a<=2;a+=4.0/columns));do
for (( p=a, q=b, i=0 ; p*p+q*q < 4 && i < 32 ; i++));do
((pnew=p*p-q*q+cr, q=2*p*q+ci, p=pnew))
done
((colour=(i/4)%8))
echo -n "\\e[4${colour}m "
done
echo
done
It will automatically give you a basic Julia set based on the equation i, but you can try messing about with different values, like for the equation 0.03i+0.3 you would run the script something like:
./julia.zsh 0.03 0.3
If you have no idea what I’m talking about just try plugging in two numbers between -2 and 2 and you’ll get a bunch of different shapes.
Update: Check out the stupid, stupid if/elif. If I came across that in someone else’s code I would have a good laugh. Feel free.