20 lines
640 B
Text
20 lines
640 B
Text
fcn mandelbrot{ // lord this is slooooow
|
|
bitmap:=PPM(640,480);
|
|
foreach y,x in ([0..479],[0..639]){
|
|
cx:=(x.toFloat()/640 - 0.5)*4.0; //range: -2.0 to +2.0
|
|
cy:=((y-240).toFloat()/240.0)*1.5; //range: -1.5 to +1.5
|
|
cnt:=0; zx:=0.0; zy:=0.0;
|
|
do(1000){
|
|
if(zx*zx + zy*zy > 2.0){ //z heads toward infinity
|
|
//set color of pixel to rate it approaches infinity
|
|
bitmap[x,y]=cnt.shiftLeft(21) + cnt.shiftLeft(10) + cnt*8;
|
|
break;
|
|
}
|
|
temp:=zx*zy;
|
|
zx=zx*zx - zy*zy + cx; //calculate next iteration of z
|
|
zy=2.0*temp + cy;
|
|
cnt+=1;
|
|
}
|
|
}
|
|
bitmap.write(File("foo.ppm","wb"));
|
|
}();
|