
Task
Generate and draw a Julia set.




Related tasks
   Mandelbrot Set


fcn juliaSet{
   w,h,zoom:=800,600, 1;
   bitmap:=PPM(w,h,0xFF|FF|FF);  // White background
 
   cX,cY:=-0.7, 0.27015;
   moveX,moveY:=0.0, 0.0;
   maxIter:=255;
 
   foreach x,y in (w,h){
      zx:=1.5*(x - w/2)/(0.5*zoom*w) + moveX;
      zy:=1.0*(y - h/2)/(0.5*zoom*h) + moveY;
      i:=maxIter;
      while(zx*zx + zy*zy < 4 and i > 1){
	 tmp:=zx*zx - zy*zy + cX;
	 zy,zx=2.0*zx*zy + cY, tmp;
	 i-=1;
      }
      // convert byte to RGB (3 bytes), kinda magic to get nice colors
      bitmap[x,y]=i.shiftLeft(21) + i.shiftLeft(10) + i*8;
   }
 
   bitmap.writeJPGFile("juliaSet.jpg",True);
}();