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


include c:\cxpl\codes;          \intrinsic 'code' declarations
def     R=100, R2=R*R;          \radius, in pixels; radius squared
def     X0=640/2, Y0=480/2;     \coordinates of center of screen
int     X, Y, Z, C, D2;         \coords, color, distance from center squared
[SetVid($112);                  \set 640x480x24 graphics mode
for Y:= -R to +R do             \for all the coordinates near the circle
    for X:= -R to +R do         \ which is under the sphere
        [D2:= X*X + Y*Y;        
        C:= 0;                  \default color is black
        if D2 <= R2 then        \coordinate is inside circle under sphere
            [Z:= sqrt(R2-D2);   \height of point on surface of sphere above X,Y
            C:= Z-(X+Y)/2+130;  \color is proportional; offset X and Y, and
            ];                  \ shift color to upper limit of its range
        Point(X+X0, Y+Y0, C<<8+C); \green + blue = cyan
       ];
repeat until KeyHit;            \wait for keystroke
SetVid($03);                    \restore normal text mode
]