Draw a sphere: Difference between revisions
Content added Content deleted
m (→{{header|PicoLisp}}: add {{libheader|GLUT}}) |
No edit summary |
||
Line 1,656: | Line 1,656: | ||
[[image:Tcl-spheroid.gif]] |
[[image:Tcl-spheroid.gif]] |
||
=={{header|XPL0}}== |
|||
[[File:SphereXPL0.png|right]] |
|||
<lang XPL0>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 |
|||
]</lang> |