Box the compass: Difference between revisions

Added XPL0 example.
m (BASIC256 and BBC BASIC moved to the BASIC section.)
(Added XPL0 example.)
Line 7,509:
1 North 354.38°
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang "XPL0">func Deg2Index(Heading); \Return index from heading in degrees
real Heading;
def Sector = 360./32.;
return (fix(Heading/Sector) & $1F) + 1;
 
real Headings;
int CompassPoint, H, Index;
[Headings:= [
0.0, 16.87, 16.88, 33.75, 50.62, 50.63, 67.5,
84.37, 84.38, 101.25, 118.12, 118.13, 135.0, 151.87, 151.88, 168.75,
185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12, 253.13, 270.0,
286.87, 286.88, 303.75, 320.62, 320.63, 337.5, 354.37, 354.38];
CompassPoint:= [
"North", "North by east", "North-northeast", "Northeast by north",
"Northeast", "Northeast by east", "East-northeast", "East by north",
"East", "East by south", "East-southeast", "Southeast by east",
"Southeast", "Southeast by south", "South-southeast", "South by east",
"South", "South by west", "South-southwest", "Southwest by south",
"Southwest", "Southwest by west", "West-southwest", "West by south",
"West", "West by north", "West-northwest", "Northwest by west",
"Northwest", "Northwest by north", "North-northwest", "North by west"];
Text(0, "Index Heading Compass Point^m^j");
for H:= 0 to 33-1 do
[Index:= Deg2Index(Headings(H));
Format(3,0);
RlOut(0, float(Index));
Format(7,2);
RlOut(0, Headings(H));
Text(0, " ");
Text(0, CompassPoint(Index-1));
CrLf(0);
];
]</syntaxhighlight>
{{out}}
<pre>
Index Heading Compass Point
1 0.00 North
2 16.87 North by east
3 16.88 North-northeast
4 33.75 Northeast by north
5 50.62 Northeast
6 50.63 Northeast by east
7 67.50 East-northeast
8 84.37 East by north
9 84.38 East
10 101.25 East by south
11 118.12 East-southeast
12 118.13 Southeast by east
13 135.00 Southeast
14 151.87 Southeast by south
15 151.88 South-southeast
16 168.75 South by east
17 185.62 South
18 185.63 South by west
19 202.50 South-southwest
20 219.37 Southwest by south
21 219.38 Southwest
22 236.25 Southwest by west
23 253.12 West-southwest
24 253.13 West by south
25 270.00 West
26 286.87 West by north
27 286.88 West-northwest
28 303.75 Northwest by west
29 320.62 Northwest
30 320.63 Northwest by north
31 337.50 North-northwest
32 354.37 North by west
1 354.38 North
</pre>
 
=={{header|Yabasic}}==
{{trans|Liberty BASIC}}
295

edits