-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
510 lines (417 loc) · 14.9 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Miscthings TAXI</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="nosleep.js"></script>
<link rel="stylesheet" href="style.css">
<style>
.number {
font-family: 'Digital-7 Mono Mono', monospace;
}
.meter {
font-family: 'Digital-7 Mono Mono', monospace;
}
body {
background-color: black;
}
* {
color: white;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0, 0, 0); /* Fallback color */
background-color: rgba(0, 0, 0, 0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: #000000;
/* 15% from the top and centered */
margin: 10% auto;
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
#anim {
background-image: url('horse_sprite_small_small.png');
width: 200px;
height: 127px;
animation: anim 0.1s steps(6) infinite;
}
@keyframes anim {
100% {
background-position: -1200px;
}
}
</style>
</head>
<body>
<table width="100%">
<tbody>
<tr>
<th style="font-size: 4em; text-align: center" class="number">
<div id="anim" style=" display: inline-block;"></div>
</th>
<th style="font-size: 4em; vertical-align: middle" class="number" id="status_html">STOP</th>
</tr>
<tr>
<td class="number" style="font-size: 3.6em; text-align: left;" onclick="change_hal();" id="hal_html">888,888
</td>
<td class="meter" style="font-size: 4em; color: lightsalmon; text-align: right;" id="danwe">8888</td>
</tr>
<tr>
<td colspan="2" style="text-align: right; padding-bottom: 4em;" onclick="run_meter();">
<span style="font-size: 6em; font-weight: bold; color: #62e762" class="number"
id="pay">888,888</span>
<span style="font-size: 2em; color: gray ">₩</span></td>
</tr>
<tr>
<td onclick="run_meter();" id="drive_btn"
style="width:50%; font-size: 3em; font-weight: 100; height: 100px; text-align: center; background-color: #363b2a">
주행
</td>
<td onclick="change_hal();"
style="width:50%; font-size: 3em; font-weight: 100; height: 100px; text-align: center; background-color: #462727">
할증
</td>
</tr>
</tbody>
</table>
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<div style="width: 100%; text-align: center">
<div style="font-size: 4em;">요금</div>
<span style="font-size: 4em; font-weight: bold; color: #62e762" class="number"
id="pay1">9,999,999</span>
<span style="font-size: 1em; color: gray ">₩</span>
</div>
</div>
</div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div>
<button onclick="nosleep()">화면켜짐</button>
<button onclick="dbg()">디버그모드</button>
</div>
<div id="distance_meter_htm"></div>
<div>/</div>
<div id="dst_result"></div>
<div id="geoinfo"></div>
<div id="errorstore">
NO ERROR
</div>
<script>
var noSleep = new NoSleep();
function nosleep() {
noSleep.enable();
}
</script>
<script>
let enable = false;
let timer = null;
let trip_timer = null;
let horse_timer = null;
let last_long_lat = null;
let distance_meter = 0;
let trip_meter = 0;
const DEFAULT_PAY = 3200;
const DANWE_FIRST = 2000;
const DANWE = 142;
let danwe_mode = 0
let hal = 0;
const hal_array = [0, 20, 50, 100]
let hal_idx = 0;
let status = 0;
const status_text = ["STOP", "DRIVE"]
const drive_btn_text = ["주행", "정지"]
let pay_total = DEFAULT_PAY;
// animation variables
const ANIMATION_DURATION_DEFAULT = 1000;
</script>
<script>
var el = document.getElementById('anim');
el.style.animationPlayState = 'paused';
function play() {
el.style.animationPlayState = 'running';
}
function pause() {
el.style.animationPlayState = 'paused';
}
function reset() {
el.style.animation = 'none';
el.offsetHeight; /* trigger reflow to apply the change immediately */
el.style.animation = null;
}
function stop() {
reset();
pause();
}
</script>
<script>
let trip_update_last_timestamp = 0;
let last_trips = [];
const TRIP_UPDATE_EXPIRE = 3000;
function trip_meter_add(x) {
trip_meter += x;
trip_update_last_timestamp = (new Date()).valueOf()
}
function trip_meter_reset() {
trip_meter = 0;
}
let last_trip_data = 0;
function adjust_horse_speed() {
let now = (new Date()).valueOf();
if(trip_update_last_timestamp + TRIP_UPDATE_EXPIRE < now){
el.style.animationPlayState = 'paused'
return;
}
if (last_trip_data < trip_meter) {
let diff = trip_meter - last_trip_data;
let speed = diff * 3.6;
last_trip_data = trip_meter;
if (speed < 5) {
el.style.animationPlayState = 'paused'
return;
}
el.style.animationPlayState = 'running'
let css_speed = "0.8s"
if (speed < 32) {
css_speed = "0.8s"
} else if (speed < 40) {
css_speed = "0.6s"
} else if (speed < 60) {
css_speed = "0.4s"
} else if (speed < 80) {
css_speed = "0.3s"
} else if (speed < 90) {
css_speed = "0.2s"
} else if (speed < 100) {
css_speed = "0.1s"
} else {
css_speed = "0.1s"
}
console.log(speed, "kmph", css_speed)
document.getElementById('anim').style.animationDuration = css_speed;
}
}
function change_hal() {
if (hal_idx === hal_array.length - 1) {
hal_idx = 0;
} else {
hal_idx += 1;
}
hal = hal_array[hal_idx];
hal_html.innerHTML = hal + "%"
}
function dbg() {
danwe_mode = 1;
let plus_meter = 3.6
setInterval(function () {
plus_meter = Math.random() * 10 + 30
trip_meter_add(plus_meter)
distance_meter += plus_meter
}, 1000)
}
function run_meter() {
status = status === 1 ? 0 : 1;
status_html.innerHTML = status_text[status];
drive_btn.innerHTML = drive_btn_text[status];
if (status === 1) {
timer = setInterval(acc_distance, 10);
horse_timer = setInterval(adjust_horse_speed, 1000);
distance_meter = 0;
danwe_mode = 0;
pay_total = DEFAULT_PAY;
pay.innerHTML = DEFAULT_PAY.toLocaleString();
hal = hal_array[hal_idx];
hal_html.innerHTML = hal + "%"
document.getElementById('danwe').innerHTML = DANWE_FIRST;
// trip timer setting
trip_meter_reset();
if (hal === 0) {
trip_timer = setInterval(update_trip, 100);
}
} else {
showmodal();
clearInterval(timer);
pay1.innerHTML = pay_total.toLocaleString()
pay_total = DEFAULT_PAY;
danwe_mode = 0;
// pay.innerHTML = DEFAULT_PAY.toLocaleString();
clearInterval(trip_timer);
clearInterval(horse_timer);
el.style.animationPlayState = 'paused';
}
}
function update_trip() {
hal_html.innerHTML = Math.round(trip_meter).toLocaleString();
}
let danwe_prev_value = 0;
let animation_allow_start_at = 0;
function acc_distance() {
let danwe_gijun = danwe_mode === 0 ? DANWE_FIRST : DANWE;
if (danwe_gijun - distance_meter < 0) {
pay_total += (100 * (1 + (hal / 100)));
distance_meter = 0 + Math.abs(danwe_gijun - distance_meter);
danwe_mode = 1;
danwe_gijun = DANWE;
}
let danwe_current = Math.floor(danwe_gijun - distance_meter)
let now = (new Date()).valueOf();
if (danwe_current !== danwe_prev_value && animation_allow_start_at < now) {
let animation_duration = ANIMATION_DURATION_DEFAULT;
// 현재 값이 더 크면 애니메이션 발동 X
if (danwe_current > danwe_prev_value) {
danwe_prev_value = danwe_gijun
pay.innerHTML = pay_total.toLocaleString();
}
animate(document.getElementById('danwe'), danwe_prev_value, danwe_current, animation_duration);
animation_allow_start_at = now + animation_duration;
danwe_prev_value = danwe_current
}
}
function animate(obj, initVal, lastVal, duration) {
let startTime = null;
//get the current timestamp and assign it to the currentTime variable
let currentTime = Date.now();
//pass the current timestamp to the step function
const step = (currentTime) => {
//if the start time is null, assign the current time to startTime
if (!startTime) {
startTime = currentTime;
}
//calculate the value to be used in calculating the number to be displayed
const progress = Math.min((currentTime - startTime) / duration, 1);
//calculate what to be displayed using the value gotten above
obj.innerHTML = Math.floor(progress * (lastVal - initVal) + initVal);
//checking to make sure the counter does not exceed the last value (lastVal)
if (progress < 1) {
window.requestAnimationFrame(step);
} else {
window.cancelAnimationFrame(window.requestAnimationFrame(step));
}
};
//start animating
window.requestAnimationFrame(step);
}
</script>
<script>
// Get the modal
var modal = document.getElementById("myModal");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
function showmodal() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target === modal) {
modal.style.display = "none";
}
}
window.ontouchend = function (event) {
if (event.target === modal) {
modal.style.display = "none";
}
}
</script>
<script>
getLocation()
function getLocation() {
errorstore.innerHTML = "LOADING"
// Get location no more than 10 minutes old. 600000 ms = 10 minutes.
navigator.geolocation.watchPosition(accLocation, showError, {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
});
}
function showError(error) {
errorstore.innerHTML = error.code + ' ' + error.message;
// alert( error.code + ' ' + error.message);
}
function accLocation(position) {
enable = true
geoinfo.innerHTML = '<p>Latitude: ' + position.coords.latitude + '</p>'
+ '<p>Longitude: ' + position.coords.longitude + '</p>'
+ '<p>Accuracy: ' + position.coords.accuracy + '</p>'
+ '<p>Altitude: ' + position.coords.altitude + '</p>'
+ '<p>Altitude accuracy: ' + position.coords.altitudeAccuracy + '</p>'
+ '<p>Speed: ' + position.coords.speed + '</p>'
+ '<p>Heading: ' + position.coords.heading + '</p>'
+ '<p>Heading: ' + new Date() + '</p>';
if (last_long_lat === null) {
last_long_lat = [position.coords.longitude, position.coords.latitude]
return
} else {
let distance_result = Math.abs(distance(last_long_lat[0], last_long_lat[1], position.coords.longitude, position.coords.latitude))
last_long_lat = [position.coords.longitude, position.coords.latitude]
dst_result.innerHTML = distance_result
distance_meter_htm.innerHTML = distance_meter
if (distance_result < 3) {
return;
}
distance_meter += distance_result
trip_meter_add(distance_result)
}
return [position.coords.latitude, position.coords.longitude]
}
if (navigator.geolocation) {
document.write('<p><input type="button" onclick="getLocation()" value="Show Geolocation Information" /></p>');
} else {
document.write('<p>Sorry, your device or browser software does not appear to support geolocation services.</p>');
enable = false;
}
function distance(lon1, lat1, lon2, lat2) {
var R = 6371008; // Radius of the earth in meter
var dLat = (lat2 - lat1).toRad(); // Javascript functions in radians
var dLon = (lon2 - lon1).toRad();
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return R * c;
}
/** Converts numeric degrees to radians */
if (typeof (Number.prototype.toRad) === "undefined") {
Number.prototype.toRad = function () {
return this * Math.PI / 180;
}
}
window.navigator.geolocation.getCurrentPosition(function (pos) {
console.log(pos);
console.log(
distance(pos.coords.longitude, pos.coords.latitude, 42.37, 71.03)
);
});
</script>
</body>
</html>