-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchronometer.html
313 lines (279 loc) · 8.97 KB
/
chronometer.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>UTILITY - CHRONOMETRY</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--
<link rel="stylesheet" href="/normalize.css" type="text/css">
<link rel="stylesheet" href="/style.css" type="text/css">
<link href="./blueprint.css" rel="stylesheet" />
<link href="./snis-blueprint.css" rel="stylesheet" />
-->
<link href="./snis-basic.css" rel="stylesheet" />
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/en/face/web-3-of-9-ascii" type="text/css"/>
<style>
#barcoded {
font-family: 'Web3Of9ASCIIRegular';
font-weight: normal;
font-style: normal;
font-size:1.25em;
transform: rotate(90deg) scale(1,.45);
position: relative;
float: right;
display: inline-block;
right: 1em;
top: 8em;
}
table.details{ margin-top:2em;}
a.buttonize {
margin-bottom: .5em;
min-width: 12em;
width: 12em;
display: block;
text-align: left;
margin-left: 1em;
}
#clockontainer {
color:green;
background-color:black;
margin: 0 auto;
width: 800px;
text-align: center;
border: green solid 1px;
}
#clockontainer p{
font-size:1.8em;
font-weight:bold;
}
#digitalClock, #digitalStopwatch { /* attempt to reduce distracting alignment flutter of non-monospace fonts */
font-variant-numeric: tabular-nums lining-nums;
font-feature-settings: 'tnum' 1;
text-align: left;
margin-left: 44%;
}
#digitalCountdown {
margin-left:15em;
}
</style>
</head>
<body>
<div id="main" bp="grid 6@md">
<div>
<div class="panel">
<h1 onClick="toggleFullScreen();">CHRONOMETRY</h1>
</div>
<div class="panel">
<p id="stardate">STARDATE: </p>
<p id="barcoded">--:--:--</p>
<div id="clockontainer">
<h1>MISSION TIME</h1>
<canvas id="analogClock" width="102" height="102">Clock</canvas>
<p id="digitalClock">--:--:--</p>
<p id="digitalStopwatch">--:--:--</p>
</div>
<button id="addTimer" >INIT COUNTDOWN</button> <!-- TODO: optional label? -->
<input id="countdownInterval" value="10" type="number"/>
<p id="digitalCountdown">--:--:--</p>
<!-- todo: beep alert if hit zero -->
<button id="addStopWatch">INIT TIMECOUNT</button> <!-- TODO: optional label? -->
</div>
<div class="panel">
<!-- perhaps this should be a partialpage/client-injection (ajax'd into dom), or SSI, "navigation.nonsense.html_fragment" file ...-->
<!-- BEGIN CHUNK -->
<table class="details">
<tr><th>STATION ID</th><th>RELATIVISTIC COMP.</th></tr>
<tr><td>01</td><td>0307</td></tr>
<tr><td>02</td><td>2600</td></tr>
</table>
<!-- END CHUNK -->
</div>
<div><a id="btn_main_menu" class="buttonize" href="menu.html">MAIN MENU</a></div>
</div>
</div>
</body>
<script>
function toggleFullScreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
}
function command(text) {
var data = { command: text };
//sanitize data?
console.info("Transmitting command: "+text);
//fetch('/SHIP/STATIONNAME/TARGETNOUN/VERB?parametername=value', {
fetch("/SHIP/NAVIGATION/" + text.toUpperCase().replace(" ","/"), {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
soundACK.play();
})
.catch((error) => {
console.error('Error:', error);
soundNACK.play();
});
}
//--UI Wire-up--//
var sinceTimeZero = 0;
var countdownSpan = 0;
var btn_addStopWatch = document.getElementById("addStopWatch");
btn_addStopWatch.addEventListener("click",(event)=>{
sinceTimeZero += 1;
});
var btn_addTimer = document.getElementById("addTimer");
btn_addTimer.addEventListener("click",(event)=>{
countdownSpan = document.getElementById("countdownInterval").value;
});
</script>
<script src="./howler.js"></script>
<script>//--Kickstart the UI--//
var soundACK = new Howl({ src: ['./sounds/tactinput_acknowledge.ogg', './sounds/tactinput_acknowledge.m4a', './sounds/tactinput_acknowledge.webm'] });
var soundNACK = new Howl({ src: ['./sounds/tactinput_neg_acknowledge.ogg', './sounds/tactinput_neg_acknowledge.m4a', './sounds/tactinput_neg_acknowledge.webm'] });
try {
toggleFullScreen();
} catch (error) {
console.warn("just warning, kinda expected this..." + error);
}
//TODO: define and call a function to list/iterate over all stardate entries and apply to template.
var stardate = new Date().toISOString().slice(0, 16).replace("T",".")
document.getElementById("stardate").innerText += " " + stardate;
//TODO: timer to update once per minute.
//TODO: wire up a localstorage commit on btn_record click
//possibly, this is "RSS" based internally. which would lead to other possibilities like a master daemonscreen/GM "rss feed subscription feed"
// or maybe in-game, occasional access of another ship's log remotely (salvage/explore derelicts, espionage/"hacking" of active ships
/**
* Setup and start an analog clock using a canvas
* @param canvas The canvas to use
* @param clockWidth The width of the clock (radius*2)
*/
function setupAnalogClock(canvas, clockWidth) {
var ctx = canvas.getContext("2d");
var centerX = canvas.width / 2 ;
var centerY = canvas.height / 2 ;
var digital = document.getElementById("digitalClock");
var stopwatch = document.getElementById("digitalStopwatch");
var countdown = document.getElementById("digitalCountdown");
var barcoded = document.getElementById("barcoded");
function tick() {
var date = new Date();
ctx.clearRect(0, 0, canvas.width , canvas.height );
drawStatic();
var hours = date.getHours();
ctx.strokeStyle = "yellow";
ctx.lineWidth = 3;
drawHand(clockWidth/3, hours * 30);
var minutes = date.getMinutes();
ctx.strokeStyle = "orange";
ctx.lineWidth = 2;
drawHand(clockWidth/2.5, minutes * 6);
var seconds = date.getSeconds();
ctx.strokeStyle = "red";
ctx.lineWidth = 1;
drawHand(clockWidth/2, seconds * 6);
digital.innerText = ("0"+hours).slice(-2)+":"+("0"+minutes).slice(-2)+":"+("0"+seconds).slice(-2);
barcoded.innerText = stardate.split(".")[0].replaceAll("-","") + ("0"+hours).slice(-2)+("0"+minutes).slice(-2)+("0"+seconds).slice(-2);
if (sinceTimeZero) {
stopwatch.innerText = ("0"+Math.floor(sinceTimeZero / 360)).slice(-2) + ":" + ("0"+Math.floor(sinceTimeZero / 60)).slice(-2) + ":" + ("0"+sinceTimeZero % 60).slice(-2);
sinceTimeZero += 1;
}
if (countdownSpan > -1 ) {
countdown.innerText = ("0"+Math.floor(countdownSpan / 360)).slice(-2) + ":" + ("0"+Math.floor(countdownSpan / 60)).slice(-2) + ":" + ("0"+countdownSpan % 60).slice(-2);
countdownSpan -= 1;
}
function drawStatic() {
ctx.beginPath();
ctx.arc(centerX, centerY, clockWidth/2, 0, 2 * Math.PI, false);
ctx.strokeStyle = "green";
ctx.lineWidth = 1;
ctx.stroke();
ctx.closePath();
ctx.beginPath();
ctx.arc(centerX, centerY, 2, 0, 2 * Math.PI, false);
ctx.fillStyle = "green";
ctx.fill();
ctx.closePath();
//weirdo outer deka-ring
ctx.beginPath();
ctx.arc(centerX, centerY, clockWidth/3.25, 0, 2 * Math.PI, false);
ctx.strokeStyle = "green";
ctx.lineWidth = 1;
ctx.stroke();
ctx.closePath();
//
function drawDekaNumbers() {
var i = 10;
ctx.strokeStyle = "grey";
ctx.lineWidth = 1;
while(i > 0) {
ctx.save();
ctx.beginPath();
ctx.translate(centerX, centerY);
var angle = (i * 36) * Math.PI/180;
ctx.rotate(angle);
ctx.translate(0, -clockWidth/3.25);
ctx.moveTo(0, 0);
ctx.lineTo(0, 10);
ctx.stroke();
ctx.closePath();
ctx.restore();
i --;
}
}
drawDekaNumbers();
drawNumbers();
function drawNumbers() {
var i = 12;
ctx.strokeStyle = "green";
ctx.lineWidth = 2;
while(i > 0) {
ctx.save();
ctx.beginPath();
ctx.translate(centerX, centerY);
var angle = (i * 30) * Math.PI/180;
ctx.rotate(angle);
ctx.translate(0, -clockWidth/2);
// Drawing numbers doesn't look so good because of the origin of the text
// ctx.save();
// ctx.translate(0, -10);
// ctx.rotate(-angle);
// ctx.fillText(i, -3, 0);
// ctx.restore();
ctx.moveTo(0, 0);
ctx.lineTo(0, 10);
ctx.stroke();
ctx.closePath();
ctx.restore();
i --;
}
}
}
function drawHand(length, angle) {
ctx.save();
ctx.beginPath();
ctx.translate(centerX, centerY);
ctx.rotate(-180 * Math.PI/180); // Correct for top left origin
ctx.rotate(angle * Math.PI/180);
ctx.moveTo(0, 0);
ctx.lineTo(0, length);
ctx.stroke();
ctx.closePath();
ctx.restore();
}
}
tick();
window.setInterval(tick, 1000);
}
setupAnalogClock(document.getElementById("analogClock"), 100);
</script>
</html>