-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
834 lines (631 loc) · 26 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
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
<html>
<head>
<meta charset="utf-8" />
<title>Sanduhr.org</title>
</head>
<body>
<div style="height:700px;width:1000px;position:relative">
<canvas width="1000px" height="700px" id="my-canvas"
style='position:absolute;top:0;left:0;z-index: 1;'></canvas>
<canvas width="1000px" height="700px" id="myOverlay"
style='position:absolute;top:0;left:0;z-index: 2;'></canvas>
</div>
<div>
<button type="button" style="height: 200; width: 400;" onclick="drawHardware()"> Mal die Zahlen in den Sand!</button>
<br>
<a href="https://github.com/geepy/Sanduhr">Das GitHub Repository zu diesem Projekt</a>
</div>
</body>
<script type="text/javascript">
const myCanvas = document.getElementById("my-canvas")
const ctx = myCanvas.getContext('2d');
const ovl = myOverlay.getContext('2d');
const servo1_pos = { x: 390, y: 50 }
const servo2_pos = { x: 610, y: 50 }
const length_arm_b = 400;
const length_arm_a = 300;
const COLOR_RED = 'red';
const COLOR_GREEN = 'green';
const NEUNZIG_GRAD = Math.PI / 2;
const DELAY = 20;
const PUNKTE = 4;
var pos_stift = { x: 190, y: 550 };
var stift_malt = false;
var real_width = 126.5;
var spacing = 36;
var real_height = 300;
var stift_position = { x: 190, y: 550 };
var wirklicher_start = { x: 150, y: 550 }
// Hilfsfunktion, weil Javascript kein string.format() hat
String.prototype.format = function () {
a = this;
for (k in arguments) {
a = a.replace("{" + k + "}", arguments[k])
}
return a
}
function stift_hoch() {
stift_malt = false;
}
function stift_runter() {
stift_malt = true;
}
function degToRad(angle) {
return angle * Math.PI / 180;
}
function drawDotOnCanvas(ctx, point, size) {
ctx.fillStyle = 'black';
ctx.beginPath();
ctx.arc(point.x, point.y, size / 2, degToRad(0), degToRad(359), false);
ctx.fill();
}
function drawDot(point, size) {
drawDotOnCanvas(ctx, point, size);
}
function drawDotOnOverlay(point, size) {
if (stift_malt) {
drawDotOnCanvas(ovl, point, size);
}
}
function clearOverlay() {
ovl.clearRect(0, 0, myOverlay.width, myOverlay.height);
}
function drawServo(servo_pos) {
ctx.fillStyle = 'green';
ctx.fillRect(servo_pos.x - 90, servo_pos.y - 40, 180, 80);
ctx.fillStyle = 'black';
drawDot(servo_pos, 10);
}
function drawSandbox(pos, size) {
ctx.fillStyle = '#e0ff20';
ctx.fillRect(pos.x, pos.y, size.x, size.y);
}
function drawArm(start, ende, farbe) {
const armWidth = 20;
drawDot(start, armWidth);
ctx.beginPath();
ctx.moveTo(start.x, start.y);
ctx.lineWidth = armWidth;
ctx.lineTo(ende.x, ende.y);
ctx.strokeStyle = farbe;
ctx.stroke();
// drawDot(ende, armWidth);
}
function drawCanvas() {
ctx.fillStyle = '#ffc000';
ctx.fillRect(0, 0, 1000, 700);
drawServo(servo1_pos);
drawServo(servo2_pos);
drawSandbox({ x: 130, y: 230 }, { x: 690, y: 340 });
}
function draw_line_by_angle(starting_point, angle, length, farbe) {
ende = end_from_angle(starting_point, angle, length);
drawArm(starting_point, ende, farbe);
}
function end_from_angle(starting_point, angle, length) {
a = length * Math.sin(angle);
b = length * Math.cos(angle);
ende_x = starting_point.x + b;
ende_y = starting_point.y + a;
ende = { x: ende_x, y: ende_y };
return ende;
}
function draw_two_lines(from, to, seite) {
if (seite == 1) {
// function draw_two_lines_left(from, to, seite) {
var DR = to.y - from.y;
var AR = to.x - from.x;
var AD = Math.sqrt(AR * AR + DR * DR);
var r1 = (Math.asin(DR / AD));
var w1 = Math.acos(
(length_arm_a ** 2 + AD ** 2 - length_arm_b ** 2)
/ (2 * length_arm_a * AD)
); // Kosinussatz
var alpha = (r1 + w1);
if (AR < 0) {
alpha = (NEUNZIG_GRAD * 2 - r1) + w1
}
//var w2 = Math.asin(AD / length_arm_a);
var w2 = Math.acos(
(length_arm_a ** 2 + length_arm_b ** 2 - AD ** 2)
/ (2 * length_arm_b * length_arm_a)
); // Kosinussatz
var beta2 = Math.PI - alpha;
var beta3 = NEUNZIG_GRAD - beta2;
var AF = length_arm_a * Math.cos(beta2);
var FE = Math.sqrt(length_arm_a * length_arm_a - AF * AF);
if (alpha > 2 * NEUNZIG_GRAD) {
FE = -FE;
}
var gelenk = { x: from.x - AF, y: from.y + FE };
draw_line_by_angle(from, alpha, length_arm_a, COLOR_RED);
drawDot(gelenk, 30);
draw_line_by_angle(gelenk, w2 + beta3 - NEUNZIG_GRAD, length_arm_b, COLOR_GREEN);
drawDotOnOverlay(to, 30);
}
else {
// function draw_two_lines_right(from, to) {
var DR = to.y - from.y; //check
var BR = (from.x) - to.x; //check
var BD = Math.sqrt(BR * BR + DR * DR); //check
var r1 = Math.atan(DR / BR); //check außer rechts von servo2_pos
var w1 = Math.acos(
(length_arm_a ** 2 + BD ** 2 - length_arm_b ** 2)
/ (2 * length_arm_a * BD)
); // Kosinussatz
var alpha = 2 * NEUNZIG_GRAD - (r1 + w1);
if (BR < 0) {
alpha = alpha - 2 * NEUNZIG_GRAD;
}
//var w2 = Math.asin(AD / length_arm_a);
var w2 = Math.acos(
(length_arm_a ** 2 + length_arm_b ** 2 - BD ** 2)
/ (2 * length_arm_b * length_arm_a)
); // Kosinussatz
var beta2 = Math.PI - alpha;
var beta3 = NEUNZIG_GRAD - beta2;
var AF = length_arm_a * Math.cos(beta2);
if (AF < 0) {
gelenk = { x: from.x + AF, y: from.y + FE };
}
var FE = Math.sqrt(length_arm_a * length_arm_a - AF * AF);
if (alpha < 0) {
FE = -FE;
}
var gelenk = { x: from.x - AF, y: from.y + FE };
draw_line_by_angle(from, alpha, length_arm_a, COLOR_RED);
// console.log("from.x: {0}, from.y: {1}, DR: {2}, AR: {3}, AD: {4}, w2: {5}"
// .format(from.x, from.y, DR, AR, AD, w2));
drawDotOnOverlay(to, 30);
drawDot(gelenk, 30);
draw_line_by_angle(gelenk, -w2 + beta3 - NEUNZIG_GRAD, length_arm_b, COLOR_GREEN);
}
}
/****************************
* BEGIN Code von außerhalb *
****************************/
function delay(n) {
n = n || 2000;
return new Promise(done => {
setTimeout(() => {
done();
}, n);
});
}
async function move_arms(angle_left, angle_right) {
await delay(DELAY);
var alpha = angle_left;
var beta = angle_right;
// berechnen des Endpunkts für linken unteren Arm
var gelenk_links = {
x: servo1_pos.x + Math.cos(alpha) * length_arm_a,
y: servo1_pos.y + Math.sin(alpha) * length_arm_a
}
var gelenk_rechts = {
x: servo2_pos.x + Math.cos(beta) * length_arm_a,
y: servo2_pos.y + Math.sin(beta) * length_arm_a
}
// Länge der Strecke C zwischen diesen beiden Punkten (Hypothenuse des Dreiecks C-Arm_b-Arm_b)
var c = Math.sqrt((gelenk_rechts.x - gelenk_links.x) ** 2 + (gelenk_rechts.y - gelenk_links.y) ** 2)
// check: C darf nicht länger sein als 2*b, sonst gibt es keinen Schnittpunkt zwischen den B-Armen
if (c > 2 * length_arm_b) {
console.log('Winkel {1} und {2} sind außerhalb des physisch darstellbaren Bereichs'.format(degToRad(alpha), degToRad(beta)))
return;
}
// Winkel zwischen C und arm_b (für beide gleich, da gleichschenkliges Dreieck)
var gamma = Math.acos(c / (2 * length_arm_b))
// Winkel zwischen Waagerechte und Linie C
var delta = 0;
if (gelenk_links.y != gelenk_rechts.y) {
var e = (gelenk_rechts.x - gelenk_links.x)
var f = (gelenk_rechts.y - gelenk_links.y)
zwerg = (e ** 2 + c ** 2 - f ** 2) / (2 * e * c)
delta = Math.acos(zwerg)
if (gelenk_links.y > gelenk_rechts.y) { delta = -delta; }
}
var alpha_1 = gamma + delta
var beta_1 = (2 * NEUNZIG_GRAD) - gamma + delta
pos_stift = {
x: gelenk_links.x + Math.cos(alpha_1) * length_arm_b,
y: gelenk_links.y + Math.sin(alpha_1) * length_arm_b
};
stift_position = {
x: gelenk_links.x + Math.cos(alpha_1) * length_arm_b,
y: gelenk_links.y + Math.sin(alpha_1) * length_arm_b
};
// malen
drawCanvas()
draw_line_by_angle(servo1_pos, alpha, length_arm_a, COLOR_RED);
draw_line_by_angle(gelenk_links, alpha_1, length_arm_b, COLOR_GREEN);
draw_line_by_angle(servo2_pos, beta, length_arm_a, COLOR_RED);
draw_line_by_angle(gelenk_rechts, beta_1, length_arm_b, COLOR_GREEN);
drawDotOnOverlay(pos_stift, 20);
}
function update_arms_from_ui() {
leftSliderValue.innerText = left_angle.value;
rightSliderValue.innerText = right_angle.value;
alpha = parseInt(left_angle.value, 10) / 180 * Math.PI;
beta = parseInt(right_angle.value, 10) / 180 * Math.PI;
stift_runter();
move_arms(alpha, beta);
stift_hoch();
}
/**************************
* END Code von außerhalb *
**************************/
// Zweiter Arm
//draw_two_lines_left(servo2_pos, mouse_position);
//mein krams
function calculate_angle(from, to, seite) {
var alpha;
if (seite == 2) {
var DR = to.y - from.y; //check
var BR = (from.x) - to.x; //check
var BD = Math.sqrt(BR * BR + DR * DR); //check
var r1 = Math.atan(DR / BR); //check außer rechts von servo2_pos
var w1 = Math.acos(
(length_arm_a ** 2 + BD ** 2 - length_arm_b ** 2)
/ (2 * length_arm_a * BD)
); // Kosinussatz
alpha = 2 * NEUNZIG_GRAD - (r1 + w1);
if (BR < 0) {
alpha = alpha - 2 * NEUNZIG_GRAD;
}
}
else {
var DR = to.y - from.y;
var AR = to.x - from.x;
var AD = Math.sqrt(AR * AR + DR * DR);
var r1 = (Math.asin(DR / AD));
var w1 = Math.acos(
(length_arm_a ** 2 + AD ** 2 - length_arm_b ** 2)
/ (2 * length_arm_a * AD)
); // Kosinussatz
alpha = (r1 + w1);
if (AR < 0) {
alpha = (NEUNZIG_GRAD * 2 - r1) + w1
}
}
return alpha;
}
async function draw_circle(radius_x, radius_y, mittelpunkt, start_winkel, end_winkel) {
stift_hoch();
var wechsel = 1;
for (winkel = start_winkel; winkel < end_winkel; winkel += NEUNZIG_GRAD / 20) {
var ende = end_from_angle(mittelpunkt, winkel, radius_x);
// skalieren, damit es ein Oval wird
ende.y = mittelpunkt.y + (ende.y - mittelpunkt.y) * (radius_y / radius_x);
var alpha = calculate_angle(servo1_pos, ende, 1);
var beta = calculate_angle(servo2_pos, ende, 2);
await stift_runter();
if (wechsel == 1) {
await draw_invisible_line(stift_position, ende);
wechsel = 2;
}
await move_arms(alpha, beta);
}
var ende = end_from_angle(mittelpunkt, winkel, radius_x);
// skalieren, damit es ein Oval wird
ende.y = mittelpunkt.y + (ende.y - mittelpunkt.y) * (radius_y / radius_x);
var alpha = calculate_angle(servo1_pos, ende, 1);
var beta = calculate_angle(servo2_pos, ende, 2);
await move_arms(alpha, beta);
}
function draw_servo_line(start, end) {
}
async function move_arms_to(ende) {
var alpha = calculate_angle(servo1_pos, ende, 1);
var beta = calculate_angle(servo2_pos, ende, 2);
await move_arms(alpha, beta);
stift_position = ende;
}
async function draw_line(start, end) {
var a;
var b;
if (end.y >= start.y) {
a = start.y - end.y;
}
if (end.y <= start.y) {
a = end.y - start.y;
}
if (start.x >= end.x) {
b = end.x - start.x;
}
if (start.x <= end.x) {
b = end.x - start.x;
}
var c = Math.sqrt((a ** 2) + (b ** 2));
var abstand = PUNKTE;
var actual_abstand;
var angle = Math.acos(b / c);
if (start.y > end.y) {
angle = 2 * Math.PI - angle;
}
await move_arms_to(start);
for (actual_abstand = abstand; actual_abstand <= c; actual_abstand += abstand) {
var ende = end_from_angle(start, angle, actual_abstand);
await move_arms_to(ende);
}
await move_arms_to(end);
}
async function draw_invisible_line(start, end) {
stift_hoch();
var a;
var b;
if (end.y >= start.y) {
a = start.y - end.y;
}
if (end.y <= start.y) {
a = end.y - start.y;
}
if (start.x >= end.x) {
b = end.x - start.x;
}
if (start.x <= end.x) {
b = end.x - start.x;
}
var c = Math.sqrt((a ** 2) + (b ** 2));
var abstand = PUNKTE;
var actual_abstand;
var angle = Math.acos(b / c);
if (start.y > end.y) {
angle = 2 * Math.PI - angle;
}
await move_arms_to(start);
for (actual_abstand = abstand; actual_abstand <= c; actual_abstand += abstand) {
var ende = end_from_angle(start, angle, actual_abstand);
await move_arms_to(ende);
}
await move_arms_to(end);
stift_runter();
}
async function draw_number_one(start, höhe, breite) {
var current_position;
var future_position;
current_position = { x: start.x, y: start.y - (2 / 3 * höhe) };
move_arms_to(start);
await draw_invisible_line(stift_position, current_position);
future_position = { x: start.x + breite, y: start.y - höhe };
await draw_line(current_position, future_position);
current_position = future_position;
future_position = { x: start.x + breite, y: start.y };
await draw_line(current_position, future_position);
stift_hoch();
}
async function draw_number_two(start, höhe, breite) {
var current_position;
var future_position;
var viertel_zwei = höhe / 4;
current_position = { x: start.x + breite / 2, y: start.y - (höhe - viertel_zwei) };
stift_runter();
future_position = { x: start.x + breite, y: start.y - (höhe - viertel_zwei) };
await draw_circle(breite / 2, viertel_zwei, current_position, 2 * NEUNZIG_GRAD, 4 * NEUNZIG_GRAD);
await draw_line(future_position, start);
current_position = start;
future_position = { x: start.x + breite, y: start.y }
await draw_line(current_position, future_position);
stift_hoch();
}
async function draw_number_three(start, höhe, breite) {
var current_position;
var future_position;
var viertel_drei = höhe / 4;
current_position = { x: start.x + breite / 2, y: start.y - höhe + viertel_drei };
stift_runter();
future_position = { x: start.x + breite / 2, y: start.y - viertel_drei };
await draw_circle(breite / 2, viertel_drei, current_position, 2 * NEUNZIG_GRAD, 5 * NEUNZIG_GRAD);
await draw_circle(breite / 2, viertel_drei, future_position, 3 * NEUNZIG_GRAD, 6 * NEUNZIG_GRAD);
stift_hoch();
}
async function draw_number_four(start, höhe, breite) {
var current_position;
var future_position;
current_position = { x: start.x + breite, y: start.y - höhe * 0.4 };
await draw_invisible_line(stift_position, current_position);
stift_runter();
future_position = { x: start.x, y: start.y - höhe * 0.4 };
await draw_line(current_position, future_position);
current_position = future_position;
future_position = { x: start.x + breite / 2, y: start.y - höhe };
await draw_line(current_position, future_position);
stift_hoch();
future_position = { x: start.x + breite / 2, y: start.y - höhe * 0.6 };
await draw_invisible_line(stift_position, future_position);
current_position = future_position;
future_position = { x: start.x + breite / 2, y: start.y }
stift_runter();
await draw_line(current_position, future_position);
stift_hoch();
}
async function draw_number_five(start, höhe, breite) {
var current_position;
var future_position;
var viertel_vier = höhe / 4;
current_position = { x: start.x + breite, y: start.y - höhe };
await draw_invisible_line(stift_position, current_position);
stift_runter();
future_position = { x: start.x, y: start.y - höhe };
await draw_line(current_position, future_position);
current_position = future_position;
future_position = { x: start.x, y: start.y - 2 * viertel_vier };
await draw_line(current_position, future_position);
current_position = future_position;
future_position = { x: start.x + breite / 2, y: start.y - 2 * viertel_vier };
await draw_line(current_position, future_position);
future_position = { x: start.x + breite / 2, y: start.y - höhe / 4 };
await draw_circle(breite / 2, viertel_vier, future_position, 3 * NEUNZIG_GRAD, 6 * NEUNZIG_GRAD);
stift_hoch();
}
async function draw_number_six(start, höhe, breite) {
var current_position;
var future_position;
var viertel_sechs = höhe / 4;
future_position = { x: start.x + breite / 2, y: start.y - viertel_sechs };
stift_runter();
await draw_circle(breite / 2, viertel_sechs, future_position, 2 * NEUNZIG_GRAD, 6 * NEUNZIG_GRAD);
current_position = { x: start.x, y: start.y - breite / 2 };
future_position = { x: start.x, y: start.y - 3 * viertel_sechs };
await draw_line(stift_position, future_position);
current_position = { x: start.x + breite / 2, y: (future_position.y) };
await draw_circle(breite / 2, viertel_sechs, current_position, 2 * NEUNZIG_GRAD, 4 * NEUNZIG_GRAD);
stift_hoch();
}
async function draw_number_seven(start, höhe, breite) {
var current_position;
var future_position;
current_position = { x: start.x, y: start.y - höhe };
await draw_invisible_line(stift_position, current_position);
stift_runter();
future_position = { x: start.x + breite, y: start.y - höhe };
await draw_line(current_position, future_position);
current_position = future_position;
future_position = start;
await draw_line(current_position, future_position);
current_position = { x: start.x, y: start.y - höhe / 2 };
future_position = { x: start.x + breite, y: start.y - höhe / 2 }
await draw_invisible_line(stift_position, current_position);
await draw_line(current_position, future_position);
stift_hoch();
}
async function draw_number_eight(start, höhe, breite) {
var current_position;
var future_position;
var viertel_acht = höhe / 4;
current_position = { x: start.x + breite / 2, y: start.y - viertel_acht };
stift_runter();
await draw_circle(breite / 2, viertel_acht, current_position, 3 * NEUNZIG_GRAD, 7 * NEUNZIG_GRAD);
stift_hoch();
current_position.y -= 2 * viertel_acht;
stift_runter();
await draw_circle(breite / 2, viertel_acht, current_position, 1 * NEUNZIG_GRAD, 5 * NEUNZIG_GRAD);
stift_hoch();
}
async function draw_number_nine(start, höhe, breite) {
var current_position;
var future_position;
var viertel_neun = höhe / 4;
stift_runter();
future_position = { x: start.x + breite / 2, y: start.y - (höhe - viertel_neun) };
await draw_circle(breite / 2, viertel_neun, future_position, 0, 4 * NEUNZIG_GRAD);
current_position = { x: start.x + breite, y: start.y - viertel_neun };
future_position = { x: start.x + breite, y: start.y - (höhe - viertel_neun) };
await draw_line(future_position, current_position);
current_position = { x: start.x + breite / 2, y: start.y - viertel_neun };
await draw_circle(breite / 2, viertel_neun, current_position, 0, 2 * NEUNZIG_GRAD);
stift_hoch();
}
async function draw_number_zero(start, höhe, breite) {
var current_position;
var future_position;
var viertel_null = höhe / 4;
current_position = { x: start.x + breite / 2, y: start.y - 3 * viertel_null };
await draw_circle(breite / 2, viertel_null, current_position, 2 * NEUNZIG_GRAD, 4 * NEUNZIG_GRAD)
current_position = { x: start.x + breite, y: start.y - 3 * viertel_null };
future_position = { x: start.x + breite, y: start.y - viertel_null };
await draw_line(current_position, future_position);
current_position = { x: start.x + breite / 2, y: start.y - viertel_null };
await draw_circle(breite / 2, viertel_null, current_position, 0, 2 * NEUNZIG_GRAD);
current_position = { x: start.x, y: start.y - viertel_null };
future_position = { x: start.x, y: start.y - 3 * viertel_null };
await draw_line(current_position, future_position);
}
async function draw_number(position, number) {
var actual_start;
actual_start = { x: (wirklicher_start.x) + (position - 1) * (real_width + spacing), y: (wirklicher_start.y) };
if (position > 2) {
actual_start.x += spacing;
}
switch (number) {
case 1:
await draw_number_one(actual_start, real_height, real_width);
break;
case 2:
await draw_number_two(actual_start, real_height, real_width);
break;
case 3:
await draw_number_three(actual_start, real_height, real_width);
break;
case 4:
await draw_number_four(actual_start, real_height, real_width);
break;
case 5:
await draw_number_five(actual_start, real_height, real_width);
break;
case 6:
await draw_number_six(actual_start, real_height, real_width);
break;
case 7:
await draw_number_seven(actual_start, real_height, real_width);
break;
case 8:
await draw_number_eight(actual_start, real_height, real_width);
break;
case 9:
await draw_number_nine(actual_start, real_height, real_width);
break;
case 0:
await draw_number_zero(actual_start, real_height, real_width);
break;
}
}
async function draw_doppelpunkt(height, width) {
var punkt_unten = { x: wirklicher_start.x + real_width * 2 + spacing * 2, y: wirklicher_start.y - (1 / 3) * real_height };
var punkt_oben = { x: wirklicher_start.x + real_width * 2 + spacing * 2, y: wirklicher_start.y - (2 / 3) * real_height };
stift_hoch();
await draw_invisible_line(stift_position, punkt_unten);
stift_runter();
drawDotOnOverlay(punkt_unten, 20);
stift_hoch();
await draw_invisible_line(stift_position, punkt_oben);
stift_runter();
drawDotOnOverlay(punkt_oben, 20);
stift_hoch();
}
async function draw_time(first_digit, second_digit, third_digit, fourth_digit, start, width, height) {
await draw_number(1, first_digit);
await draw_number(2, second_digit);
await draw_doppelpunkt(real_width / 2, real_height);
await draw_number(3, third_digit);
await draw_number(4, fourth_digit);
}
var lastDate = new Date();
async function draw_new_time(force) {
var date = new Date();
if (force || date.getMinutes() != lastDate.getMinutes()) {
clearOverlay();
await draw_time(Math.floor(date.getHours() / 10), date.getHours() % 10, Math.floor(date.getMinutes() / 10), date.getMinutes() % 10, 650);
lastDate = date;
}
setTimeout("draw_new_time(false)", 1000);
}
function drawHardware() {
self.location = '/index.html?drawTime=' + new Date().toTimeString().substring(0, 5)
}
/*
**********************************************************
Possible start points :
First Position = {x:150, y: 550}
Second Position = {x:150 + 162,5, y: 550}
Third Position = {x:150 + 162,5 + 162,5, y: 550}
Fourth Position = {x:150 + 162,5 + 162,5 + 162,5, y: 550}
**********************************************************
*/
// initialization
// main program
drawCanvas();
//clearOverlay();
// der Rest passiert in den Event-Handlern
// myOverlay.onmousedown = stift_runter;
// myOverlay.onmouseup = stift_hoch;
// rechte Maustaste löscht Spur
// Default-Aktion (Kontextmenü des Browsers) wird verhindert
myOverlay.oncontextmenu = (event) => {
clearOverlay();
event.preventDefault();
}
draw_new_time(true);
//draw_time(8, 8, 6, 6)
//move_arms_to({x: 150, y: 550});
//draw_time(0);
</script>
</html>