-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestbed2-backup.html
More file actions
11646 lines (10181 loc) · 413 KB
/
testbed2-backup.html
File metadata and controls
11646 lines (10181 loc) · 413 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 2 ~ 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 Second Island of Misfit Code</h1>
<div style = "font-size: 16px; background-color: rgb(255, 150, 150); padding: 8px; margin-top: 25px; margin-bottom: 25px; border-radius: 10px"><b><i>Moved to from <a href = "https://e4494s.neocities.org/testbed.html" target = "_blank">testbed.html</a> on 10/17/2021.</i></b></div>
<!--
<canvas id = "canvas0"></canvas>
<button onclick = "startCanvas0()">Start/Stop</button>
<div class = "desc"></div>
<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>Click and drag to zoom. Make sure the animation is running by toggling the <b><i>Paused</i></b> button. The render gets more accurate every swipe.</div>
<canvas id = "canvas78"></canvas>
<button onclick = "startCanvas78(this)" style = "color: red; border-color: red"><b><i>Paused</i></b></button>
<div style = "color: dimgray; margin: 5px; font-size: 11px"><i><b>[ FPS: <span id = "fps78Txt"></span> ]</b></i></div>
<br><br>
<button onclick = "multScale78(0.5)">Zoom In</button>
<button onclick = "multScale78(2)">Zoom Out</button>
<br><br>
<input type = "checkbox" id = "intenseColoring78Checkbox" oninput = "updateSettings78()" CHECKED>
<label for = "intenseColoring78Checkbox">Intensified Coloring (may get whitewashed at deeper zooms)</label>
<br><br>
<div><b><u>Fractal Hue:</u></b> <span id = "hue78Txt">300</span>°</div>
<input type = "range" min = "0" max = "360" step = "30" value = "300" id = "hue78Range" oninput = "updateSettings78()">
<br><br>
<b>Fractal:</b>
<button onclick = "setFractalMode78(1)" id = "fractalMode78Btn1" class = "fractalMode78Btns" style = "background-color: gray">Mandelbrot</button>
<button onclick = "setFractalMode78(2)" id = "fractalMode78Btn2" class = "fractalMode78Btns">Mindlebrit</button>
<button onclick = "setFractalMode78(3)" id = "fractalMode78Btn3" class = "fractalMode78Btns">Cosine Fractal</button>
<button onclick = "setFractalMode78(4)" id = "fractalMode78Btn4" class = "fractalMode78Btns">Two-Cosine Fractal</button>
<p>
The <b>Mindlebrit Fractal</b> is a fractal that is generated the exact same as the Mandelbrot--except z_0 = i, instead of 0.
<br><br>
The <b>Cosine Fractal</b> is generated similar to the Mandelbrot, except instead of squaring z_n and adding c every iteration, you take the cosine of z_n and add c (and color based on escape iterations similarly).
<br><br>
The <b>Two-Cosine Fractal</b> is the same as the Cosine Fractal, but with 2 times cosine each step.
</p>
<div class = "desc"><b><i>(3/30/2022)</i></b> I tried making a faster Mandelbrot set visualizer than the <a href = "https://e4494s.neocities.org/mandelbrot.html">old one</a> I had, but it's not much faster. I did add dragging and zooming though, which was really difficult to get working properly. It still loses a lot of detail at higher zoom levels, but I'm not sure how to fix that without waiting like 30 seconds for it to render. I also made it where the escape iterations for each point also affect the hue, not just the brightness, which creates a really interesting effect.<br><b><i>(3/31/2022)</i></b> Added buttons for different fractal modes.<br><b><i>(3/31/2022)</i></b> I significantly improved runtime and performance by adding an update frame function instead of just rendering the fractal all at once, one time. It instead now passes down the screen, rendering as it goes. Each time it reaches the bottom of the screen, it does another pass with higher iterations. (Deeper zooms will take longer to render as they have a higher iteration escape period).<br><b><i>Update: (Later that day)</i></b> I made the rendering passes happen twice at once, moving from the center of the screen, and also added a setting to intensify the coloring, which means the intensity is multiplied based on the maximum iterations (as the higher the max iterations are, the less intense the colors typically are). I added it as an optional setting since sometimes it looks whitewashed with intense colors on.</div>
<hr><hr>
<script>
const ctx78 = canvas78.getContext("2d");
canvas78.width = canvas78.height = 500;
let canvas78Running = false;
let canvas78Rect = canvas78.getBoundingClientRect();
let canvas78Ratio = canvas78.width / 300;
const Complex78 = {};
Complex78.number = function(a, b) { // a + bi
this.re = a;
this.im = b;
};
Complex78.string = function(z) {
return `${z.re} ${Math.sign(z.im) === -1 ? "-" : "+"} ${Math.abs(z.im)}i`;
};
Complex78.iSquared = new Complex78.number(-1, 0); // i^2 = -1
Complex78.add = function(x, y) {
if (typeof x === "number") x = new Complex78.number(x, 0);
if (typeof y === "number") y = new Complex78.number(y, 0);
return new Complex78.number(x.re + y.re, x.im + y.im);
};
Complex78.subtract = function(x, y) {
if (typeof x === "number") x = new Complex78.number(x, 0);
if (typeof y === "number") y = new Complex78.number(y, 0);
return new Complex78.number(x.re - y.re, x.im - y.im);
};
Complex78.multiply = function(x, y) {
if (typeof x === "number") x = new Complex78.number(x, 0);
if (typeof y === "number") y = new Complex78.number(y, 0);
let iSq = new Complex78.number(Complex78.iSquared.re * x.im * y.im, Complex78.iSquared.im * x.im * y.im);
let real = (x.re * y.re) + iSq.re;
let imaginary = (x.re * y.im) + (x.im * y.re) + iSq.im;
return new Complex78.number(real, imaginary);
};
Complex78.power = function(x, n) {
let result = new Complex78.number(1, 0);
for (let i = 0; i < n; i++) {
result = Complex78.multiply(result, x);
}
return result;
}
Complex78.inMandelbrot = function(c) {
let z = new Complex78.number(0, 0);
for (let i = 0; i < maxIterations78; i++) {
z = Complex78.add(Complex78.power(z, 2), c);
if (z.re * z.im > 5) return i / maxIterations78;
}
return 0;
};
function inMandelbrot78(re, im) {
let a = 0;
let b = fractalMode78 === 2 ? 1 : 0;
if ((a + a) * (b + b) > 4) return 1;
for (let i = 0; i < maxIterations78; i++) {
let _a = (a * a) - (b * b);
let _b = 2 * a * b;
a = _a + re;
b = _b + im;
if ((a * a) + (b * b) > 4) return i / maxIterations78;
}
return 0;
}
function inCosFractal78(re, im) { // z_n+1 = cos(z_n) + c
let a = re;
let b = im;
for (let i = 0; i < maxIterations78; i++) {
let eB = Math.exp(b); // e^b
let eNegB = 1 / eB; // e^-b
let c = Math.cos(a);
let s = Math.sin(a);
let _a = (c * (eB + eNegB)) / (fractalMode78 === 4 ? 1 : 2);
let _b = (s * (eNegB - eB)) / (fractalMode78 === 4 ? 1 : 2);
a = _a + re;
b = _b + im;
if (a * b > 5) return i / maxIterations78;
}
return 0;
}
let pan78X = -0.23;
let pan78Y = 0;
let hue78 = 300;
let scale78 = 2;
let fractalMode78 = 1;
let intenseColoring78 = true;
/*
1: Mandelbrot
2: Mandelbrot with z_0 = i
3: Cosine Fractal
4: Two-Cosine Fractal
*/
let scale78Array = [
2, // Mandelbrot
1, // Mindlebrit
4, // Cosine Fractal
1 // Two-Cosine Fractal
];
let pan78XArray = [
-0.23, // Mandelbrot
0, // Mindlebrit
0.39, // Cosine Fractal
-0.5 // Two-Cosine Fractal
];
let pan78YArray = [
0, // Mandelbrot
-0.5, // Mindlebrit
0, // Cosine Fractal
0 // Two-Cosine Fractal
];
function plotPoint78(x, y) {
let _x = x - (canvas78.width / 2);
let _y = y - (canvas78.height / 2);
_x /= canvas78.width;
_y /= canvas78.height;
_x += pan78X;
_y += pan78Y;
_x *= scale78;
_y *= scale78;
let escape = 0;
if (fractalMode78 === 1 || fractalMode78 === 2) escape = inMandelbrot78(_x, _y);
else if (fractalMode78 === 3 || fractalMode78 === 4) escape = inCosFractal78(_x, _y);
if (intenseColoring78) escape *= (maxIterations78 / iterationsPerPass78);
let brightness = escape * 100;
let hue = hue78 + (180 * escape);
ctx78.fillStyle = `hsl(${hue}deg, 100%, ${brightness}%)`;
ctx78.fillRect(x, y, 1, 1);
}
function plotFractal78() {
ctx78.fillStyle = "white";
ctx78.fillRect(0, 0, canvas78.width, canvas78.height);
for (let x = 0; x < canvas78.width; x++) {
for (let y = 0; y < canvas78.height; y++) {
plotPoint78(x, y);
}
}
}
//plotFractal78();
let currPixel78 = 0;
let numPasses78 = 0;
let maxIterations78 = 200;
let iterationsPerPass78 = 200;
let maxPasses78 = 5;
let stepsPerFrame78 = 4000;
let lastFrame78Time = 0;
let lastFps78DisplayTime = 1000;
function frame78() {
if (Date.now() - lastFps78DisplayTime >= 500) {
fps78Txt.innerHTML = (1000 / (Date.now() - lastFrame78Time)).toFixed(1);
lastFps78DisplayTime = Date.now();
}
lastFrame78Time = Date.now();
for (let i = 0; i < stepsPerFrame78; i++) {
if (numPasses78 < maxPasses78) {
let x = Math.floor(currPixel78 / 2) % canvas78.width;
let y = Math.floor(Math.floor(currPixel78 / 2) / canvas78.width);
if (currPixel78 % 2 === 0) {
y += canvas78.height / 2;
}
else {
y = (canvas78.height / 2) - y;
y--;
}
plotPoint78(x, y);
currPixel78++;
if (currPixel78 > canvas78.width * canvas78.height) {
currPixel78 = 0;
numPasses78++;
maxIterations78 = (numPasses78 + 1) * iterationsPerPass78;
}
}
}
if (canvas78Running) requestAnimationFrame(frame78);
}
function startCanvas78(caller) {
if (canvas78Running) {
canvas78Running = false;
caller.innerHTML = "<b><i>Paused</i></b>";
caller.style.color = caller.style.borderColor = "red";
}
else {
canvas78Running = true;
caller.innerHTML = "<b><i>Running</i></b>";
caller.style.color = caller.style.borderColor = "green";
frame78();
}
}
function resetDrawing78() {
ctx78.fillStyle = "black";
ctx78.fillRect(0, 0, canvas78.width, canvas78.height);
currPixel78 = 0;
numPasses78 = 0;
maxIterations78 = iterationsPerPass78;
}
function redrawLastPass78() {
currPixel78 = 0;
numPasses78--;
numPasses78 = Math.max(0, numPasses78);
maxIterations78 = (numPasses78 + 1) * iterationsPerPass78;
}
function updateSettings78() {
intenseColoring78 = intenseColoring78Checkbox.checked;
hue78 = hue78Txt.innerHTML = Number(hue78Range.value);
redrawLastPass78();
}
function resetFractal78() {
scale78 = scale78Array[fractalMode78 - 1];
pan78X = pan78XArray[fractalMode78 - 1];
pan78Y = pan78YArray[fractalMode78 - 1];
resetDrawing78();
}
//plotFractal78();
function multScale78(factor) {
scale78 *= factor;
pan78X /= factor;
pan78Y /= factor;
resetDrawing78();
}
function setFractalMode78(n) {
fractalMode78 = n;
let btns = document.getElementsByClassName("fractalMode78Btns");
for (let i = 0; i < btns.length; i++) btns[i].style.backgroundColor = "white";
document.getElementById("fractalMode78Btn" + n).style.backgroundColor = "gray";
resetFractal78();
}
function drawPanIcon78(x, y) {
return;
let size = 30;
let s3 = size / 3;
ctx78.fillStyle = "white";
ctx78.strokeStyle = "black";
ctx78.lineWidth = 2;
let cx = x - (s3 / 2);
let cy = y - (s3 * 1.5);
ctx78.beginPath();
ctx78.moveTo(cx, cy);
cx += s3;
ctx78.lineTo(cx, cy);
cy += s3;
ctx78.lineTo(cx, cy);
cx += s3;
ctx78.lineTo(cx, cy);
cy += s3;
ctx78.lineTo(cx, cy);
cx -= s3;
ctx78.lineTo(cx, cy);
cy += s3;
ctx78.lineTo(cx, cy);
cx -= s3;
ctx78.lineTo(cx, cy);
cy -= s3;
ctx78.lineTo(cx, cy);
cx -= s3;
ctx78.lineTo(cx, cy);
cy -= s3;
ctx78.lineTo(cx, cy);
cx += s3;
ctx78.lineTo(cx, cy);
cy -= s3;
ctx78.lineTo(cx, cy);
ctx78.fill();
ctx78.stroke();
}
let Mouse78 = {
down: false,
downX: 0,
downY: 0,
willRedraw: false
};
canvas78.addEventListener("mousedown", e => {
canvas78Rect = canvas78.getBoundingClientRect();
e.preventDefault();
Mouse78.down = true;
Mouse78.downX = (e.clientX - canvas78Rect.left) * canvas78Ratio;
Mouse78.downY = (e.clientY - canvas78Rect.top) * canvas78Ratio;
drawPanIcon78(Mouse78.downX, Mouse78.downY);
});
window.addEventListener("mouseup", e => {
Mouse78.down = false;
if (Mouse78.willRedraw) {
canvas78Rect = canvas78.getBoundingClientRect();
let mX = (e.clientX - canvas78Rect.left) * canvas78Ratio;
let mY = (e.clientY - canvas78Rect.top) * canvas78Ratio;
pan78X -= (mX - Mouse78.downX) / canvas78.width;
pan78Y -= (mY - Mouse78.downY) / canvas78.height;
resetDrawing78();
}
Mouse78.willRedraw = false;
});
window.addEventListener("mousemove", e => {
if (!Mouse78.down) return;
Mouse78.willRedraw = true;
e.preventDefault();
});
</script>
<!--Idea?: Triangle grid with random tile size, rounded to multiple of 0.25 so they connect better-->
<canvas id = "canvas77"></canvas>
<button onclick = "startCanvas77(this)" style = "color: red; border-color: red"><b><i>Paused</i></b></button>
<button onclick = "reset77()">Reset</button>
<div style = "color: dimgray; margin: 5px; font-size: 11px"><i><b>[ FPS: <span id = "fps77Txt"></span> ]</b></i></div>
<div class = "desc"><b><i>(3/10/2022)</i></b> I decided to go with an animated design with a triangle grid this time. Each triangle slowly fades in and out with size and brightness, but the offset it has increases the further it is from the center, which makes a really cool rippling or breaking away effect.</div>
<hr><hr>
<script>
const ctx77 = canvas77.getContext("2d");
canvas77.width = canvas77.height = 1000;
let canvas77Running = false;
const ratio77 = Math.sqrt(3) / 2;
let gridSize77 = 7;
let t77 = 0;
let period77 = 250;
let hue77 = 0;
let clearOpacity77 = 1;
let flatness77 = 1.7;
function smooth77(t) {
return Math.min((1 - Math.cos(t * Math.PI * 2)) / flatness77, 1);
}
function drawTriangle77(x, y, sideLength, flip) { // >: Normal <: flipped
let cx = x;
let cy = y;
let ca = -Math.PI / 2;
ctx77.lineWidth = 1;
ctx77.lineCap = ctx77.lineJoin = "round";
ctx77.beginPath();
ctx77.moveTo(cx, cy);
for (let i = 0; i < 3; i++) {
cx += sideLength * Math.cos(ca);
cy += sideLength * Math.sin(ca);
ca += ((2 * Math.PI) / 3) * (flip ? -1 : 1);
ctx77.lineTo(cx, cy);
}
ctx77.fill();
ctx77.stroke();
}
function drawTriangle77FromCenter(x, y, sideLength, flip) { // >: Normal <: flipped
if (!flip) drawTriangle77(x - (sideLength * 0.25 * (1 / ratio77)), y + (sideLength * 0.5), sideLength, flip);
if (flip) drawTriangle77(x + (sideLength * 0.25 * (1 / ratio77)), y + (sideLength * 0.5), sideLength, flip);
}
function Triangle77(x, y, normSize, flip) { // >: Normal <: flipped
this.x = x + (normSize * ratio77 * (flip ? -1 : 1));
if (!flip) this.x += normSize * 0.5 * (1 / ratio77);
this.y = y - (normSize / 2);
let dx = Math.abs((canvas77.width / 2) - this.x);
let dy = Math.abs((canvas77.height / 2) - this.y);
let dist = Math.sqrt((dx * dx) + (dy * dy));
let distRatio = dist / canvas77.width;
this.normSize = normSize;
this.currSize = normSize;
this.flip = flip;
this.hue = (distRatio * 360) + hue77;
this.saturation = 100;
this.brightess = 0;
this.tOffset = distRatio;
}
Triangle77.prototype.update = function() {
let t = smooth77((t77 + this.tOffset) % 1);
this.currSize = this.normSize * t;
this.brightness = ((1 - t) * 60) + 40;
};
Triangle77.prototype.draw = function() {
ctx77.fillStyle = ctx77.strokeStyle = `hsl(${this.hue}deg, ${this.saturation}%, ${this.brightness}%)`;
drawTriangle77FromCenter(this.x, this.y, this.currSize, this.flip);
};
let triangle77Array = [];
let lastFrame77Time = 0;
let lastFps77DisplayTime = 1000;
function frame77() {
if (Date.now() - lastFps77DisplayTime >= 500) {
fps77Txt.innerHTML = (1000 / (Date.now() - lastFrame77Time)).toFixed(1);
lastFps77DisplayTime = Date.now();
}
lastFrame77Time = Date.now();
ctx77.fillStyle = `hsla(0deg, 0%, 0%, ${clearOpacity77})`;
ctx77.fillRect(0, 0, canvas77.width, canvas77.height);
t77 += 1 / period77;
t77 %= 1;
for (let i = 0; i < triangle77Array.length; i++) {
triangle77Array[i].update();
triangle77Array[i].draw();
}
if (canvas77Running) requestAnimationFrame(frame77);
}
function reset77() {
ctx77.fillStyle = "black";
ctx77.fillRect(0, 0, canvas77.width, canvas77.height);
t77 = Math.random();
hue77 = Math.random() * 360;
triangle77Array = [];
let tileSize = canvas77.width / gridSize77;
let numX = Math.ceil(gridSize77 / ratio77) + 2;
let numY = gridSize77 + 2;
let xOffset = tileSize * 0.22 * (1 / ratio77);
for (let x = -2; x < numX; x++) {
for (let y = -1; y < numY; y++) {
let _x = x * tileSize * ratio77;
let _y = x % 2 === 0 ? y : y - 0.5;
_y *= tileSize;
triangle77Array.push(new Triangle77(_x - xOffset, _y, tileSize, true));
triangle77Array.push(new Triangle77(_x - xOffset, _y, tileSize, false));
}
}
if (!canvas77Running) frame77();
}
reset77();
function startCanvas77(caller) {
if (canvas77Running) {
canvas77Running = false;
caller.innerHTML = "<b><i>Paused</i></b>";
caller.style.color = caller.style.borderColor = "red";
}
else {
canvas77Running = true;
caller.innerHTML = "<b><i>Running</i></b>";
caller.style.color = caller.style.borderColor = "green";
frame77();
}
}
</script>
<canvas id = "canvas76"></canvas>
<button onclick = "draw76()">Redraw</button>
<div class = "desc"><b><i>(3/7/2022)</i></b> I tried to use something I implemented in the previous project, by connecting lines with random quadratic curves, but the result is pretty underwhelming.</div>
<hr><hr>
<script>
const ctx76 = canvas76.getContext("2d");
canvas76.width = canvas76.height = 1000;
let points76 = [];
let numPoints76 = 200;
let connectDist76 = 150;
let lineWidth76 = 2;
let lineBend76 = 100;
let shadow76 = 5;
function resetPoints76() {
points76 = [];
for (let i = 0; i < numPoints76; i++) {
points76.push({
x: Math.random() * canvas76.width,
y: Math.random() * canvas76.height
});
}
}
function connectPoints76() {
for (let i = 0; i < points76.length; i++) {
let connections = [];
for (let j = 0; j < points76.length; j++) {
if (i !== j) {
let dx = points76[i].x - points76[j].x;
let dy = points76[i].y - points76[j].y;
let distSq = (dx * dx) + (dy * dy);
if (distSq <= connectDist76 * connectDist76) connections.push(points76[j]);
}
}
for (let k = 0; k < connections.length; k++) {
ctx76.lineWidth = (lineWidth76 / connections.length) + 0.1;
ctx76.lineCap = ctx76.lineJoin = "round";
ctx76.strokeStyle = `hsl(${Math.random() * 360}deg, 80%, 40%)`;
ctx76.shadowBlur = shadow76;
ctx76.shadowColor = "white";
let mX = (points76[i].x + connections[k].x) / 2;
let mY = (points76[i].y + connections[k].y) / 2;
let a = Math.random() * Math.PI * 2;
let bend = Math.random() * lineBend76;
let cx = mX + (bend * Math.cos(a));
let cy = mY + (bend * Math.sin(a));
ctx76.beginPath();
ctx76.moveTo(points76[i].x, points76[i].y);
ctx76.quadraticCurveTo(cx, cy, connections[k].x, connections[k].y);
ctx76.stroke();
ctx76.shadowBlur = 0;
}
}
}
function draw76() {
ctx76.fillStyle = "black";
ctx76.fillRect(0, 0, canvas76.width, canvas76.height);
resetPoints76();
connectPoints76();
}
draw76();
</script>
<canvas id = "canvas75" style = "width: 500px; height: 500px"></canvas>
<button onclick = "draw75()">Redraw</button>
<div class = "desc"><b><i>(3/5/2022)</i></b> Experimenting with point networks. At first I just made a phyllotaxis spiral and connected the nearest points but it looked pretty bland. Then I added randomness to how offset each point is, and then finally changed the golden angle from ≈137.5078° to 2-4° and made the connections get lighter and thinner as they go out. Now it resembles some kind of mystic tribal rune, or magical energy...<br><b><i>Update: (A few minutes later)</i></b> I wanted to emphasize the theme of mysterious ancient energy so I changed the connections from simple line to quadratic curves, with a random offset bend that increases towards the edge of the circle. This creates an interesting contrast between the geometric design of the center and the stringy loops of the edge.<br><b><i>(3/6/2022)</i></b> I added white shadows to everything to create a glowing effect and added random white glowing dots around to emphasize the energy theme.<br><b><i><mark>Actually finished! (3/6/2022)</mark> Added to <a href = "https://e4494s.neocities.org/generative-art-gallery.html" target = "_blank">generative-art-gallery.html</a>.</i></b></div>
<hr><hr>
<script>
const ctx75 = canvas75.getContext("2d");
canvas75.width = canvas75.height = 1000;
let cachedSqrt75 = [];
for (let i = 0; i < 1100; i++) cachedSqrt75.push(Math.sqrt(i));
let connectDist75 = 40;
let spiralScale75 = 15;
let spiralJitter75 = 25;
let lineWidth75 = 5;
let lineBend75 = 50;
let minBend75 = 0;
let numDots75 = 150;
let dotSize75 = 6;
let hue75 = 0;
let dotOpacity75 = 1//0.35;
let shadowSize75 = 10//5;
let shadowRatio75 = 0//0.8;
let goldenAngle75 = toRad(3);//Math.PI * (3 - Math.sqrt(5));
let points75 = [];
function drawDot75(x, y, isSquare) {
ctx75.fillStyle = `hsla(${hue75}deg, 100%, 100%, ${dotOpacity75})`;
ctx75.shadowColor = `hsl(${hue75}deg, 100%, 100%)`;
ctx75.shadowBlur = 10;
let r = dotSize75 * randBetween(0.5, 1);
let offset = Math.random() * Math.PI * 2;
for (let j = 0; j < 3; j++) {
if (!isSquare) ctx75.fillCircle(x, y, r / 1.3);
else {
ctx75.beginPath();
for (let i = 0; i < 4; i++) {
let a = ((i / 4) * Math.PI * 2) + offset;
ctx75.lineTo(x + (r * Math.cos(a)), y + (r * Math.sin(a)));
}
ctx75.fill();
}
}
ctx75.shadowBlur = 0;
}
function spiralPoints75() {
points75 = [];
let offset = Math.random() * Math.PI * 2;
for (let i = 0; i < 1000; i++) {
let a = (i * goldenAngle75) + offset;
let r = cachedSqrt75[i] * spiralScale75;
let x = (canvas75.width / 2) + (r * Math.cos(a));
let y = (canvas75.height / 2) + (r * Math.sin(a));
let a2 = Math.random() * Math.PI * 2;
let r2 = Math.random() * spiralJitter75;
points75.push({x: x + (r2 * Math.cos(a2)), y: y + (r2 * Math.sin(a2))});
}
}
function connectPoints75() {
ctx75.lineCap = ctx75.lineJoin = "round";
ctx75.shadowColor = "white";
let hue = hue75;
for (let i = 0; i < points75.length; i++) {
for (let j = 0; j < points75.length; j++) {
if (i !== j) {
let dx = points75[i].x - points75[j].x;
let dy = points75[i].y - points75[j].y;
let distSq = (dx * dx) + (dy * dy);
if (distSq <= connectDist75 * connectDist75) {
let iRatio = i / points75.length;
ctx75.strokeStyle = ctx75.shadowColor = `hsl(${hue}deg, 100%, ${(iRatio * 95) + 10}%)`;
ctx75.lineWidth = ((1 - iRatio) * lineWidth75) + 0.2;
ctx75.shadowBlur = iRatio > shadowRatio75 ? shadowSize75 : 0;
let p = {};
let a = Math.random() * Math.PI * 2;
let bend = (iRatio * lineBend75) + minBend75;
let r = Math.random() * bend;
p.x = ((points75[i].x + points75[j].x) / 2) + (r * Math.cos(a));
p.y = ((points75[i].y + points75[j].y) / 2) + (r * Math.sin(a));
ctx75.beginPath();
ctx75.moveTo(points75[i].x, points75[i].y);
ctx75.quadraticCurveTo(p.x, p.y, points75[j].x, points75[j].y);
ctx75.stroke();
}
}
}
}
ctx75.shadowBlur = 0;
}
function draw75() {
ctx75.fillStyle = "black";
ctx75.fillRect(0, 0, canvas75.width, canvas75.height);
hue75 = Math.random() * 360;
goldenAngle75 = toRad(randBetween(2, 4));
if (Math.random() < 0.5) goldenAngle75 *= -1;
spiralPoints75();
connectPoints75();
for (let i = 0; i < numDots75; i++) {
let r = (canvas75.width / 2) - ((canvas75.width / 2) * Math.random() * Math.random());
let a = Math.random() * Math.PI * 2;
drawDot75((canvas75.width / 2) + (r * Math.cos(a)), (canvas75.height / 2) + (r * Math.sin(a)), Math.random() < 0);
}
}
draw75();
</script>
<canvas id = "canvas74" style = "width: 500px; height: 500px"></canvas>
<button onclick = "draw74()">Redraw</button>
<div class = "desc"><b><i>(3/4/2022)</i></b> I worked out a program to draw the impossible Penrose Triangle.<br><b><i>(3/5/2022)</i></b> Went from drawing one large triangle, to drawing lots of them in a hexagon grid. I really like the design of the triangles but I'm not happy with this arrangement of them and I want to find a more cool looking way to put them on the screen.</div>
<hr><hr>
<script>
const ctx74 = canvas74.getContext("2d");
canvas74.width = canvas74.height = 1000;
const ratio74 = Math.sqrt(3) / 2;
let gridSize74 = 6;
let hueVariation74 = 0.1;
function drawTriangle74(x, y, radius, angle, hue) {
ctx74.strokeStyle = "white";
ctx74.lineWidth = 1;
ctx74.lineCap = ctx74.lineJoin = "round";
let side = radius / (ratio74 * 5.5);
let h = hue + randBetween(-180 * hueVariation74, 180 * hueVariation74);
let s = randBetween(50, 100);
for (let i = 2; i >= 0; i--) {
ctx74.fillStyle = `hsl(${h}deg, ${s}%, ${((i / 2) * 70) + 15}%)`;
let ca = 30 + (i * 120) + angle;
let r = side * (4 / 3) * ratio74;
let cx = x + (r * Math.cos(toRad(ca)));
let cy = y + (r * Math.sin(toRad(ca)));
ctx74.beginPath();
ctx74.moveTo(cx, cy);
ca -= 30;
cx += side * Math.cos(toRad(ca));
cy += side * Math.sin(toRad(ca));
ctx74.lineTo(cx, cy);
ca -= 120;
cx += side * 5 * Math.cos(toRad(ca));
cy += side * 5 * Math.sin(toRad(ca));
ctx74.lineTo(cx, cy);
ca -= 120;
cx += side * 6 * Math.cos(toRad(ca));
cy += side * 6 * Math.sin(toRad(ca));
ctx74.lineTo(cx, cy);
ca -= 60;
cx += side * Math.cos(toRad(ca));
cy += side * Math.sin(toRad(ca));
ctx74.lineTo(cx, cy);
ca -= 120;
cx += side * 5 * Math.cos(toRad(ca));
cy += side * 5 * Math.sin(toRad(ca));
ctx74.lineTo(cx, cy);
ca += 120;
cx += side * 3 * Math.cos(toRad(ca));
cy += side * 3 * Math.sin(toRad(ca));
ctx74.lineTo(cx, cy);
ctx74.fill();
//ctx74.stroke();
}
}
function draw74() {
ctx74.fillStyle = "black";
ctx74.fillRect(0, 0, canvas74.width, canvas74.height);
gridSize74 = Math.round(randBetween(3, 10));
let tileSize = canvas74.width / gridSize74;
let numX = gridSize74 + 2; // Compensate for staggered rows and x-offset
let numY = Math.ceil(gridSize74 * (1 / ratio74)) + 1; // Compensate for vertical compression and y-offset
let hue = Math.random() * 360;
let offsetX = Math.random() * tileSize;
let offsetY = Math.random() * tileSize;
for (let x = 0; x < numX; x++) {
for (let y = 0; y < numY; y++) {
let _x = y % 2 === 0 ? x : x - 0.5;
_x += 0.5;
_y = y * ratio74;
_y += 0.5;
let tileX = (_x * tileSize) - offsetX;
let tileY = (_y * tileSize) - offsetY;
let dx = tileX - (canvas74.width / 2)// - tileX;
let dy = tileY - (canvas74.height / 2)// - tileY;
let a = Math.random() * 360//toDeg(Math.atan2(dy, dx)) + 30;
drawTriangle74(tileX, tileY, tileSize * 0.5, a, hue);
}
}
}
draw74();
</script>
<canvas id = "canvas73"></canvas>
<button onclick = "draw73()">Redraw</button>
<div class = "desc"><b><i>(3/1/2022)</i></b> More variation circle packing, this time with random triangles drawn instead of circles, and with a visual size ratio of 1.5x so they overlap each other but still are spaced out nicely.<br><b><i>Update: (Later that day)</i></b> Added more paramaters that get randomized. Lines are drawn on every triangle either from its center to its corners or its center to its edges, randomized every generation. There is also a random tilt factor for how rotated each triangle will be off the global angle, and a skew angle for how skewed the triangles will be from a perfect equilateral.<br><b><i><mark>Actually finished! (3/1/2022)</mark> Added to <a href = "generative-art-gallery.html" target = "_blank">generative-art-gallery.html</a>.</i></b></div>
<hr><hr>
<script>
const ctx73 = canvas73.getContext("2d");
canvas73.width = canvas73.height = 1000;
let maxCircles73 = 2000;
let canvas73Filled = false;
let minCircle73Size = 5;
let maxCircle73Size = 100;
let circle73SizeRatio = 1.5;
let brightnessRatio73 = 1;
let hue73 = 0;
let angleOffset73 = 0;
let sides73 = 3//Math.round(randBetween(3, 5));
let skew73 = 0;
let edges73 = false;
let tilt73 = 15;
function randColor73() {
let s = Math.random() * Math.random() * 40;
return `hsl(${hue73 + randBetween(-5, 5)}deg, ${randBetween(20, 40) + s}%, ${randBetween(30, 60) * brightnessRatio73}%)`;
}
function drawCircle73(x, y, radius) {
//angleOffset73 = Math.random() * Math.PI * 2;
ctx73.fillStyle = randColor73();
ctx73.lineWidth = 2;
ctx73.lineCap = ctx73.lineJoin = "round";
ctx73.strokeStyle = "black";
let numPoints = sides73;
let angle = (Math.PI * 2) / numPoints;
let corners = [];
let offset = toRad(randBetween(-tilt73, tilt73));
ctx73.beginPath();
for (let i = 0; i < numPoints; i++) {
let a = (angle * i) + angleOffset73 + offset + toRad(randBetween(-skew73, skew73));
let r = radius;
let iX = x + (r * Math.cos(a));
let iY = y + (r * Math.sin(a));
corners.push({x: iX, y: iY});
ctx73.lineTo(iX, iY);
}
ctx73.lineTo(corners[0].x, corners[0].y);
ctx73.lineTo(corners[1].x, corners[1].y);
ctx73.fill();
ctx73.stroke();
ctx73.beginPath();
let mX = (corners[0].x + corners[1].x + corners[2].x) / 3;
let mY = (corners[0].y + corners[1].y + corners[2].y) / 3;
let edges = [];
for (let i = 0; i < 3; i++) {
let j = corners[i];
let k = corners[(i + 1) % 3];
edges.push({x: (j.x + k.x) / 2, y: (j.y + k.y) / 2});
}
for (let i = 0; i < 3; i++) {
ctx73.moveTo(mX, mY);
if (edges73) ctx73.lineTo(edges[i].x, edges[i].y);
else ctx73.lineTo(corners[i].x, corners[i].y);
}
ctx73.stroke();
}
function Circle73() {
let x = Math.random() * canvas73.width;
let y = Math.random() * canvas73.height;
let tries = 0;
while (!validatePoint73(x, y)) {
if (tries > 1000) {
canvas73Filled = true;
return;
}
x = Math.random() * canvas73.width;
y = Math.random() * canvas73.height;
tries++;
}
this.x = x;
this.y = y;
this.radius = 0;
this.grow();
}
Circle73.prototype.grow = function() {
let smallestDist = Infinity;
for (let i = 0; i < circle73Array.length; i++) {
if (i != circle73Array.indexOf(this)) {
let dx = this.x - circle73Array[i].x;
let dy = this.y - circle73Array[i].y;
let distSq = (dx * dx) + (dy * dy);
let dist = Math.sqrt(distSq) - circle73Array[i].radius;
if (dist <= smallestDist) smallestDist = dist;
}
}
// Uncomment to constrain within canvas edges:
/*let distToTop = this.y;
if (distToTop <= smallestDist) smallestDist = distToTop;
let distToRight = canvas73.width - this.x;
if (distToRight <= smallestDist) smallestDist = distToRight;
let distToBottom = canvas73.height - this.y;
if (distToBottom <= smallestDist) smallestDist = distToBottom;
let distToLeft = this.x;
if (distToLeft <= smallestDist) smallestDist = distToLeft;*/
this.radius = Math.min(smallestDist, maxCircle73Size);
drawCircle73(this.x, this.y, this.radius * circle73SizeRatio);
};
let circle73Array = [];
function validatePoint73(x, y) {
for (let i = 0; i < circle73Array.length; i++) {