Task

Draw a sphere.

The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.

Either static or rotational projection is acceptable for this task.



Related tasks

 draw a cuboid
 draw a rotating cube
 write language name in 3D ASCII
 draw a Deathstar


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"));