Draw a sphere: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: used a more idiomatic expression for getting the minimum. |
m →{{header|REXX}}: added whitespace and changed comments. |
||
Line 4,171:
Programming note: the output will appear slightly different when executed on an EBCDIC machine (due to different dithering characters).
<lang rexx>/*REXX program expresses a lighted sphere with simple characters used for shading. */
call drawSphere 19, 4, 2/10, '30 30
call drawSphere 10, 2, 4/10, '30 30
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
ceil: procedure; parse arg x; _= trunc(x); return _ +
floor: procedure; parse arg x; _= trunc(x); return _ -
norm: parse arg $a $b $c; _= sqrt($a**2 + $b**2 + $c**2); return $a/_ $b/_ $c/_
/*──────────────────────────────────────────────────────────────────────────────────────*/
drawSphere: procedure; parse arg r, k, ambient,
if
else shading= "·:!°oe@░▒▓" /* ASCII " " */
parse value norm(lightSource) with s1 s2 s3 /*normalize light source. */
shadeLen= length(shading) - 1; rr= r**2; r2= r+r /*handy─dandy variables. */
do i=floor(
do j=floor(-r2) to ceil(r2); y= j * .5 + .5;
if
b=
end
else $= $'
end /*j*/ /*[↓] strip trailing blanks*/
say strip($, 'T') /*show a line of the sphere*/
|