-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestbed-backup.html
More file actions
12139 lines (11017 loc) · 454 KB
/
testbed-backup.html
File metadata and controls
12139 lines (11017 loc) · 454 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
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<link rel = "icon" href = "https://e4494s.neocities.org/images/favicon.png" type = "image/png">
<link rel = "stylesheet" href = "https://e4494s.neocities.org/stylesheets/main.css">
<title>Test Bed ~ e4494s</title>
<style>
canvas {
width: 300px;
height: 300px;
border: 2px solid black;
}
hr {
border: 1px solid black;
}
.desc {
background-color: silver;
margin: 5px;
padding: 5px;
border-radius: 5px;
}
.desc mark {
background-color: #ffff4d;
}
</style>
</head>
<body>
<script src = "https://e4494s.neocities.org/scripts/main.js"></script>
<h1>The Island of Misfit Code</h1>
<!--
<canvas id = "canvas0"></canvas>
<button onclick = "startCanvas0()">Start/Stop</button>
<hr><hr>
<script>
const ctx0 = canvas0.getContext("2d");
canvas0.width = canvas0.height = 300;
let canvas0Running = false;
function frame0() {
ctx0.clearRect(0, 0, canvas0.width, canvas0.height);
if (canvas0Running) requestAnimationFrame(frame0);
}
frame0();
function startCanvas0() {
if (canvas0Running) canvas0Running = false;
else {
canvas0Running = true;
frame0();
}
}
</script>
-->
<div style = "font-size: 16px; background-color: rgba(255, 255, 100); padding: 8px; margin-top: 25px; margin-bottom: 25px; border-radius: 10px"><b><i>Reached 99 canvases! (6/30/2021 - 10/17/2021) Moved to <a href = "testbed2.html" target = "_blank">testbed2.html</a>.</i></b></div>
<canvas id = "canvas99" style = "background-color: black; width: 400px; height: 400px"></canvas>
<button onclick = "drawBands99()">Redraw</button>
<table>
<tr>
<td style = "padding: 5px">
<div><b><u>Number of Bands:</u></b> <span id = "numBands99Txt">30</span></div>
<input type = "range" min = "0" max = "23" value = "12" step = "1" id = "numBands99Range" oninput = "updateSettings99()">
</td>
<td></td>
<td></td>
<td rowspan = "10" style = "padding: 5px">
<button onclick = "randomizeSettings99()">Randomize Settings</button>
<div><b><u>Settings Presets:</u></b></div>
<div id = "presets99Div" style = "width: 150px"></div>
</td>
</tr>
<tr>
<td style = "padding: 5px">
<div><b><u>Min Band Offset Angle:</u></b> <span id = "minAngle99Txt">0</span>°</div>
<input type = "range" min = "0" max = "360" value = "0" step = "5" id = "minAngle99Range" oninput = "updateSettings99()">
</td>
<td style = "padding: 5px">
<div><b><u>Max Band Offset Angle:</u></b> <span id = "maxAngle99Txt">360</span>°</div>
<input type = "range" min = "0" max = "360" value = "360" step = "5" id = "maxAngle99Range" oninput = "updateSettings99()">
</td>
</tr>
<tr>
<td style = "padding: 5px">
<div><b><u>Hue:</u></b> <span id = "hue99Txt">60</span>°</div>
<input type = "range" min = "0" max = "360" value = "60" step = "5" id = "hue99Range" oninput = "updateSettings99()">
</td>
<td style = "padding: 5px">
<div><b><u>Contrast:</u></b> <span id = "contrast99Txt">75</span>%</div>
<input type = "range" min = "0" max = "100" value = "75" step = "5" id = "contrast99Range" oninput = "updateSettings99()">
</td>
<td style = "padding: 5px">
<div><b><u>Rainbow:</u></b></div>
<input type = "checkbox" id = "rainbow99Checkbox" oninput = "updateSettings99()">
</td>
</tr>
<tr>
<td style = "padding: 5px">
<div><b><u>Band Thickness:</u></b> <span id = "bandThickness99Txt">5</span>px</div>
<input type = "range" min = "1" max = "25" value = "5" step = "1" id = "bandThickness99Range" oninput = "updateSettings99()">
</td>
<td style = "padding: 5px">
<div><b><u>Band Spacing:</u></b> <span id = "bandSpacing99Txt">15</span>px</div>
<input type = "range" min = "1" max = "50" value = "15" step = "1" id = "bandSpacing99Range" oninput = "updateSettings99()">
</td>
</tr>
<tr>
<td style = "padding: 5px">
<div><b><u>Connect Bands:</u></b></div>
<input type = "checkbox" id = "connectBands99Checkbox" oninput = "updateSettings99()" CHECKED>
</td>
<td style = "padding: 5px">
<div><b><u>Align Bands:</u></b></div>
<input type = "checkbox" id = "alignBands99Checkbox" oninput = "updateSettings99()" CHECKED>
</td>
</tr>
<tr>
<td style = "padding: 5px">
<div><b><u>Band Direction:</u></b></div>
<input type = "radio" name = "bandDirection99Radio" id = "bandDirection99Radio1" oninput = "updateSettings99()">
<label for = "bandDirection99Radio1">Randomize Direction</label>
<br>
<input type = "radio" name = "bandDirection99Radio" id = "bandDirection99Radio2" oninput = "updateSettings99()">
<label for = "bandDirection99Radio2">Same Direction</label>
<br>
<input type = "radio" name = "bandDirection99Radio" id = "bandDirection99Radio3" oninput = "updateSettings99()" CHECKED>
<label for = "bandDirection99Radio3">Alternate Direction</label>
</td>
</tr>
</table>
<div class = "desc"><b><i>(10/14/2021)</i></b> Simple interlocking bands generational art.<br><b><i>(10/15/2021)</i></b> Added more settings, colors, and sliders, as well as randomizing settings and settings presets.<br><b><i>(10/17/2021)</i></b> Added more presets.<br><b><i><mark>Actually finished! (11/18/2021)</mark> Moved to <a href = "bands.html" target = "_blank">bands.html</a>.</i></b></div>
<hr><hr>
<script>
const ctx99 = canvas99.getContext("2d");
canvas99.width = canvas99.height = 1000;
let numBands99 = 30;
let bandThickness99 = 5;
let bandSpacing99 = 15;
let connectBands99 = true;
let randomizeDirection99 = false;
let alternateDirection99 = true;
let alignBands99 = true;
let minAngle99 = 0;
let maxAngle99 = 360;
let hue99 = 60;
let rainbow99 = false;
let contrast99 = 75;
function drawBands99() {
ctx99.clearRect(0, 0, canvas99.width, canvas99.height);
ctx99.lineWidth = bandThickness99;
ctx99.lineJoin = ctx99.lineCap = "round";
let currAngle = Math.random() * Math.PI * 2;
let currX = canvas99.width / 2;
let currY = canvas99.height / 2;
if (connectBands99) ctx99.beginPath();
for (let i = 0; i < numBands99; i++) {
let h = rainbow99 ? ((i / numBands99) * 360) + hue99 : hue99;
ctx99.strokeStyle = `hsl(${h}deg, 100%, ${((i / numBands99) * contrast99) + ((100 - contrast99) / 2)}%)`;
//`hsl(${hue99}deg, 100%, ${((i / numBands99) * 70) + 15}%)`;
if (!alignBands99) currAngle = Math.random() * Math.PI * 2;
let sign = Math.random() >= 0.5 ? 1 : -1;
if (!randomizeDirection99) {
if (alternateDirection99) sign = i % 2 === 1 ? 1 : -1;
else sign = 1;
}
let nextAngle = currAngle + (toRad(randBetween(minAngle99, maxAngle99)) * sign);
let radius = i * bandSpacing99;
let nextX1 = (canvas99.width / 2) + (radius * Math.cos(currAngle));
let nextY1 = (canvas99.height / 2) + (radius * Math.sin(currAngle));
let nextX2 = (canvas99.width / 2) + (radius * Math.cos(nextAngle));
let nextY2 = (canvas99.height / 2) + (radius * Math.sin(nextAngle));
ctx99.beginPath();
ctx99.arc(canvas99.width / 2, canvas99.height / 2, radius, currAngle, nextAngle, sign === -1);
ctx99.stroke();
if (connectBands99) {
ctx99.beginPath();
ctx99.moveTo(currX, currY);
ctx99.lineTo(nextX1, nextY1);
ctx99.stroke();
}
currAngle = nextAngle;
currX = nextX2;
currY = nextY2;
}
}
drawBands99();
for (let i = 1; i <= 8; i++) {
let btn = document.createElement("button");
btn.innerHTML = i;
btn.style.display = "inline-block";
btn.style.margin = "5px";
btn.style.borderRadius = "50%";
btn.onclick = () => loadPreset99(i);
presets99Div.appendChild(btn);
}
function randomizeSettings99() {
let randomizeRange = element => element.value = Number(randBetween(Number(element.min), Number(element.max))).toMultipleOf(Number(element.step));
randomizeRange(numBands99Range);
randomizeRange(hue99Range);
rainbow99Checkbox.checked = Math.random() >= 0.5;
randomizeRange(contrast99Range);
randomizeRange(maxAngle99Range);
minAngle99Range.max = maxAngle99Range.value;
randomizeRange(minAngle99Range);
randomizeRange(bandThickness99Range);
randomizeRange(bandSpacing99Range);
let dir = Math.floor(Math.random() * 3);
bandDirection99Radio1.checked = dir === 0;
bandDirection99Radio2.checked = dir === 1;
bandDirection99Radio3.checked = dir === 2;
connectBands99Checkbox.checked = Math.random() >= 0.5;
if (!connectBands99Checkbox.checked) alignBands99Checkbox.checked = Math.random() >= 0.5;
else alignBands99Checkbox.checked = true;
updateSettings99();
}
function loadPreset99(n) {
if (n === 1) {
numBands99Range.value = numBands99RangeArray.indexOf(30);
hue99Range.value = 60;
rainbow99Checkbox.checked = false;
contrast99Range.value = 75;
maxAngle99Range.value = minAngle99Range.max = 360;
minAngle99Range.value = 0;
bandThickness99Range.value = 5;
bandSpacing99Range.value = 15;
bandDirection99Radio1.checked = false;
bandDirection99Radio2.checked = false;
bandDirection99Radio3.checked = true;
alignBands99Checkbox.checked = true;
connectBands99Checkbox.checked = true;
}
else if (n === 2) {
numBands99Range.value = numBands99RangeArray.indexOf(50);
hue99Range.value = 300;
rainbow99Checkbox.checked = true;
contrast99Range.value = 0;
maxAngle99Range.value = minAngle99Range.max = 360;
minAngle99Range.value = 90;
bandThickness99Range.value = 10;
bandSpacing99Range.value = 15;
bandDirection99Radio1.checked = true;
bandDirection99Radio2.checked = false;
bandDirection99Radio3.checked = false;
alignBands99Checkbox.checked = false;
connectBands99Checkbox.checked = false;
}
else if (n === 3) {
numBands99Range.value = numBands99RangeArray.indexOf(50);
hue99Range.value = 0;
rainbow99Checkbox.checked = false;
contrast99Range.value = 100;
maxAngle99Range.value = minAngle99Range.max = 280;
minAngle99Range.value = 235;
bandThickness99Range.value = 5;
bandSpacing99Range.value = 9;
bandDirection99Radio1.checked = false;
bandDirection99Radio2.checked = false;
bandDirection99Radio3.checked = true;
alignBands99Checkbox.checked = true;
connectBands99Checkbox.checked = false;
}
else if (n === 4) {
numBands99Range.value = numBands99RangeArray.indexOf(7);
hue99Range.value = 240;
rainbow99Checkbox.checked = false;
contrast99Range.value = 100;
maxAngle99Range.value = minAngle99Range.max = 270;
minAngle99Range.value = 90;
bandThickness99Range.value = 25;
bandSpacing99Range.value = 50;
bandDirection99Radio1.checked = true;
bandDirection99Radio2.checked = false;
bandDirection99Radio3.checked = false;
alignBands99Checkbox.checked = false;
connectBands99Checkbox.checked = false;
}
else if (n === 5) {
numBands99Range.value = numBands99RangeArray.indexOf(150);
hue99Range.value = 20;
rainbow99Checkbox.checked = false;
contrast99Range.value = 100;
maxAngle99Range.value = minAngle99Range.max = 360;
minAngle99Range.value = 0;
bandThickness99Range.value = 8;
bandSpacing99Range.value = 5;
bandDirection99Radio1.checked = false;
bandDirection99Radio2.checked = false;
bandDirection99Radio3.checked = true;
alignBands99Checkbox.checked = true;
connectBands99Checkbox.checked = true;
}
else if (n === 6) {
numBands99Range.value = numBands99RangeArray.indexOf(200);
hue99Range.value = 100;
rainbow99Checkbox.checked = true;
contrast99Range.value = 75;
maxAngle99Range.value = minAngle99Range.max = 25;
minAngle99Range.value = 0;
bandThickness99Range.value = 10;
bandSpacing99Range.value = 5;
bandDirection99Radio1.checked = false;
bandDirection99Radio2.checked = false;
bandDirection99Radio3.checked = true;
alignBands99Checkbox.checked = true;
connectBands99Checkbox.checked = true;
}
else if (n === 7) {
numBands99Range.value = numBands99RangeArray.indexOf(25);
hue99Range.value = 0;
rainbow99Checkbox.checked = true;
contrast99Range.value = 50;
maxAngle99Range.value = minAngle99Range.max = 240;
minAngle99Range.value = 120;
bandThickness99Range.value = 3;
bandSpacing99Range.value = 20;
bandDirection99Radio1.checked = false;
bandDirection99Radio2.checked = false;
bandDirection99Radio3.checked = true;
alignBands99Checkbox.checked = true;
connectBands99Checkbox.checked = false;
}
else if (n === 8) {
numBands99Range.value = numBands99RangeArray.indexOf(35);
hue99Range.value = 30;
rainbow99Checkbox.checked = true;
contrast99Range.value = 75;
maxAngle99Range.value = minAngle99Range.max = 180;
minAngle99Range.value = 90;
bandThickness99Range.value = 25;
bandSpacing99Range.value = 20;
bandDirection99Radio1.checked = false;
bandDirection99Radio2.checked = false;
bandDirection99Radio3.checked = true;
alignBands99Checkbox.checked = true;
connectBands99Checkbox.checked = true;
}
updateSettings99();
}
let numBands99RangeArray = [2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 150, 200];
function updateSettings99() {
numBands99 = numBands99Txt.innerHTML = numBands99RangeArray[Number(numBands99Range.value)];
hue99 = hue99Txt.innerHTML = Number(hue99Range.value);
rainbow99 = rainbow99Checkbox.checked;
contrast99 = contrast99Txt.innerHTML = Number(contrast99Range.value);
maxAngle99 = maxAngle99Txt.innerHTML = Number(maxAngle99Range.value);
minAngle99Range.max = maxAngle99;
minAngle99 = minAngle99Txt.innerHTML = Number(minAngle99Range.value);
bandThickness99 = bandThickness99Txt.innerHTML = Number(bandThickness99Range.value);
bandSpacing99 = bandSpacing99Txt.innerHTML = Number(bandSpacing99Range.value);
randomizeDirection99 = false;
alternateDirection99 = false;
if (bandDirection99Radio1.checked) randomizeDirection99 = true;
else if (bandDirection99Radio3.checked) alternateDirection99 = true;
alignBands99 = alignBands99Checkbox.checked;
connectBands99 = connectBands99Checkbox.checked;
drawBands99();
}
</script>
<canvas id = "canvas98" style = "background-color: black"></canvas>
<button onclick = "startCanvas98()">Start/Stop</button>
<button onclick = "if (!canvas98Running) frame98()">Step</button>
<div><b><u>Random Mode:</u></b> [ <span id = "randMode98Txt">random</span> ]</div>
<input type = "range" min = "1" max = "15" value = "1" step = "1" id = "randMode98Range" style = "width: 250px" oninput = "updateSettings98()">
<div><b><u>Average of 1,000 random values:</u></b> <span id = "rand98AverageTxt"></span></div>
<div class = "desc"><b><i>(10/13/2021)</i></b> Experimenting with how different random functions can have different results.<br><b><i>(10/14/2021)</i></b> Added more functions and average of 1,000 random values text.</div>
<hr><hr>
<script>
const ctx98 = canvas98.getContext("2d");
canvas98.width = canvas98.height = 1000;
let canvas98Running = false;
let randMode98 = 1;
function rand98() {
if (randMode98 === 1) return Math.random();
else if (randMode98 === 2) return (Math.random() + Math.random()) / 2;
else if (randMode98 === 3) return (Math.random() + Math.random() + Math.random()) / 3;
else if (randMode98 === 4) return (Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random()) / 10;
else if (randMode98 === 5) return 1 / (Math.random() + 1);
else if (randMode98 === 6) return Math.random() ** Math.random();
else if (randMode98 === 7) return Math.random() ** (1 / Math.random());
else if (randMode98 === 8) return Math.random() ** 2;
else if (randMode98 === 9) return Math.random() ** 3;
else if (randMode98 === 10) return Math.random() ** 10;
else if (randMode98 === 11) return Math.sqrt(Math.random());
else if (randMode98 === 12) return Math.cbrt(Math.random());
else if (randMode98 === 13) return Math.random() ** 0.1;
else if (randMode98 === 14) return Math.random() % Math.random();
else if (randMode98 === 15) return Math.random().toMultipleOf(0.05);
}
let lastRandAverageTime = Date.now();
function updateRand98AverageTxt() {
let sum = 0;
for (let i = 0; i < 1000; i++) sum += rand98();
rand98AverageTxt.innerHTML = (sum / 1000).toFixed(16);
lastRandAverageTime = Date.now();
}
function frame98() {
ctx98.clearRect(0, 0, canvas98.width, canvas98.height);
if (Date.now() - lastRandAverageTime >= 1000 || !canvas98Running) updateRand98AverageTxt();
for (let i = 0; i < 300; i++) {
ctx98.fillStyle = `hsl(${rand98() * 360}deg, 100%, 50%)`;
ctx98.fillCircle(rand98() * canvas98.width, rand98() * canvas98.height, (rand98() * 20) + 5);
}
if (canvas98Running) requestAnimationFrame(frame98);
}
updateRand98AverageTxt();
frame98();
let randMode98TxtArray = ["random", "(2 randoms) / 2", "(3 randoms) / 3", "(10 randoms) / 10", "1 / (random + 1)", "random ^ random", "random ^ (1 / random)", "random ^ 2", "random ^ 3", "random ^ 10", "square root of random", "cube root of random", "10th root of random", "random mod random", "random rounded to multiple of 0.05"];
function updateSettings98() {
randMode98 = Number(randMode98Range.value);
randMode98Txt.innerHTML = randMode98TxtArray[Number(randMode98Range.value) - 1];
updateRand98AverageTxt();
if (!canvas98Running) frame98();
}
function startCanvas98() {
if (canvas98Running) canvas98Running = false;
else {
canvas98Running = true;
frame98();
}
}
</script>
<canvas id = "canvas97" style = "background-color: black"></canvas>
<button onclick = "startCanvas97()">Start/Stop</button>
<button onclick = "reset97()">Reset</button>
<div><b><u>Turbo:</u></b></div>
<input type = "checkbox" id = "turbo97Checkbox" oninput = "updateSettings97()">
<div><b><u>Hue:</u></b> <span id = "hue97Txt">120</span>°</div>
<input type = "range" min = "0" max = "360" value = "120" step = "15" id = "hue97Range" oninput = "updateSettings97()">
<div><b><u>Line Width:</u></b> <span id = "lineWidth97Txt">3</span>px</div>
<input type = "range" min = "1" max = "5" value = "3" step = "1" id = "lineWidth97Range" oninput = "updateSettings97()">
<div><b><u>Jitter:</u></b> <span id = "jitter97Txt">10</span>px</div>
<input type = "range" min = "0" max = "25" value = "10" step = "1" id = "jitter97Range" oninput = "updateSettings97()">
<div><b><u>Rainbow:</u></b></div>
<input type = "checkbox" id = "rainbow97Checkbox" oninput = "grayscale97Checkbox.checked = false; updateSettings97()">
<div><b><u>Grayscale:</u></b></div>
<input type = "checkbox" id = "grayscale97Checkbox" oninput = "rainbow97Checkbox.checked = false; updateSettings97()">
<div class = "desc"><b><i>(10/11/2021)</i></b> Not really sure what this is, I was originally just going to make some art thing where when you click it makes a random spiral with random shape and color, but then I discovered this, and I kinda like it. It's just a spiral with random turn speed and grow speed, but also a random jitter property that randomizes where it draws to each frame by a set amount of pixels. I also some settings and sliders. At some point I might fully flesh this out into a background generator, but for now it'll stay how it is.</div>
<hr><hr>
<script>
const ctx97 = canvas97.getContext("2d");
canvas97.width = canvas97.height = 1000;
let canvas97Running = false;
let canvas97Rect = canvas97.getBoundingClientRect();
let canvas97Ratio = canvas97.width / 300;
let spiral97StepsPerFrame = 100;
let hue97 = 120;
let rainbow97 = false;
let grayscale97 = false;
let lineWidth97 = 3;
let jitter97 = 10;
let running97 = true;
function Spiral97(x, y) {
running97 = true;
this.centerX = x;
this.centerY = y;
this.x = this.centerX;
this.y = this.centerY;
this.lastX = this.x;
this.lastY = this.y;
this.angle = 0;
this.radius = 0;
this.turnSpeed = randBetween(0.5, 2);
this.growSpeed = randBetween(0.02, 0.07);
}
Spiral97.prototype.render = function() {
if (this.radius >= (canvas97.width * 0.5 * Math.SQRT2) + 25) {
running97 = false;
return;
}
for (let i = 0; i < spiral97StepsPerFrame; i++) {
this.lastX = this.x;
this.lastY = this.y;
this.angle += Math.random() * this.turnSpeed;
this.radius += Math.random() * this.growSpeed;
let r = Math.random() * jitter97;
let cx = this.centerX + randBetween(-r, r);
let cy = this.centerY + randBetween(-r, r);
this.x = cx + (this.radius * Math.cos(toRad(this.angle)));
this.y = cy + (this.radius * Math.sin(toRad(this.angle)));
ctx97.lineJoin = ctx97.lineCap = "round";
ctx97.lineWidth = lineWidth97;
ctx97.strokeStyle = rainbow97 ? `hsl(${Math.random() * 360}deg, 100%, 50%)` : `hsl(${hue97}deg, ${grayscale97 ? 0 : 100}%, ${Math.random() * 100}%)`;
ctx97.beginPath();
ctx97.moveTo(this.lastX, this.lastY);
ctx97.lineTo(this.x, this.y);
ctx97.stroke();
}
};
let spiral97Array = [];
spiral97Array.push(new Spiral97(canvas97.width / 2, canvas97.height / 2));
function frame97() {
//ctx97.clearRect(0, 0, canvas97.width, canvas97.height);
for (let i = 0; i < spiral97Array.length; i++) spiral97Array[i].render();
if (canvas97Running) requestAnimationFrame(frame97);
}
frame97();
function updateSettings97() {
spiral97StepsPerFrame = turbo97Checkbox.checked ? 500 : 100;
hue97 = hue97Txt.innerHTML = Number(hue97Range.value);
lineWidth97 = lineWidth97Txt.innerHTML = Number(lineWidth97Range.value);
rainbow97 = rainbow97Checkbox.checked;
grayscale97 = grayscale97Checkbox.checked;
jitter97 = jitter97Txt.innerHTML = Number(jitter97Range.value);
if (!running97) reset97();
}
function reset97() {
running97 = true;
ctx97.clearRect(0, 0, canvas97.width, canvas97.height);
spiral97Array = [];
spiral97Array.push(new Spiral97(canvas97.width / 2, canvas97.height / 2));
}
function startCanvas97() {
if (canvas97Running) canvas97Running = false;
else {
canvas97Running = true;
frame97();
}
}
</script>
<canvas id = "canvas96" style = "width: 384px; height: 317px; border: none; background-image: url('https://e4494s.neocities.org/images/etch-a-sketch.png'); background-size: 100% 100%"></canvas>
<button onclick = "startCanvas96()">Start/Stop</button>
<div class = "desc"><b><i>(10/10/2021)</i></b> An attempt to make a digital Etch-a-Sketch, but I didn't get the knobs working. I'll probably fix it at some point.<br><b><i>(10/11/2021)</i></b> Got everything working right! Now the movement is calculated based on the sign of the last angle and the current angle from the mouse cursor to the knob you're dragging.</div>
<hr><hr>
<script>
const ctx96 = canvas96.getContext("2d");
canvas96.width = 384 * 2;
canvas96.height = 317 * 2;
let canvas96Running = false;
let canvas96Rect = canvas96.getBoundingClientRect();
let canvas96Ratio = 2;
let Mouse96 = {
down: false,
x: 0,
y: 0,
angleOnClick: 0,
draggingKnob: ""
};
let LeftKnob96 = {
x: 58,
y: 576,
radius: 46
};
let RightKnob96 = {
x: 712,
y: 578,
radius: 46
};
let Pen96 = {
x: canvas96.width / 2,
y: 306,
lastX: canvas96.width / 2,
lastY: 306,
radius: 0.5,
minX: 102,
maxX: 656,
minY: 99,
maxY: 502
};
Pen96.move = function(x, y) {
if (this.x + x > this.maxX || this.x + x < this.minX || this.y + y > this.maxY || this.y + y < this.minY) return;
this.lastX = this.x;
this.lastY = this.y;
this.x += x;
this.y += y;
this.draw();
};
Pen96.draw = function() {
ctx96.beginPath();
ctx96.moveTo(this.lastX, this.lastY);
ctx96.lineTo(this.x, this.y);
ctx96.stroke();
ctx96.stroke();
};
function frame96() {
if (canvas96Running) requestAnimationFrame(frame96);
}
frame96();
function startCanvas96() {
if (canvas96Running) canvas96Running = false;
else {
canvas96Running = true;
frame96();
}
}
canvas96.addEventListener("mousedown", e => {
if (!canvas96Running) return;
e.preventDefault();
Mouse96.down = true;
canvas96Rect = canvas96.getBoundingClientRect();
Mouse96.x = (e.clientX - canvas96Rect.left) * canvas96Ratio;
Mouse96.y = (e.clientY - canvas96Rect.top) * canvas96Ratio;
let dx = LeftKnob96.x - Mouse96.x;
let dy = LeftKnob96.y - Mouse96.y;
let distSq = (dx * dx) + (dy * dy);
if (distSq <= LeftKnob96.radius * LeftKnob96.radius) {
Mouse96.draggingKnob = "left";
Mouse96.angleOnClick = Math.atan2(dy, dx);
return;
}
dx = RightKnob96.x - Mouse96.x;
dy = RightKnob96.y - Mouse96.y;
distSq = (dx * dx) + (dy * dy);
if (distSq <= RightKnob96.radius * RightKnob96.radius) {
Mouse96.draggingKnob = "right";
Mouse96.angleOnClick = Math.atan2(dy, dx);
}
});
canvas96.addEventListener("mousemove", e => {
if (!canvas96Running || !Mouse96.down) return;
e.preventDefault();
canvas96Rect = canvas96.getBoundingClientRect();
Mouse96.x = (e.clientX - canvas96Rect.left) * canvas96Ratio;
Mouse96.y = (e.clientY - canvas96Rect.top) * canvas96Ratio;
if (Mouse96.draggingKnob === "left") {
let dx = LeftKnob96.x - Mouse96.x;
let dy = LeftKnob96.y - Mouse96.y;
let angle = Math.atan2(dy, dx);
let diff = angle - Mouse96.angleOnClick;
Pen96.move(Math.sign(diff), 0);
Mouse96.angleOnClick = angle;
return;
}
else if (Mouse96.draggingKnob === "right") {
let dx = RightKnob96.x - Mouse96.x;
let dy = RightKnob96.y - Mouse96.y;
let angle = Math.atan2(dy, dx);
let diff = angle - Mouse96.angleOnClick;
Pen96.move(0, -Math.sign(diff));
Mouse96.angleOnClick = angle;
return;
}
});
window.addEventListener("mouseup", e => {
Mouse96.down = false;
Mouse96.draggingKnob = "";
});
</script>
<canvas id = "canvas95" style = "background-color: black; width: 400px; height: 400px"></canvas>
<button onclick = "startCanvas95()">Start/Stop</button>
<div><b><u>Connect Dots:</u></b></div>
<input type = "checkbox" id = "chain95ConnectPointsCheckbox" oninput = "updateSettings95(false)">
<div><b><u>Number of Dots:</u></b> <span id = "chain95NumPointsTxt">20</span></div>
<input type = "range" min = "5" max = "50" value = "20" step = "5" id = "chain95NumPointsRange" oninput = "updateSettings95(true)">
<div><b><u>Dot Size:</u></b> <span id = "chain95PointRadiusTxt">15</span></div>
<input type = "range" min = "5" max = "25" value = "15" step = "5" id = "chain95PointRadiusRange" oninput = "updateSettings95(false)">
<div><b><u>Dot Spacing:</u></b> <span id = "chain95TouchRatioTxt">100</span>%</div>
<input type = "range" min = "0" max = "12" value = "9" step = "1" id = "chain95TouchRatioRange" oninput = "updateSettings95(false)">
<div><b><u>Dot Speed:</u></b> <span id = "chain95DistRatioTxt">20</span>%</div>
<input type = "range" min = "0" max = "8" value = "4" step = "1" id = "chain95DistRatioRange" oninput = "updateSettings95(false)">
<div class = "desc"><b><i>(10/9/2021)</i></b> Trailing dots behind the cursor, implemented from the idea on <a href = "https://fahad-haidari.medium.com/build-a-simple-circle-based-physics-simulation-with-pi2-js-edd6d7ce857f?p=711cf788bb">https://fahad-haidari.medium.com/build-a-simple-circle-based-physics-simulation-with-pi2-js-edd6d7ce857f?p=711cf788bb</a>. Each dot follows the one before it when you click and drag.<br><b><i>(10/10/2021)</i></b> Added sliders for all the settings.</div>
<hr><hr>
<script>
const ctx95 = canvas95.getContext("2d");
canvas95.width = canvas95.height = 1000;
let canvas95Running = false;
let canvas95Rect = canvas95.getBoundingClientRect();
let canvas95Ratio = canvas95.width / 400;
let Mouse95 = {
down: false,
x: 0,
y: 0
};
let Chain95 = {
points: [],
pointRadius: 15,
distRatio: 0.2,
touchRatio: 1,
connectPoints: false,
numPoints: 20
};
Chain95.render = function() {
for (let i = 0; i < this.points.length; i++) {
if (i !== this.points.length - 1) {
let dx = this.points[i + 1].x - this.points[i].x;
let dy = this.points[i + 1].y - this.points[i].y;
let distSq = (dx * dx) + (dy * dy);
let radSq = this.pointRadius * this.pointRadius * 4 * this.touchRatio * this.touchRatio;
if (distSq >= radSq) {
let dist = Math.sqrt(distSq);
let vel = dist * this.distRatio;
dx /= dist;
dy /= dist;
this.points[i].x += dx * vel;
this.points[i].y += dy * vel;
}
}
}
ctx95.lineCap = ctx95.lineJoin = "round";
ctx95.lineWidth = this.pointRadius * 2;
for (let i = 0; i < this.points.length; i++) {
if (this.connectPoints) {
ctx95.strokeStyle = this.points[i].color;
ctx95.beginPath();
ctx95.moveTo(this.points[i].x, this.points[i].y);
if (i !== this.points.length - 1) ctx95.lineTo(this.points[i + 1].x, this.points[i + 1].y);
ctx95.stroke();
}
else {
ctx95.fillStyle = this.points[i].color;
ctx95.fillCircle(this.points[i].x, this.points[i].y, this.pointRadius);
}
}
};
Chain95.resetPoints = function() {
this.points = [];
for (let i = 0; i < this.numPoints; i++) this.points.push({x: canvas95.width / 2, y: canvas95.height / 2, color: `hsl(${360 - ((i / (this.numPoints - 1)) * 360)}deg, 100%, 50%)`});
if (!canvas95Running) frame95();
};
Chain95.resetPoints();
function frame95() {
ctx95.clearRect(0, 0, canvas95.width, canvas95.height);
if (Mouse95.down) {
Chain95.points[Chain95.points.length - 1].x = Mouse95.x;
Chain95.points[Chain95.points.length - 1].y = Mouse95.y;
}
Chain95.render();
if (canvas95Running) requestAnimationFrame(frame95);
}
function startCanvas95() {
if (canvas95Running) canvas95Running = false;
else {
canvas95Running = true;
frame95();
}
}
let chain95TouchRatioRangeArray = [1, 3, 5, 10, 15, 25, 50, 75, 100, 150, 200, 250, 300];
let chain95DistRatioRangeArray = [1, 5, 10, 15, 20, 25, 30, 40, 50];
function updateSettings95(resetPoints) {
Chain95.connectPoints = chain95ConnectPointsCheckbox.checked;
Chain95.numPoints = chain95NumPointsTxt.innerHTML = Number(chain95NumPointsRange.value);
Chain95.pointRadius = chain95PointRadiusTxt.innerHTML = Number(chain95PointRadiusRange.value);
Chain95.touchRatio = chain95TouchRatioRangeArray[Number(chain95TouchRatioRange.value)] / 100;
chain95TouchRatioTxt.innerHTML = chain95TouchRatioRangeArray[Number(chain95TouchRatioRange.value)];
Chain95.distRatio = chain95DistRatioRangeArray[Number(chain95DistRatioRange.value)] / 100;
chain95DistRatioTxt.innerHTML = chain95DistRatioRangeArray[Number(chain95DistRatioRange.value)];
if (resetPoints) Chain95.resetPoints();
}
canvas95.addEventListener("mousedown", e => {
if (!canvas95Running) return;
e.preventDefault();
Mouse95.down = true;
canvas95Rect = canvas95.getBoundingClientRect();
Mouse95.x = (e.clientX - canvas95Rect.left) * canvas95Ratio;
Mouse95.y = (e.clientY - canvas95Rect.top) * canvas95Ratio;
});
canvas95.addEventListener("mousemove", e => {
if (!canvas95Running || !Mouse95.down) return;
e.preventDefault();
canvas95Rect = canvas95.getBoundingClientRect();
Mouse95.x = (e.clientX - canvas95Rect.left) * canvas95Ratio;
Mouse95.y = (e.clientY - canvas95Rect.top) * canvas95Ratio;
});
window.addEventListener("mouseup", e => {
Mouse95.down = false;
});
</script>
<canvas id = "canvas94" style = "width: 400px; height: 400px"></canvas>
<button onclick = "startCanvas94()">Start/Stop</button>
<div class = "desc"><b><i>(10/8/2021)</i></b> Rollercoaster generator using Bezier curves. At some point I want this to have a little rollercoaster cart rolling along it using the tangent and normal directions at a current point, and have it infinitely scroll along, generating new coaster tracks, and driving along it. I also want to fix the spacing of the supports so that they're more regular and not bunched up.</div>
<hr><hr>
<script>
const ctx94 = canvas94.getContext("2d");
canvas94.width = canvas94.height = 1000;
let canvas94Running = false;
function Track94(x, y, span, minHeight, maxHeight) {
this.startPoint = {x: x, y: y};
this.span = span;
this.minHeight = minHeight;
this.maxHeight = maxHeight;
this.endPoint = {x: this.startPoint.x + this.span, y: this.startPoint.y};
this.controlPoint1 = {x: randBetween(this.startPoint.x, this.startPoint.x + this.span), y: randBetween(this.startPoint.y - this.maxHeight, this.startPoint.y - this.minHeight)};
this.controlPoint2 = {x: randBetween(this.startPoint.x, this.startPoint.x + this.span), y: randBetween(this.startPoint.y - this.maxHeight, this.startPoint.y - this.minHeight)};
}
Track94.prototype.lerp = function(p1, p2, t) {
return {x: ((1 - t) * p1.x) + (t * p2.x), y: ((1 - t) * p1.y) + (t * p2.y)};
};
Track94.prototype.draw = function() {
ctx94.lineWidth = 3;
ctx94.lineCap = ctx94.lineJoin = "round";
for (let i = 0; i <= 100; i += 5) {
let A = this.lerp(this.startPoint, this.controlPoint1, i / 100);
let B = this.lerp(this.controlPoint1, this.controlPoint2, i / 100);
let C = this.lerp(this.controlPoint2, this.endPoint, i / 100);
let D = this.lerp(A, B, i / 100);
let E = this.lerp(B, C, i / 100);
let F = this.lerp(D, E, i / 100);
ctx94.moveTo(F.x, F.y);
ctx94.lineTo(F.x, this.startPoint.y);
ctx94.stroke();
}
ctx94.lineWidth = 12;
ctx94.beginPath();
ctx94.moveTo(this.startPoint.x, this.startPoint.y);
ctx94.bezierCurveTo(this.controlPoint1.x, this.controlPoint1.y, this.controlPoint2.x, this.controlPoint2.y, this.endPoint.x, this.endPoint.y);
ctx94.stroke();
}
let track94Array = [];
track94Array.push(new Track94(200, 800, 400, 100, 500));
track94Array.push(new Track94(600, 800, 400, 100, 500));
function frame94() {
ctx94.clearRect(0, 0, canvas94.width, canvas94.height);
for (let i = 0; i < track94Array.length; i++) track94Array[i].draw();
ctx94.fillRect(0, 800, 1000, 200);
if (canvas94Running) requestAnimationFrame(frame94);
}
frame94();
function startCanvas94() {
if (canvas94Running) canvas94Running = false;
else {
canvas94Running = true;
frame94();
}
}
</script>
<canvas id = "canvas93" style = "background-color: black; width: 500px; height: 500px"></canvas>
<button onclick = "startCanvas93()">Start/Stop</button>
<div class = "desc"><b><i>(10/7/2021)</i></b> Space Golf! I want to have different levels with different planets and obstacles, where you try to get your golf ball into a black hole.</div>
<hr><hr>
<script>
const ctx93 = canvas93.getContext("2d");
canvas93.width = canvas93.height = 1000;
let canvas93Running = false;
let canvas93Rect = canvas93.getBoundingClientRect();
let canvas93Ratio = canvas93.width / 500;
let Mouse93 = {
x: 0,
y: 0,
power: 0.05,
lineScale: 5
};
let gravity93 = 10;
let GolfBall93 = {
x: canvas93.width / 2,
y: canvas93.height - 100,
radius: 10,
vx: 0,
vy: 0,
moving: false,
launchVelocity: 0,
launchAngle: 0,
mass: 10,
ricochet: false
};
GolfBall93.update = function() {
if (!this.moving) {
if (this.ricochet) this.launch();
else return;
}
this.x += this.vx;
this.y += this.vy;
for (let i = 0; i < planet93Array.length; i++) {
let dx = planet93Array[i].x - this.x;
let dy = planet93Array[i].y - this.y;
let distSq = (dx * dx) + (dy * dy);
let r = planet93Array[i].radius + this.radius;
let angle = Math.atan2(dy, dx);
if (distSq <= r * r) {
this.x = planet93Array[i].x + (r * Math.cos(angle + Math.PI));
this.y = planet93Array[i].y + (r * Math.sin(angle + Math.PI));
this.stopMoving();
return;
}
let force = (this.mass * gravity93 * planet93Array[i].mass) / distSq;
this.vx += force * Math.cos(angle);
this.vy += force * Math.sin(angle);
}
let left = this.radius;
let right = canvas93.width - this.radius;
let top = this.radius;
let bottom = canvas93.width - this.radius;
if (this.x < left) {
this.x = left;
this.vx = this.vy = 0;
return;
}
if (this.x > right) {
this.x = right;
this.vx = this.vy = 0;
return;
}
if (this.y < top) {
this.y = top;
this.vx = this.vy = 0;
return;
}
if (this.y > bottom) {
this.y = bottom;
this.vx = this.vy = 0;
return;
}
};
GolfBall93.stopMoving = function() {
this.moving = false;
this.vx = this.vy = 0;
let dx = Mouse93.x - this.x;
let dy = Mouse93.y - this.y;
this.launchAngle = Math.atan2(dy, dx);
this.launchVelocity = Math.sqrt((dx * dx) + (dy * dy)) * Mouse93.power;
};
GolfBall93.draw = function() {
if (!this.moving) {
ctx93.strokeStyle = "yellow";
ctx93.lineWidth = 5;
ctx93.beginPath();
ctx93.moveTo(this.x, this.y);
ctx93.lineTo(this.x + (this.launchVelocity * Mouse93.lineScale * Math.cos(this.launchAngle)), this.y + (this.launchVelocity * Mouse93.lineScale * Math.sin(this.launchAngle)));
ctx93.stroke();
}
ctx93.fillStyle = "white";
ctx93.fillCircle(this.x, this.y, this.radius);
};
GolfBall93.launch = function() {
this.moving = true;
this.vx = this.launchVelocity * Math.cos(this.launchAngle);
this.vy = this.launchVelocity * Math.sin(this.launchAngle);
};
function Planet93(x, y, radius, mass, color) {