RosettaCodeData/Task/Draw-a-sphere/Zkl/draw-a-sphere-1.zkl
2023-07-01 13:44:08 -04:00

15 lines
726 B
Text

img:=PPM(640,480);
R:=100; R2:=R*R; //radius, in pixels; radius squared
X0:=640/2; Y0:=480/2; //coordinates of center of screen
foreach Y in ([-R..R]){ //for all the coordinates near the circle
foreach X in ([-R..R]){ // which is under the sphere
D2:=X*X + Y*Y;
C:=0; //default color is black
if(D2<=R2){ //coordinate is inside circle under sphere
Z:=(R2-D2).toFloat().sqrt();//height of point on surface of sphere above X,Y
C=0x82+Z-(X+Y)/2; //color is proportional; offset X and Y, and
} // shift color to upper limit of its range
img[X+X0,Y+Y0]=C.shiftLeft(8)+C; //green + blue = cyan
}
}
img.write(File("foo.ppm","wb"));