Box the compass: Difference between revisions
Content added Content deleted
(→{{header|AppleScript}}: Added a simpler alternative.) |
Walterpachl (talk | contribs) (→{{header|REXX}}: refurbished and extended the output) |
||
Line 6,474: | Line 6,474: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
This version does normalization of the (degree) heading and can also handle negative headings. |
This version does normalization of the (degree) heading and can also handle negative headings. |
||
<syntaxhighlight lang="rexx">/*REXX program "boxes the compass" |
<syntaxhighlight lang="rexx">/*REXX program "boxes the compass" */ |
||
/* [from degree (º) headings ---> a 32 point set]. */ |
|||
Parse Arg degrees |
|||
if $='' then $= 0 16.87 16.88 33.75 50.62 50.63 67.5 84.37 84.38 101.25 118.12 118.13 , |
|||
If degrees='' Then |
|||
⚫ | |||
degrees=0 16.87 16.88 33.75 50.62 50.63 67.5 84.37 84.38 101.25, |
|||
⚫ | |||
⚫ | |||
219.37 219.38 236.25 253.12 253.13 270 286.87 286.88 303.75, |
|||
⚫ | |||
320.62 320.63 337.5 354.37 354.38 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
nn=words(names)+1 /* nn: used for integer ÷ remainder */ |
|||
dirs= |
dirs='north south east west' /* define cardinal compass directions*/ |
||
/* choose a glyph for degree (°).*/ |
|||
If 4=='f4'x Then /* is this system an EBCDIC system*/ |
|||
degsym='a1'x |
|||
else degSym= "a7"x /*'f8'x is the degree symbol: ° vs º */ |
|||
Else |
|||
/*──────────────────────────── f8 vs a7*/ |
|||
⚫ | |||
say right(degSym'heading', 30) center("compass heading", 20) |
|||
Say right(degsym'heading',30) center('compass heading',20) |
|||
Say right('--------',30) copies('-',20) |
|||
⚫ | |||
pad=' ' /* used to interject a blank for o */ |
|||
Do i=1 To words(degrees) |
|||
⚫ | |||
x=word(degrees,i) /* obtain one of the degree headings */ |
|||
⚫ | |||
exit /*stick a fork in it, we're all done. */ |
|||
End |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
boxHeading: y= arg(1)//360; if y<0 then y=360-y /*normalize heading within unit circle.*/ |
|||
/*---------------------------------------------------------------------*/ |
|||
⚫ | |||
boxheading: |
|||
do k=1 for words(dirs); d= word(dirs, k) |
|||
y=arg(1)//360 |
|||
z= changestr( left(d, 1), z, d) |
|||
If y<0 Then |
|||
end /*k*/ /* [↑] old, haystack, new*/ |
|||
y=360-y /* normalize heading within unit circle */ |
|||
⚫ | |||
/* n e s w are now replaced by north east south west, respectively */ |
|||
Do k=1 To words(dirs) |
|||
d=word(dirs,k) |
|||
z=changestr(left(d,1),z,d) |
|||
End |
|||
Return changestr('b',z,' by ') /* expand 'b' ---? ' by '. */</syntaxhighlight> |
|||
Some older REXXes don't have a '''changestr''' BIF, so one is included here ──► [[CHANGESTR.REX]]. |
Some older REXXes don't have a '''changestr''' BIF, so one is included here ──► [[CHANGESTR.REX]]. |
||
<br><br> |
<br><br> |
||
{{out}} |
|||
'''output''' |
|||
<pre> |
<pre> |
||
ºheading compass heading |
ºheading compass heading |
||
Line 6,543: | Line 6,552: | ||
354.38º north |
354.38º north |
||
</pre> |
</pre> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
<syntaxhighlight lang="ring"> |
<syntaxhighlight lang="ring"> |