Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -0,0 +1,27 @@
USING: formatting kernel math sequences ;
CONSTANT: box
{
"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"
}
{
0 16.87 16.88 33.75 50.62 50.63 67.5 84.37 84.38 101.25
118.12 118.13 135 151.87 151.88 168.75 185.62 185.63 202.5
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
}
[
dup 32 * 360 /f 0.5 + >integer 32 mod [ 1 + ] [ box nth ] bi
"%6.2f° %2d %s\n" printf
] each

View file

@ -1,23 +1,23 @@
function degree2compasspoint(d::Float64)::String
majors = ("north", "east", "south", "ovest", "north", "east", "south", "ovest")
quart1 = ("N", "N by E", "N-NE", "NE by N", "NE", "NE by E", "E-NE", "E by N")
using Printf
d = (d % 360) + 360/64
majorindex, minor = divrem(d, 90)
minorindex = div(minor * 4, 45)
majorindex += 1
minorindex += 1
p1, p2 = majors[majorindex:majorindex+1]
if p1 in ("north", "south"); q = quart1
else q = quart1 end
return titlecase(replace(replace(q[minorindex], 'N', p1), 'E', p2))
function degree2compasspoint(d::Float64)
majors = ("north", "east", "south", "west", "north", "east", "south", "west")
quarter1 = ("N", "N by E", "N-NE", "NE by N", "NE", "NE by E", "E-NE", "E by N")
quarter2 = map(p -> replace(p, "NE" => "EN"), quarter1)
d = d % 360 + 360 / 64
imajor, minor = divrem(d, 90)
iminor = div(minor * 4, 45)
imajor += 1
iminor += 1
p1, p2 = majors[imajor:imajor+1]
q = p1 in ("north", "south") ? quarter1 : quarter2
titlecase(replace(replace(q[iminor], 'N' => p1), 'E' => p2))
end
for i in 0:32
d = i * 11.25
m = i % 3
if m == 1; d += 5.62 end
if m == 2; d -= 5.62 end
n = i % 32 + 1
@printf("%2i %-17s %10.2f°\n", n, degree2compasspoint(d), d)
i % 3 == 1 && (d += 5.62)
i % 3 == 2 && (d -= 5.62)
@printf("%2i %-17s %10.2f°\n", i % 32 + 1, degree2compasspoint(d), d)
end

View file

@ -1,18 +1,30 @@
import strfmt
import math, sequtils, strformat, strutils
const names = [
"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", "North"]
const
headingNames: array[1..32, string] = [
"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"]
maxNameLength = headingNames.mapIt(it.len).max
degreesPerHeading = 360 / 32
func toCompassIndex(degree: float): 1..32 =
var degree = (degree + degreesPerHeading / 2).floorMod 360
int(degree / degreesPerHeading) + 1
func toCompassHeading(degree: float): string = headingNames[degree.toCompassIndex]
for i in 0..32:
let j = i mod 32
var d = float(i) * 11.25
if i mod 3 == 1: d += 5.62
if i mod 3 == 2: d -= 5.62
printlnfmt "{:2} {:18} {:>6.2f}", j + 1, names[j], d
let
heading = float(i) * 11.25 + (case i mod 3
of 1: 5.62
of 2: -5.62
else: 0)
index = heading.toCompassIndex
compassHeading = heading.toCompassHeading.alignLeft(maxNameLength)
echo fmt"{index:>2} {compassHeading} {heading:6.2f}"

View file

@ -11,18 +11,16 @@ test_angles=( 0.00 16.87 16.88 33.75 50.62 50.63 67.50
236.25 253.12 253.13 270.00 286.87 286.88 303.75
320.62 320.63 337.50 354.37 354.38 )
# capitalize a string
function capitalize {
echo "$1" | sed 's/^./\U&/'
capitalize() {
printf '%s%s\n' "$(tr a-z A-Z <<<"${1:0:1}")" "${1:1}"
}
# convert compass point abbreviation to full text of label
function expand_point {
local label="$1"
local label=$1
set -- N north E east S south W west b " by "
while (( $# )); do
label="${label//$1/$2}"
label=${label//$1/$2}
shift 2
done
capitalize "$label"
@ -35,6 +33,7 @@ function amod {
# convert a compass angle from degrees into a box index (1..32)
function compass_point {
# use bc or dc depending on what's on the system
#amod $(dc <<<"$1 5.625 + 11.25 / 1 + p") 32
amod $(bc <<<"($1 + 5.625) / 11.25 + 1") 32
}