Anonymous user
Draw a sphere: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, simplified and optimized a function, used a template for the output.
(Added Julia language) |
m (→{{header|REXX}}: added/changed comments and whitespace, simplified and optimized a function, used a template for the output.) |
||
Line 3,936:
=={{header|REXX}}==
This program is modeled after the '''C''' version.
<br>Same with the '''CEIL'''ing and '''FLOOR''' functions.
<lang rexx>/*REXX program expresses a lighted sphere with simple characters used for shading. */
call drawSphere 19, 4, 2/10 /*draw a sphere with a radius of 19. */
Line 3,953 ⟶ 3,955:
lightSource= '30 30 -50' /*position of light source.*/
parse value norm(lightSource) with s1 s2 s3 /*normalize light source. */
do i=floor( -r)
do j=floor(-
if xx+yy<=rr then do /*is point within sphere ? */
parse value norm(x y sqrt(rr-xx-yy) ) with v1 v2 v3
dot=s1*v1 + s2*v2 + s3*v3
if dot>0 then dot=0 /*if positive, make it zero*/
b=
if b<=0 then brite=
else brite=
$=($)substr(shading, brite + 1, 1)
end /* [↑] build display line.*/
else $=$' ' /*append a blank to line. */
end /*j*/ /*[↓] strip trailing blanks*/
say strip($, 'T') /*show a line of the sphere*/
end /*i*/ /* [↑] display the sphere.*/
Line 3,977 ⟶ 3,979:
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/
numeric digits d; return g/1</lang>
<pre>
eeeeeeeeee@@@@@@@
|