Draw a sphere: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: removed dead code from subroutine. -- ~~~~) |
|||
Line 1,631: | Line 1,631: | ||
shading='·:!ºoe@░▒█' /*for ASCI machines*/ |
shading='·:!ºoe@░▒█' /*for ASCI machines*/ |
||
if 1=='f1'x then shading='.:!*oe&#%@' /*for EBCDIC machs.*/ |
if 1=='f1'x then shading='.:!*oe&#%@' /*for EBCDIC machs.*/ |
||
parse value '30 30 -50' with s1 s2 s3 |
parse value '30 30 -50' with s1 s2 s3 /*the light source.*/ |
||
_=sqrt(s1**2 + s2**2 + s3**2); s1=s1/_; s2=s2/_; s3=s3/_ /*normalize S'*/ |
_=sqrt(s1**2 + s2**2 + s3**2); s1=s1/_; s2=s2/_; s3=s3/_ /*normalize S'*/ |
||
sLen=length(shading); sLen1=sLen-1; rr=r*r |
sLen=length(shading); sLen1=sLen-1; rr=r*r |
||
Line 1,638: | Line 1,638: | ||
do j=floor(-2*r) to ceil(2*r); y=j/2+.5; yy=y**2 |
do j=floor(-2*r) to ceil(2*r); y=j/2+.5; yy=y**2 |
||
if xx+yy<=rr then do |
if xx+yy<=rr then do |
||
parse value x y sqrt(rr-xx-yy) with v1 v2 v3 |
parse value x y sqrt(rr-xx-yy) with v1 v2 v3 |
||
_=sqrt(v1**2 + v2**2 + v3**2) |
_=sqrt(v1**2 + v2**2 + v3**2) |
||
v1=v1/_; v2=v2/_; v3=v3/_ /*normalize V's.*/ |
v1=v1/_; v2=v2/_; v3=v3/_ /*normalize V's.*/ |
||
Line 1,654: | Line 1,654: | ||
return |
return |
||
/*─────────────────────────────────────"1─liner" subroutines────────────*/ |
/*─────────────────────────────────────"1─liner" subroutines────────────*/ |
||
sqrt: procedure |
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits() |
||
numeric digits 11; g=.sqrtGuess(); do j=0 while p>9; m.j=p;p=p%2+1;end |
numeric digits 11; g=.sqrtGuess(); do j=0 while p>9; m.j=p;p=p%2+1;end |
||
do k=j+5 to 0 by -1; if m.k>11 then numeric digits m.k |
do k=j+5 to 0 by -1; if m.k>11 then numeric digits m.k |