Draw a sphere: Difference between revisions

Content added Content deleted
m (Updated D entry)
m (→‎{{header|REXX}}: removed superflous blanks. -- ~~~~)
Line 1,496: Line 1,496:
<br>The REXX language doesn't have a SQRT function, so I included a version.
<br>The REXX language doesn't have a SQRT function, so I included a version.
<br>Same with CEILing and FLOOR.
<br>Same with CEILing and FLOOR.
<lang rexx>/*REXX program to express a lighted sphere with simple chars for shading*/
<lang rexx>
/*REXX program to express a lighted sphere with simple chars for shading*/

call drawSphere 19, 4, 2/10
call drawSphere 19, 4, 2/10
call drawSphere 10, 2, 4/10
call drawSphere 10, 2, 4/10
exit
exit

/*─────────────────────────────────────drawSphere subroutine────────────*/
/*─────────────────────────────────────drawSphere subroutine────────────*/
drawSphere: procedure; parse arg r,k,ambient
drawSphere: procedure; parse arg r,k,ambient
Line 1,529: Line 1,526:
end /*i*/
end /*i*/
return
return

/*─────────────────────────────────────"1─liner" subroutines────────────*/
/*─────────────────────────────────────"1─liner" subroutines────────────*/
sqrt: procedure expose $.; parse arg x; if x=0 then return 0; d=digits()
sqrt: procedure expose $.; parse arg x; if x=0 then return 0; d=digits()
Line 1,538: Line 1,534:
parse value format(x,2,1,,0) 'E0' with g 'E' _ .;return g*.5'E'_%2
parse value format(x,2,1,,0) 'E0' with g 'E' _ .;return g*.5'E'_%2
ceil: procedure; parse arg x; _=trunc(x); return _+(x>0)*(x\=_)
ceil: procedure; parse arg x; _=trunc(x); return _+(x>0)*(x\=_)
floor: procedure; parse arg x; _=trunc(x); return _-(x<0)*(x\=_)
floor: procedure; parse arg x; _=trunc(x); return _-(x<0)*(x\=_)</lang>
</lang>
Output:
Output:
<pre style="height:105ex;overflow:scroll">
<pre style="height:105ex;overflow:scroll">