Repository navigation
Expand file tree
/
Copy pathTrueWind.html
More file actions
980 lines (864 loc) · 37.1 KB
/
Copy pathTrueWind.html
File metadata and controls
980 lines (864 loc) · 37.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
<!DOCTYPE html>
<html lang="en" data-theme="day">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>True Wind Calculator</title>
<style>
/* ==========================================================================
Palette. Day is the chart table: charted-shallow-water blue, chart paper,
engraving ink, and the magenta that Admiralty charts reserve for compass
roses and cautionary notes --- here reserved for the true wind, the one
figure that gets transcribed. Night is the darkened bridge under red
instrument lighting.
========================================================================== */
:root {
color-scheme: light;
--bg: #d7e3e7;
--panel: #f7fafb;
--panel-2: #eaf1f4;
--graticule: #e5eef1;
--line: #b9ccd3;
--line-soft: #d7e4e9;
--ink: #0c2831;
/* Dark enough to clear 4.5:1 on the segmented-control tray, not just on the
lighter panel behind it. */
--muted: #556e78;
/* Muted text sitting directly on the page ground, which is darker than the
panels --- --muted only reaches 4.12:1 there. */
--muted-on-bg: #47606a;
--field: #ffffff;
--field-line: #aec4cd;
--accent: #a81e67;
--err: #b3261e;
--rose: #8ba9b4;
--rose-fine: #bacdd5;
--rose-ink: #4e6a75;
--hull: #e4edf0;
--hull-line: #4e6a75;
--c-ship: #8a6a22;
--c-app: #1f5f70;
--c-true: #a81e67;
--port: #c8102e;
--stbd: #00843d;
--on-signal: #ffffff;
--sel-bg: var(--ink);
--sel-ink: var(--panel);
/* The repeater reads the same in daylight and dark, like the real thing. */
--ro-bg: #08202a;
--ro-bg-2: #0b2a36;
--ro-line: #17414f;
--ro-ink: #f3eee2;
--ro-dim: #7e9aa4;
--ro-acc: #ff6fb0;
--focus: var(--accent);
}
html[data-theme="night"] {
color-scheme: dark;
--bg: #060809;
--panel: #0f1214;
--panel-2: #15191b;
--graticule: #14191b;
--line: #2e1d18;
--line-soft: #211511;
--ink: #ff9c82;
/* Lifted from #a55b47: that only reached 3.75:1 on the night panel, and
these are the smallest labels on the darkest ground. */
--muted: #bd7259;
--muted-on-bg: #bd7259;
--field: #131718;
--field-line: #3b241d;
--accent: #ff4433;
--err: #ff5c47;
--rose: #6b3a2e;
--rose-fine: #45241d;
--rose-ink: #bd7259;
--hull: #191d1f;
--hull-line: #8a4a3a;
--c-ship: #b87a3c;
--c-app: #c2603a;
--c-true: #ff4433;
--port: #a32b20;
--stbd: #3d6630;
--on-signal: #ffd9d0;
/* A dark pill with bright text, not a bright pill: on a darkened bridge the
selected control must not be the brightest thing on the screen. */
--sel-bg: #4a1a12;
--sel-ink: #ff9c82;
--ro-bg: #0a0304;
--ro-bg-2: #120706;
--ro-line: #3a1712;
--ro-ink: #ff9c82;
/* Was #8a4636 --- only 2.93:1 against the repeater ground. */
--ro-dim: #bd7259;
--ro-acc: #ff4433;
--focus: #ff8a72;
}
/* --------------------------------------------------------------------------
Type. Bahnschrift is Windows' DIN-derived variable grotesque --- the face
family of technical and transport signage, and present on the machines this
ships to. No webfont: the file has to stay offline and small.
-------------------------------------------------------------------------- */
:root {
--font-display: "Bahnschrift", "DIN Alternate", "Segoe UI Semibold", "Segoe UI", system-ui, sans-serif;
--font-body: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
--font-data: "Consolas", ui-monospace, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--bg);
color: var(--ink);
font: 15px/1.55 var(--font-body);
-webkit-font-smoothing: antialiased;
}
.app { max-width: 1200px; margin: 0 auto; padding: 22px 20px 48px; }
/* ---- masthead ---- */
.masthead {
display: flex; flex-wrap: wrap; gap: 16px;
align-items: center; justify-content: space-between;
padding-bottom: 16px; margin-bottom: 16px;
border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; }
.mark { width: 40px; height: 40px; flex: none; color: var(--rose-ink); }
h1 {
margin: 0;
font-family: var(--font-display);
font-variation-settings: 'wght' 600, 'wdth' 87;
font-weight: 600;
font-size: 1.32rem; line-height: 1.1;
letter-spacing: .1em; text-transform: uppercase;
}
.subtitle { color: var(--muted-on-bg); font-size: .82rem; margin: 3px 0 0; }
.view-toggles { display: flex; gap: 10px; flex-wrap: wrap; }
/* ---- the repeater ---- */
.readout {
background: linear-gradient(180deg, var(--ro-bg-2), var(--ro-bg));
border: 1px solid var(--ro-line);
border-radius: 5px;
padding: 15px 20px 16px;
margin-bottom: 16px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
}
.ro-title {
font: 600 .66rem/1 var(--font-body);
letter-spacing: .2em; text-transform: uppercase;
color: var(--ro-dim); margin-bottom: 14px;
}
.ro-figures { display: grid; grid-template-columns: repeat(3, 1fr); }
.ro { padding: 0 22px; border-left: 1px solid var(--ro-line); min-width: 0; }
.ro:first-child { padding-left: 0; border-left: 0; }
.ro-cap {
display: block; margin-bottom: 7px;
font: 600 .62rem/1 var(--font-body);
letter-spacing: .16em; text-transform: uppercase; color: var(--ro-dim);
}
.ro-val {
font-family: var(--font-display);
font-variation-settings: 'wght' 700, 'wdth' 85;
font-weight: 700;
font-size: clamp(2.1rem, 5vw, 3rem); line-height: 1;
color: var(--ro-ink);
font-variant-numeric: tabular-nums;
}
.ro-unit { font-size: .38em; color: var(--ro-dim); margin-left: .18em; letter-spacing: .04em; }
.ro-note {
display: block; margin-top: 8px;
font: 600 .8rem/1.25 var(--font-body); letter-spacing: .07em;
color: var(--ro-acc);
}
.ro-sub {
margin: 15px 0 0; padding-top: 13px;
border-top: 1px solid var(--ro-line);
font-size: .8rem; color: var(--ro-dim);
}
.calm .ro-dir .ro-val { font-size: clamp(1.4rem, 3.2vw, 1.9rem); }
/* The compass point is a figure read at a glance, not a caption. */
#rPoint {
margin-top: 5px;
font-family: var(--font-display);
font-variation-settings: 'wght' 700, 'wdth' 88;
font-weight: 700;
font-size: clamp(1.3rem, 2.6vw, 1.75rem);
line-height: 1.1;
letter-spacing: .09em;
}
/* Except when calm, where it carries a sentence rather than a symbol. */
.calm #rPoint {
margin-top: 8px;
font: 600 .8rem/1.25 var(--font-body);
letter-spacing: .07em;
}
@media (max-width: 700px) {
.ro-figures { grid-template-columns: 1fr; gap: 15px; }
.ro { padding: 15px 0 0; border-left: 0; border-top: 1px solid var(--ro-line); }
.ro:first-child { padding-top: 0; border-top: 0; }
}
/* ---- console ---- */
.console { display: grid; grid-template-columns: minmax(290px, 358px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .console { grid-template-columns: 1fr; } }
.panel {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 5px;
padding: 18px 18px 20px;
}
.panel h2 {
display: flex; align-items: center; gap: 9px;
margin: 0 0 17px; padding-bottom: 11px;
border-bottom: 1px solid var(--line-soft);
font: 600 .68rem/1 var(--font-body);
letter-spacing: .2em; text-transform: uppercase; color: var(--muted);
}
.panel h2::before {
content: ""; width: 3px; height: 12px; flex: none;
background: var(--accent); border-radius: 1px;
}
/* Chart paper: a faint graticule, the way a working chart is ruled. */
.chart {
background-color: var(--panel);
background-image:
repeating-linear-gradient(0deg, var(--graticule) 0 1px, transparent 1px 44px),
repeating-linear-gradient(90deg, var(--graticule) 0 1px, transparent 1px 44px);
}
/* ---- inputs ---- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label {
display: block; margin-bottom: 6px;
font: 600 .74rem/1.2 var(--font-body);
letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
}
.input-wrap { position: relative; display: block; }
.field input[type="text"] {
width: 100%; padding: 11px 52px 11px 13px;
font: 600 1.2rem/1.3 var(--font-data);
font-variant-numeric: tabular-nums;
color: var(--ink); background: var(--field);
border: 1px solid var(--field-line); border-radius: 4px;
transition: border-color .12s ease;
}
.field input[type="text"]:hover { border-color: var(--rose-ink); }
.unit-tag {
position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
font: 600 .72rem/1 var(--font-body); letter-spacing: .1em;
color: var(--muted); pointer-events: none;
}
.hint { font-size: .74rem; color: var(--muted); margin-top: 5px; }
.err { font-size: .78rem; color: var(--err); margin-top: 5px; font-weight: 600; }
.field.bad input[type="text"] { border-color: var(--err); }
:where(input, button):focus-visible {
outline: 2px solid var(--focus); outline-offset: 2px;
}
.seg {
display: flex; gap: 2px; padding: 2px;
background: var(--panel-2);
border: 1px solid var(--field-line); border-radius: 4px;
}
.seg button {
flex: 1; min-width: 0; padding: 10px 8px;
font: 600 .78rem/1 var(--font-body); letter-spacing: .05em;
background: transparent; color: var(--muted);
border: 0; border-radius: 3px; cursor: pointer;
transition: background .12s ease, color .12s ease;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--sel-bg); color: var(--sel-ink); }
.seg.compact button { padding: 8px 11px; font-size: .72rem; letter-spacing: .08em; }
.rg-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; }
.side button[aria-pressed="true"].side-red { background: var(--port); color: var(--on-signal); }
.side button[aria-pressed="true"].side-green { background: var(--stbd); color: var(--on-signal); }
/* ---- diagram ---- */
svg#diagram { display: block; width: 100%; height: auto; }
svg text { text-anchor: middle; dominant-baseline: central; }
.rose-ring { fill: none; stroke: var(--rose); stroke-width: 1.4; }
.rose-inner { fill: none; stroke: var(--rose-fine); stroke-width: 1; }
.tick { stroke: var(--rose-fine); stroke-width: .9; }
.tick-med { stroke: var(--rose); stroke-width: 1; }
.tick-major { stroke: var(--rose); stroke-width: 1.8; }
.rose-label { fill: var(--rose-ink); font: 500 12px var(--font-body); letter-spacing: .04em; }
.rose-card { fill: var(--ink); font-family: var(--font-display); font-variation-settings: 'wght' 700, 'wdth' 90; font-weight: 700; font-size: 17px; letter-spacing: .06em; }
.north-star { fill: var(--accent); }
.hull { fill: var(--hull); stroke: var(--hull-line); stroke-width: 1.9; stroke-linejoin: round; }
.deckline { fill: none; stroke: var(--hull-line); stroke-width: .9; opacity: .55; }
.centerline { stroke: var(--hull-line); stroke-width: .9; stroke-dasharray: 6 5; opacity: .6; }
.fitting { fill: none; stroke: var(--hull-line); stroke-width: 1.3; }
.v-ship { stroke: var(--c-ship); stroke-width: 3; stroke-linecap: butt; }
.v-app { stroke: var(--c-app); stroke-width: 3.4; stroke-dasharray: 10 5; }
.v-true { stroke: var(--c-true); stroke-width: 5.4; }
.constr { stroke: var(--rose); stroke-width: 1.1; stroke-dasharray: 2 5; opacity: .9; }
.vlabel {
font-family: var(--font-display);
font-variation-settings: 'wght' 700, 'wdth' 88;
font-weight: 700; font-size: 14px; letter-spacing: .06em;
paint-order: stroke; stroke: var(--panel); stroke-width: 4.5px; stroke-linejoin: round;
}
.l-true { fill: var(--c-true); }
.rim-mark { fill: var(--c-true); }
.scale-bar { stroke: var(--rose-ink); stroke-width: 1.6; }
.scale-txt { fill: var(--rose-ink); font: 500 12px var(--font-body); text-anchor: start; letter-spacing: .05em; }
/* ---- key ---- */
.key { list-style: none; display: grid; gap: 9px; margin: 16px 0 0; padding: 14px 0 0; border-top: 1px solid var(--line-soft); font-size: .82rem; }
.key li { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 11px; }
.key .k-name { color: var(--muted); }
.key .k-val {
font: 600 .86rem/1.3 var(--font-data);
font-variant-numeric: tabular-nums; text-align: right;
}
.k-ship { color: var(--c-ship); }
.k-app { color: var(--c-app); }
.k-true { color: var(--c-true); }
.sw { width: 28px; height: 0; display: inline-block; }
.sw-ship { border-top: 3px solid var(--c-ship); }
.sw-app { border-top: 3.4px dashed var(--c-app); }
.sw-true { border-top: 5px solid var(--c-true); }
.note { font-size: .78rem; line-height: 1.6; color: var(--muted); margin: 14px 0 0; max-width: 68ch; }
.colophon {
margin-top: 18px; padding-top: 14px;
border-top: 1px solid var(--line);
font-size: .78rem; line-height: 1.6; color: var(--muted-on-bg);
display: flex; flex-wrap: wrap; gap: 6px 28px;
align-items: baseline; justify-content: space-between;
}
.colophon p { margin: 0; }
.colophon .disclaimer { max-width: 72ch; }
.colophon strong { color: var(--ink); }
/* The file gets copied around on its own, so it has to say which build it is. */
.colophon .version { font-family: var(--font-data); letter-spacing: .04em; white-space: nowrap; }
/* Touch: the segmented controls are the only targets small enough to matter,
and this thing gets used on a phone as readily as on the bridge PC. */
@media (pointer: coarse), (max-width: 900px) {
.seg button { padding: 15px 8px; }
.seg.compact button { padding: 12px 13px; }
}
@media (prefers-reduced-motion: reduce) {
* { transition: none !important; animation: none !important; }
}
</style>
</head>
<body>
<div class="app">
<header class="masthead">
<div class="brand">
<svg class="mark" viewBox="0 0 40 40" aria-hidden="true" focusable="false">
<circle cx="20" cy="20" r="18.2" fill="none" stroke="currentColor" stroke-width="1.1" opacity=".5"/>
<circle cx="20" cy="20" r="12.6" fill="none" stroke="currentColor" stroke-width=".8" opacity=".3"/>
<path d="M20 1.4 L23.1 17 L20 20 L16.9 17 Z" fill="var(--accent)"/>
<path d="M20 38.6 L16.9 23 L20 20 L23.1 23 Z" fill="currentColor" opacity=".6"/>
<path d="M1.4 20 L17 16.9 L20 20 L17 23.1 Z" fill="currentColor" opacity=".38"/>
<path d="M38.6 20 L23 23.1 L20 20 L23 16.9 Z" fill="currentColor" opacity=".38"/>
</svg>
<div>
<h1>True Wind</h1>
<p class="subtitle">Relative wind resolved into true wind and force</p>
</div>
</div>
<div class="view-toggles">
<div class="seg compact" id="orientationSeg">
<button type="button" data-val="north" aria-pressed="true">North-up</button>
<button type="button" data-val="head" aria-pressed="false">Head-up</button>
</div>
<div class="seg compact" id="themeSeg">
<button type="button" data-val="day" aria-pressed="true">Day</button>
<button type="button" data-val="night" aria-pressed="false">Night</button>
</div>
</div>
</header>
<section class="readout" id="resultPanel">
<div class="ro-title">True wind</div>
<div aria-live="polite">
<div class="ro-figures">
<div class="ro ro-dir">
<span class="ro-cap">Direction</span>
<span class="ro-val"><span id="rDir">—</span><span class="ro-unit" id="rDegSym">°T</span></span>
<span class="ro-note" id="rPoint"></span>
</div>
<div class="ro">
<span class="ro-cap">Speed</span>
<span class="ro-val"><span id="rSpeed">—</span><span class="ro-unit">kn</span></span>
</div>
<div class="ro">
<span class="ro-cap">Beaufort</span>
<span class="ro-val"><span id="rForce">—</span></span>
<span class="ro-note" id="rForceTerm"></span>
</div>
</div>
<p class="ro-sub" id="rSub">—</p>
</div>
</section>
<div class="console">
<section class="panel">
<h2>Observations</h2>
<div class="field" id="f-course">
<label for="course">Ship's course</label>
<span class="input-wrap">
<input type="text" id="course" inputmode="decimal" autocomplete="off" value="000">
<span class="unit-tag">°T</span>
</span>
<div class="err" id="e-course"></div>
</div>
<div class="field" id="f-speed">
<label for="speed">Ship's speed</label>
<span class="input-wrap">
<input type="text" id="speed" inputmode="decimal" autocomplete="off" value="12">
<span class="unit-tag">kn</span>
</span>
<div class="hint">As logged — speed over ground or through the water.</div>
<div class="err" id="e-speed"></div>
</div>
<div class="field">
<label>Relative wind direction</label>
<div class="seg" id="modeSeg">
<button type="button" data-val="bearing" aria-pressed="true">Relative bearing</button>
<button type="button" data-val="rg" aria-pressed="false">Red / Green</button>
</div>
</div>
<div class="field" id="f-bearing">
<label for="relBearing">Bearing from the bow</label>
<span class="input-wrap">
<input type="text" id="relBearing" inputmode="decimal" autocomplete="off" value="045">
<span class="unit-tag">°</span>
</span>
<div class="hint">000 ahead · 090 starboard beam · 180 astern · 270 port beam.</div>
<div class="err" id="e-relBearing"></div>
</div>
<div class="field" id="f-rg" hidden>
<label for="rgDeg">Side and angle</label>
<div class="rg-row">
<div class="seg side" id="sideSeg">
<button type="button" class="side-red" data-val="red" aria-pressed="false">Red</button>
<button type="button" class="side-green" data-val="green" aria-pressed="true">Green</button>
</div>
<span class="input-wrap">
<input type="text" id="rgDeg" inputmode="decimal" autocomplete="off" value="045">
<span class="unit-tag">°</span>
</span>
</div>
<div class="hint">Red = port side · Green = starboard side · 0 to 180°.</div>
<div class="err" id="e-rgDeg"></div>
</div>
<div class="field" id="f-appSpeed">
<label for="appSpeed">Relative wind speed</label>
<span class="input-wrap">
<input type="text" id="appSpeed" inputmode="decimal" autocomplete="off" value="20">
<span class="unit-tag">kn</span>
</span>
<div class="err" id="e-appSpeed"></div>
</div>
</section>
<section class="panel chart">
<h2>Wind diagram</h2>
<svg id="diagram" viewBox="-80 -15 760 630" role="img" aria-labelledby="diagTitle"><title id="diagTitle">Wind vector diagram</title></svg>
<ul class="key">
<li><i class="sw sw-app"></i><span class="k-name">Apparent wind (observed)</span><span class="k-val k-app" id="kApp">—</span></li>
<li><i class="sw sw-ship"></i><span class="k-name">Ship's motion</span><span class="k-val k-ship" id="kShip">—</span></li>
<li><i class="sw sw-true"></i><span class="k-name">True wind (result)</span><span class="k-val k-true" id="kTrue">—</span></li>
</ul>
<p class="note">Wind arrows point the way the air travels; labels give the direction the wind blows <strong>from</strong>, as recorded in the log. The true wind is the diagonal of the parallelogram formed by the apparent wind and the ship's motion.</p>
</section>
</div>
<footer class="colophon">
<p class="disclaimer"><strong>Portfolio demonstration.</strong> Built to show the
engineering. It is not certified or approved for operational navigation, and must not be
used as the source for an official record.</p>
<p class="version">Version 1.0.0</p>
</footer>
</div>
<script id="wind-math">
/* Pure wind-triangle mathematics. No DOM access in this block --- tests.html
pulls this exact script out of the shipped file and runs against it. */
var WindMath = (function () {
'use strict';
var DEG = Math.PI / 180;
/* Wrap any angle into [0, 360). */
function normalizeAngle(deg) {
var a = deg % 360;
return a < 0 ? a + 360 : a;
}
/* "Green 45" is 45 deg on the starboard side, i.e. 45 deg clockwise from the
bow. "Red 45" is 45 deg to port, i.e. 315 deg clockwise from the bow. */
function redGreenToRelative(side, deg) {
return normalizeAngle(side === 'red' ? -deg : deg);
}
var POINTS = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'];
function compassPoint(deg) {
return POINTS[Math.round(normalizeAngle(deg) / 22.5) % 16];
}
/* WMO Beaufort scale. Upper bound of each force in whole knots; anything
above the last entry is force 12. The table is defined in whole knots, so
the observed speed is rounded before the lookup. */
var BEAUFORT_MAX = [0, 3, 6, 10, 16, 21, 27, 33, 40, 47, 55, 63];
var BEAUFORT_TERM = ['Calm', 'Light air', 'Light breeze', 'Gentle breeze',
'Moderate breeze', 'Fresh breeze', 'Strong breeze', 'Near gale', 'Gale',
'Strong gale', 'Storm', 'Violent storm', 'Hurricane'];
function beaufort(knots) {
var kn = Math.round(knots);
for (var f = 0; f < BEAUFORT_MAX.length; f++) {
if (kn <= BEAUFORT_MAX[f]) return { force: f, term: BEAUFORT_TERM[f] };
}
return { force: 12, term: BEAUFORT_TERM[12] };
}
/* true wind velocity = apparent wind velocity + ship velocity, where each
vector points the way the air or the ship is travelling. Components are
x = east, y = north. */
function solveTrueWind(input) {
var course = normalizeAngle(input.courseDeg);
var shipSpeed = input.shipSpeedKn;
var apparentSpeed = input.apparentSpeedKn;
/* The anemometer bearing is measured from the fore-and-aft line, so the
apparent wind's compass bearing is the course plus the relative bearing. */
var apparentFrom = normalizeAngle(course + input.relativeBearingDeg);
var apparentToward = apparentFrom + 180;
var ax = apparentSpeed * Math.sin(apparentToward * DEG);
var ay = apparentSpeed * Math.cos(apparentToward * DEG);
var sx = shipSpeed * Math.sin(course * DEG);
var sy = shipSpeed * Math.cos(course * DEG);
var tx = ax + sx;
var ty = ay + sy;
var trueSpeed = Math.hypot(tx, ty);
/* Below the display resolution the direction is meaningless: the ship's
motion has exactly cancelled the wind. Reporting a bearing here would be
inventing one. */
var calm = trueSpeed < 0.05;
return {
courseDeg: course,
shipSpeedKn: shipSpeed,
apparentFromDeg: apparentFrom,
apparentSpeedKn: apparentSpeed,
trueFromDeg: calm ? null : normalizeAngle(Math.atan2(tx, ty) / DEG + 180),
trueSpeedKn: trueSpeed,
calm: calm
};
}
return {
normalizeAngle: normalizeAngle,
redGreenToRelative: redGreenToRelative,
compassPoint: compassPoint,
beaufort: beaufort,
solveTrueWind: solveTrueWind
};
})();
</script>
<script id="app">
(function () {
'use strict';
var DEG = Math.PI / 180;
var CX = 300, CY = 300;
var R = 234; /* compass rose radius */
var VMAX = 150; /* longest vector, in pixels */
var RIM_LABEL_R = 268; /* where the rim label sits when nothing pushes it out */
var state = { mode: 'bearing', side: 'green', orientation: 'north', theme: 'day' };
/* ---------------- helpers ---------------- */
function $(id) { return document.getElementById(id); }
function pad3(deg) {
var n = Math.round(deg) % 360;
return (n < 10 ? '00' : n < 100 ? '0' : '') + n;
}
/* Screen coordinates of a point at the given bearing and pixel distance. */
function pt(bearing, dist) {
var r = bearing * DEG;
return [CX + dist * Math.sin(r), CY - dist * Math.cos(r)];
}
function store(key, val) {
try { localStorage.setItem(key, val); } catch (e) { /* policy may block it */ }
}
function recall(key) {
try { return localStorage.getItem(key); } catch (e) { return null; }
}
/* ---------------- input reading ---------------- */
/* Number() is far more permissive than a deck log warrants --- it reads
"0x1F" as 31 and "1e3" as 1000. Only plain decimals belong in these fields. */
var DECIMAL = /^[+-]?(\d+(\.\d*)?|\.\d+)$/;
function readField(id, opts) {
var raw = $(id).value.trim().replace(',', '.');
var err = null, v = NaN;
if (raw === '') {
err = 'Required';
} else if (!DECIMAL.test(raw)) {
err = 'Numbers only';
} else {
/* A long enough digit string still overflows to Infinity. */
v = Number(raw);
if (!isFinite(v)) err = 'Numbers only';
else if (opts.min !== undefined && v < opts.min) err = 'Cannot be less than ' + opts.min;
else if (opts.max !== undefined && v > opts.max) err = 'Cannot be more than ' + opts.max;
}
$('e-' + id).textContent = err || '';
$('f-' + (opts.field || id)).classList.toggle('bad', !!err);
return err ? null : v;
}
function readInputs() {
var course = readField('course', {});
var speed = readField('speed', { min: 0 });
var appSpeed = readField('appSpeed', { min: 0 });
var relative = null;
if (state.mode === 'bearing') {
var b = readField('relBearing', { field: 'bearing' });
if (b !== null) relative = WindMath.normalizeAngle(b);
} else {
var d = readField('rgDeg', { field: 'rg', min: 0, max: 180 });
if (d !== null) relative = WindMath.redGreenToRelative(state.side, d);
}
if (course === null || speed === null || appSpeed === null || relative === null) {
return { ok: false, courseDeg: course };
}
return {
ok: true,
courseDeg: course,
shipSpeedKn: speed,
apparentSpeedKn: appSpeed,
relativeBearingDeg: relative
};
}
/* ---------------- result panel ---------------- */
function showResult(s) {
var panel = $('resultPanel');
if (!s) {
panel.classList.remove('calm');
$('rDir').innerHTML = '—';
$('rDegSym').textContent = '°T';
$('rPoint').textContent = '';
$('rSpeed').innerHTML = '—';
$('rForce').innerHTML = '—';
$('rForceTerm').textContent = '';
$('rSub').textContent = 'Complete the observations to resolve the true wind.';
$('kApp').innerHTML = '—';
$('kShip').innerHTML = '—';
$('kTrue').innerHTML = '—';
return;
}
/* Derive the force from the speed as displayed, not from the raw value.
Otherwise two observations both reading "3.5 kn" can show different
forces, because 3.45 rounds down to 3 kn and 3.50 rounds up to 4. */
var shownSpeed = Math.round(s.trueSpeedKn * 10) / 10;
var bf = WindMath.beaufort(shownSpeed);
panel.classList.toggle('calm', s.calm);
if (s.calm) {
$('rDir').textContent = 'CALM';
$('rDegSym').textContent = '';
$('rPoint').textContent = 'direction variable';
} else {
$('rDir').textContent = pad3(s.trueFromDeg);
$('rDegSym').textContent = '°T';
$('rPoint').textContent = WindMath.compassPoint(s.trueFromDeg);
}
$('rSpeed').textContent = shownSpeed.toFixed(1);
$('rForce').textContent = String(bf.force);
$('rForceTerm').textContent = bf.term;
$('rSub').textContent = 'Apparent wind from ' + pad3(s.apparentFromDeg) + '°T at '
+ s.apparentSpeedKn.toFixed(1) + ' kn.';
/* Values for the diagram key, so each arrow can be read without pinning
text to it. */
$('kApp').textContent = 'from ' + pad3(s.apparentFromDeg) + '°T · ' + s.apparentSpeedKn.toFixed(1) + ' kn';
$('kShip').textContent = pad3(s.courseDeg) + '°T · ' + s.shipSpeedKn.toFixed(1) + ' kn';
$('kTrue').textContent = s.calm
? 'calm'
: 'from ' + pad3(s.trueFromDeg) + '°T · ' + s.trueSpeedKn.toFixed(1) + ' kn';
}
/* ---------------- diagram ---------------- */
function defs() {
return '<defs>'
+ marker('ah-ship', 'var(--c-ship)')
+ marker('ah-app', 'var(--c-app)')
+ marker('ah-true', 'var(--c-true)')
+ '</defs>';
}
function marker(id, fill) {
return '<marker id="' + id + '" viewBox="0 0 10 10" refX="9.5" refY="5"'
+ ' markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto">'
+ '<path d="M0,0 L10,5 L0,10 Z" fill="' + fill + '"/></marker>';
}
function rose(rot) {
var out = ['<circle class="rose-ring" cx="' + CX + '" cy="' + CY + '" r="' + R + '"/>',
'<circle class="rose-inner" cx="' + CX + '" cy="' + CY + '" r="' + (R - 24) + '"/>'];
var d, a, b, p, card, cls, len;
/* Graduated the way a chart rose is engraved: a stroke every 5 degrees,
longer at 10, longest at 30. */
for (d = 0; d < 360; d += 5) {
cls = d % 30 === 0 ? 'tick-major' : (d % 10 === 0 ? 'tick-med' : 'tick');
len = d % 30 === 0 ? 24 : (d % 10 === 0 ? 13 : 7);
a = pt(d + rot, R);
b = pt(d + rot, R - len);
out.push('<line class="' + cls + '" x1="' + a[0].toFixed(1) + '" y1="' + a[1].toFixed(1)
+ '" x2="' + b[0].toFixed(1) + '" y2="' + b[1].toFixed(1) + '"/>');
}
var cards = { 0: 'N', 90: 'E', 180: 'S', 270: 'W' };
for (d = 0; d < 360; d += 30) {
card = cards[d];
p = pt(d + rot, R - 41);
out.push('<text class="' + (card ? 'rose-card' : 'rose-label') + '" x="' + p[0].toFixed(1)
+ '" y="' + p[1].toFixed(1) + '">' + (card || pad3(d)) + '</text>');
}
/* North point, set outside the ring --- the one fixed reference on the
rose, and the thing that moves when the view is switched to head-up. */
var n = pt(rot, R + 3);
out.push('<path class="north-star" transform="translate(' + n[0].toFixed(1) + ','
+ n[1].toFixed(1) + ') rotate(' + rot.toFixed(2) + ')" d="M0,-14 L5.5,0 L0,-3.5 L-5.5,0 Z"/>');
return out.join('');
}
function ship(bearing) {
return '<g transform="translate(' + CX + ',' + CY + ') rotate(' + bearing.toFixed(2) + ')">'
/* Hull in plan: raked stem, parallel body, transom stern. */
+ '<path class="hull" d="M0,-74 C13,-56 19,-34 19,-14 L19,44 L15,56 L-15,56 L-19,44 L-19,-14'
+ ' C-19,-34 -13,-56 0,-74 Z"/>'
+ '<path class="deckline" d="M0,-65 C10,-50 14,-33 14,-14 L14,42 L11,49 L-11,49 L-14,42 L-14,-14'
+ ' C-14,-33 -10,-50 0,-65 Z"/>'
+ '<line class="centerline" x1="0" y1="-58" x2="0" y2="49"/>'
/* Cargo hatches forward, superstructure with bridge wings and funnel aft. */
+ '<rect class="fitting" x="-9" y="-41" width="18" height="13" rx="1"/>'
+ '<rect class="fitting" x="-9" y="-24" width="18" height="13" rx="1"/>'
+ '<rect class="fitting" x="-9" y="-7" width="18" height="13" rx="1"/>'
+ '<rect class="fitting" x="-13" y="15" width="26" height="19" rx="1"/>'
+ '<line class="fitting" x1="-20" y1="18" x2="20" y2="18"/>'
+ '<rect class="fitting" x="-4.5" y="38" width="9" height="11" rx="1"/>'
+ '</g>';
}
function line(cls, from, to, markerId) {
return '<line class="' + cls + '" x1="' + from[0].toFixed(1) + '" y1="' + from[1].toFixed(1)
+ '" x2="' + to[0].toFixed(1) + '" y2="' + to[1].toFixed(1) + '"'
+ (markerId ? ' marker-end="url(#' + markerId + ')"' : '') + '/>';
}
function text(cls, p, str) {
return '<text class="' + cls + '" x="' + p[0].toFixed(1) + '" y="' + p[1].toFixed(1) + '">'
+ str + '</text>';
}
/* The rim label is an upright box, so towards east and west its width reaches
back across the graduation and sits on top of the rose. Measure what the
font actually produced --- it differs between machines --- then walk the
label out along its own bearing until the whole box clears the ring. */
function placeRimLabel(svg, bearing) {
var el = svg.querySelector('.rim-label');
if (!el) return;
var box = el.getBBox();
var halfW = box.width / 2, halfH = box.height / 2;
var u = Math.sin(bearing * DEG), v = -Math.cos(bearing * DEG);
var clear = R + 10;
var d = RIM_LABEL_R;
/* Nearest point of the box to the rose centre, per axis. */
for (var i = 0; i < 400; i++) {
var nx = Math.max(0, Math.abs(d * u) - halfW);
var ny = Math.max(0, Math.abs(d * v) - halfH);
if (nx * nx + ny * ny >= clear * clear) break;
d += 1;
}
el.setAttribute('x', (CX + d * u).toFixed(1));
el.setAttribute('y', (CY + d * v).toFixed(1));
}
/* Longest "nice" round number that fits comfortably inside the drawn vectors. */
function scaleStep(maxKn) {
var steps = [1, 2, 5, 10, 20, 25, 50, 100], step = steps[0];
for (var i = 0; i < steps.length; i++) if (steps[i] <= maxKn / 2) step = steps[i];
return step;
}
function renderDiagram(s, courseFallback) {
var svg = $('diagram');
var course = s ? s.courseDeg : courseFallback;
var rot = state.orientation === 'head' ? -course : 0;
var out = [defs(), rose(rot), ship(course + rot)];
if (s) {
var maxKn = Math.max(s.apparentSpeedKn, s.shipSpeedKn, s.trueSpeedKn, 5);
var px = VMAX / maxKn;
var O = [CX, CY];
var A = pt(s.apparentFromDeg + 180 + rot, s.apparentSpeedKn * px);
var S = pt(s.courseDeg + rot, s.shipSpeedKn * px);
var T = s.calm ? [CX, CY] : pt(s.trueFromDeg + 180 + rot, s.trueSpeedKn * px);
/* Closing sides of the parallelogram, so the addition is visible. */
out.push(line('constr', A, T));
out.push(line('constr', S, T));
/* The three magnitudes are read off the key beneath the diagram rather
than from labels pinned to the arrows. Pinned labels collide whenever
two vectors point the same way --- running before the wind puts the
ship and apparent arrows exactly on top of each other. */
if (s.shipSpeedKn > 0.05) out.push(line('v-ship', O, S, 'ah-ship'));
if (s.apparentSpeedKn > 0.05) out.push(line('v-app', O, A, 'ah-app'));
if (!s.calm) {
out.push(line('v-true', O, T, 'ah-true'));
/* Marker on the rose rim showing where the true wind comes from ---
this is the figure that gets written into the log. */
var rim = pt(s.trueFromDeg + rot, R - 2);
out.push('<g class="rim-mark" transform="translate(' + rim[0].toFixed(1) + ','
+ rim[1].toFixed(1) + ') rotate(' + (s.trueFromDeg + rot + 180).toFixed(2) + ')">'
+ '<path d="M0,-13 L8,5 L-8,5 Z"/></g>');
/* Placed properly by placeRimLabel once the font has been measured. */
out.push(text('vlabel l-true rim-label', pt(s.trueFromDeg + rot, RIM_LABEL_R),
'FROM ' + pad3(s.trueFromDeg) + '°T'));
}
/* Scale legend. */
var step = scaleStep(maxKn);
var x0 = -66, x1 = x0 + step * px;
out.push('<line class="scale-bar" x1="' + x0 + '" y1="576" x2="' + x1.toFixed(1) + '" y2="576"/>');
out.push('<line class="scale-bar" x1="' + x0 + '" y1="571" x2="' + x0 + '" y2="581"/>');
out.push('<line class="scale-bar" x1="' + x1.toFixed(1) + '" y1="571" x2="' + x1.toFixed(1) + '" y2="581"/>');
out.push('<text class="scale-txt" x="' + (x1 + 8).toFixed(1) + '" y="576">' + step + ' kn</text>');
}
svg.innerHTML = '<title id="diagTitle">Wind vector diagram</title>' + out.join('');
if (s && !s.calm) placeRimLabel(svg, s.trueFromDeg + rot);
}
/* ---------------- wiring ---------------- */
function recalc() {
var input = readInputs();
if (!input.ok) {
showResult(null);
renderDiagram(null, input.courseDeg === null ? 0 : input.courseDeg);
return;
}
var solved = WindMath.solveTrueWind(input);
showResult(solved);
renderDiagram(solved);
}
function segment(id, onPick) {
var seg = $(id);
seg.addEventListener('click', function (ev) {
var btn = ev.target.closest('button');
if (!btn) return;
Array.prototype.forEach.call(seg.querySelectorAll('button'), function (b) {
b.setAttribute('aria-pressed', String(b === btn));
});
onPick(btn.dataset.val);
});
}
function preselect(id, val) {
Array.prototype.forEach.call($(id).querySelectorAll('button'), function (b) {
b.setAttribute('aria-pressed', String(b.dataset.val === val));
});
}
segment('modeSeg', function (val) {
state.mode = val;
$('f-bearing').hidden = val !== 'bearing';
$('f-rg').hidden = val !== 'rg';
recalc();
});
segment('sideSeg', function (val) { state.side = val; recalc(); });
segment('orientationSeg', function (val) {
state.orientation = val; store('tw-orientation', val); recalc();
});
segment('themeSeg', function (val) {
state.theme = val;
document.documentElement.setAttribute('data-theme', val);
store('tw-theme', val);
});
['course', 'speed', 'relBearing', 'rgDeg', 'appSpeed'].forEach(function (id) {
$(id).addEventListener('input', recalc);
});
var savedTheme = recall('tw-theme');
if (savedTheme !== 'night' && savedTheme !== 'day') {
/* Nothing stored yet: follow the machine. A bridge PC set to dark should
not open in daylight white. */
savedTheme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
? 'night' : 'day';
}
state.theme = savedTheme;
document.documentElement.setAttribute('data-theme', savedTheme);
preselect('themeSeg', savedTheme);
var savedOrientation = recall('tw-orientation');
if (savedOrientation === 'head' || savedOrientation === 'north') {
state.orientation = savedOrientation;
preselect('orientationSeg', savedOrientation);
}
recalc();
})();
</script>
</body>
</html>