-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
2070 lines (1916 loc) · 72.5 KB
/
script.js
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
// TO DO
// Add mute button
// Waterfall instrument? Something with multiple sizes
// Hover instrument(s)?
// Comparison instrument(s)?
// Crop variable range?
// Random font button
// Documentation menu
// —————————————————————————————————————————————————————————————————————
// INTRO AND LOGO
// —————————————————————————————————————————————————————————————————————
// Logo functions
function logoIn() {
let logoLine1 = document.querySelector(".logo-line-1");
let logoLine2 = document.querySelector(".logo-line-2");
let logoLine3 = document.querySelector(".logo-line-3");
logoLine1.style.transform = "translateY(0vh) rotate(0deg)";
setTimeout(() => {
logoLine2.style.transform = "translateX(0vw) rotate(0deg)";
}, 100);
setTimeout(() => {
logoLine3.style.transform = "translateY(0vh) rotate(0deg)";
}, 600);
}
function logoOut() {
let logo = document.querySelector(".logo");
logo.style.transform = "translateY(-120vh) rotate(10deg)";
logoAnimationLoop = false;
setTimeout(() => {
logo.style.display = "none";
document.querySelector('.intro-text').style.display = "none";
}, 1200);
}
let logoAnimationLoop = true;
let logoFontVariation = true;
function logoAnimation() {
let logoLetters = document.querySelectorAll(".logo span");
let index = 0;
let loop = setInterval(() => {
if (logoAnimationLoop) {
if (logoFontVariation) {
logoLetters[index].style.fontVariationSettings = `'BASH' 100`;
} else {
logoLetters[index].style.fontVariationSettings = `'BASH' 0`;
}
index++;
if (index >= logoLetters.length) {
index = 0;
logoFontVariation = !logoFontVariation;
clearInterval(loop);
setTimeout(() => {
logoAnimation();
}, 500);
}
} else {
clearInterval(loop);
return
}
}, 50);
}
let colors = ["red", "blue", "purple", "yellow", "pink", "green"];
let currentColor = 0;
let colorCycleToggle = true;
function colorCycle() {
// Set initial primary color
currentColor = Math.floor(Math.random()*colors.length);
let color = colors[currentColor];
document.querySelector(':root').style.setProperty("--primary", `var(--${color})`);
// Set initial background styling
let body = document.querySelector("body");
body.style.backgroundImage = `url("graphics/background-${color}.gif")`;
body.style.backgroundSize = `${Math.random()*50+50}px ${Math.random()*50+50}px`;
// Color index iteration
currentColor++;
if (currentColor >= colors.length) {
currentColor = 0;
}
// Main loop
colorLoop = setInterval(() => {
if (colorCycleToggle) {
// Primary color change
let color = colors[currentColor];
document.querySelector(':root').style.setProperty("--primary", `var(--${color})`);
// Background styling
let body = document.querySelector("body");
body.style.backgroundImage = `url("graphics/background-${color}.gif")`;
body.style.backgroundSize = `${Math.random()*50+50}px ${Math.random()*50+50}px`;
// Color index iteration
currentColor++;
if (currentColor >= colors.length) {
currentColor = 0;
}
} else {
clearInterval(colorLoop);
}
}, 5000);
}
// Intro on page load
setTimeout(() => {
let logoLine1 = document.querySelector(".logo-line-1");
let logoLine2 = document.querySelector(".logo-line-2");
let logoLine3 = document.querySelector(".logo-line-3");
logoLine1.style.transition = "0s";
logoLine2.style.transition = "0s";
logoLine3.style.transition = "0s";
logoLine1.style.transform = `translateY(-75vh) rotate(${Math.random()*90-45}deg)`;
logoLine2.style.transform = `translateX(-75vw) rotate(${Math.random()*90-45}deg)`;
logoLine3.style.transform = `translateY(75vh) rotate(${Math.random()*90-45}deg)`;
setTimeout(() => {
logoLine1.style.transition = "transform 2s, background-color .5s, color .5s, fill .5s";
logoLine2.style.transition = "transform 2s, background-color .5s, color .5s, fill .5s";
logoLine3.style.transition = "transform 2s, background-color .5s, color .5s, fill .5s";
logoIn();
}, 50);
setTimeout(() => {
logoAnimation();
colorCycle();
}, 2000);
}, 50);
// —————————————————————————————————————————————————————————————————————
// CREDITS
// —————————————————————————————————————————————————————————————————————
// Credits in and out
function creditsIn() {
let credits = document.querySelector("#credits");
credits.style.transform = "translateY(0%)";
}
function creditsOut() {
let credits = document.querySelector("#credits");
credits.style.transform = "translateY(-200%)";
}
// Credit info
let creditList = {
jost: "<strong>Jost*</strong> by Owen Earl",
bashful: "<strong>Bashful</strong> by Gabriel Drozdov",
powerpack: "<strong>PowerPack</strong> by Gabriel Drozdov",
thatthenthis: "<strong>That Then This</strong> by Gabriel Drozdov",
minimochi: "<strong>Mini Mochi</strong> by Gabriel Drozdov",
dreidel: "<strong>Dreidel</strong> by Gabriel Drozdov",
galapagos: "<strong>Work Sans Galápagos</strong> by Gabriel Drozdov, based on <strong>Work Sans</strong> by Wei Huang",
authenticremixed: "<strong>AUTHENTIC Remixed</strong> by Gabriel Drozdov, based on <strong>AUTHENTIC Sans</strong> by Christina Janus and Desmond Wong",
caffeine: "<strong>Caffeine</strong> by Gabriel Drozdov",
jump: "<strong>Jump</strong> by Jinhong Cai, based on <strong>Barlow Black</strong> by Jeremy Tribby",
nocturnalspaceinvaders: "<strong>Nocturnal Space Invaders</strong> by Kryeol Chen, based on a pixel font from <strong>Mario Paint</strong>",
spaghettisans: "<strong>Spaghetti Sans</strong> by Gina Kang",
funkyserif: "<strong>Funky Serif</strong> by Ivy Zhang, based on <strong>Adobe Caslon Pro</strong> by Carol Twombly",
scribblesurprise: "<strong>Scribble Surprise</strong> by Rita Wang",
studiodisplay: "<strong>STUDIO Display</strong> by Husna Abubakar",
cloris: "<strong>Cloris</strong> by Alex Zhu",
fungus: "<strong>Fungus</strong> by Plato Peng, based on <strong>Kumbh Sans</strong> by Saurabh Sharma",
selfportraits: "<strong>Self-Portraits</strong> by Students of the Workshop",
littlemonster: "<strong>Little Monster</strong> by Yining Li, based on <strong>Jost*</strong> by Owen Earl",
gilberto: "<strong>Gilberto</strong> by Cameron Astles",
corruption: "<strong>Corruption</strong> by Haoyuan Liu",
emotype: "<strong>Emo Type</strong> by Mehek Vohra",
garden: "<strong>Garden</strong> by Alex Kim",
lava: "<strong>Lava</strong> by Victoria Liang",
macaroni: "<strong>Macaroni</strong> by Truman Lesak",
natoalphabet: "<strong>NATO Alphabet</strong> by Christine Wang",
noah: "<strong>NOAH</strong> by Helen Peng",
phromphong: "<strong>Phrom Phong</strong> by Varissara Patiparnprechavut",
popup: "<strong>Pop-up</strong> by Jisu Chang",
starfont: "<strong>Star Font</strong> by Sharlene Deng",
tetris: "<strong>Tetris</strong> by Brianna Cheng",
useless: "<strong>Useless</strong> by Wenqing Ma",
whatsthepoint: "<strong>What’s The Point</strong> by Harshal Duddalwar",
windyday: "<strong>Windy Day</strong> by Ashley Kim",
xopuzzles: "<strong>XO Puzzles</strong> by Li Huang",
newivy: "<strong>New Ivy</strong> by Max Beidler",
"jost-amputation": "<strong>Jost*</strong>, as remixed by Alex Zhu",
"jost-kilter": "<strong>Jost*</strong>, as remixed by Cameron Astles",
"jost-pointy": "<strong>Jost*</strong>, as remixed by Gina Kang",
"jost-squint": "<strong>Jost*</strong>, as remixed by Ivy Zhang",
"jost-yl": "<strong>Jost*</strong>, as remixed by Yining Li",
"jost-jc": "<strong>Jost*</strong>, as remixed by Jinhong Cai",
"jost-scone": "<strong>Jost*</strong>, as remixed by Kryeol Chen",
"jost-mmb": "<strong>Jost*</strong>, as remixed by Max Mainio Beidler",
"jost-ml": "<strong>Jost*</strong>, as remixed by Moritz Lonyay",
"jost-negativespace": "<strong>Jost*</strong>, as remixed by Plato Peng",
"jost-sleepy": "<strong>Jost*</strong>, as remixed by Rita Wang",
"jost-nn": "<strong>Jost*</strong>, as remixed by Nishtha Nanda",
"jost-ha": "<strong>Jost*</strong>, as remixed by Husna Abubakar",
"jost-hu": "<strong>Jost*</strong>, as remixed by Raven Hu",
"userupload": "<strong>Something</strong>, you uploaded!",
}
function creditInfo(credit) {
let credits = document.querySelector("#credits");
credits.querySelector("p").innerHTML = creditList[credit];
}
// —————————————————————————————————————————————————————————————————————
// NAVIGATION AND SETTINGS
// —————————————————————————————————————————————————————————————————————
// Nav and settings sidebar
function navIn() {
let nav = document.querySelector("#nav");
nav.style.transform = "translateX(0) rotate(0deg)";
}
function navOut() {
let nav = document.querySelector("#nav");
nav.style.transform = "translateX(400px) rotate(-30deg)";
}
let navState = true;
function navHide() {
let navToggle = document.querySelector("#nav-toggle");
if (navState) {
navOut();
setTimeout(() => {
navToggle.style.right = "-100px";
navState = false;
}, 250);
} else {
navToggle.style.right = "-200px";
setTimeout(() => {
navIn();
navState = true;
}, 250);
}
}
function settingsIn() {
navOut();
let settings = document.querySelector("#settings");
setTimeout(() => {
settings.style.transform = "translateX(0) rotate(0deg)";
}, 250);
}
function settingsOut() {
let settings = document.querySelector("#settings");
settings.style.transform = "translateX(400px) rotate(-30deg)";
setTimeout(() => {
navIn();
}, 250);
}
// Settings functions
function settingsFontSize(value) {
let currentValue = getComputedStyle(document.documentElement).getPropertyValue('--player-fontsize');
document.querySelector(':root').style.setProperty("--player-fontsize", parseFloat(currentValue) + value + "vmax");
}
function settingsTracking(value) {
let currentValue = getComputedStyle(document.documentElement).getPropertyValue('--player-letterspacing');
document.querySelector(':root').style.setProperty("--player-letterspacing", parseFloat(currentValue) + value + "em");
}
function settingsLeading(value) {
let currentValue = getComputedStyle(document.documentElement).getPropertyValue('--player-lineheight');
document.querySelector(':root').style.setProperty("--player-lineheight", parseFloat(currentValue) + value + "em");
}
let caseOptions = ["unset", "uppercase", "capitalize", "lowercase"];
let currentCase = 0;
function settingsSetCase() {
currentCase++;
if (currentCase >= caseOptions.length) {
currentCase = 0;
}
document.querySelector(':root').style.setProperty("--player-texttransform", caseOptions[currentCase]);
}
let toggleAnimations = true;
function settingsToggleAnimations() {
if (toggleAnimations) {
toggleAnimations = false;
for (i of document.querySelectorAll(".instrument-display-text")) {
i.dataset.toggle = "1";
}
} else {
toggleAnimations = true;
for (i of document.querySelectorAll(".instrument-display-text")) {
i.dataset.toggle = "0";
}
}
}
function settingsSwapColor() {
colorCycleToggle = false;
currentColor++;
if (currentColor >= colors.length) {
currentColor = 0;
}
// Primary color change
let color = colors[currentColor];
document.querySelector(':root').style.setProperty("--primary", `var(--${color})`);
// Background styling
let body = document.querySelector("body");
body.style.backgroundImage = `url("graphics/background-${color}.gif")`;
body.style.backgroundSize = `${Math.random()*50+50}px ${Math.random()*50+50}px`;
}
// Randomize font order in menu
let fontMenu = document.querySelector("#fontbox");
let fontMenuList = fontMenu.querySelector("ul");
for (let i = 1; i <= fontMenuList.children.length; i++) {
fontMenuList.appendChild(fontMenuList.children[Math.random() * i | 1]);
}
// Menus
let currentMenu = "";
function menuIn(menuName) {
colorCycleToggle = false;
instrumentOut();
creditsOut();
navOut();
conversatorDeactivate();
// Move settings out if shown
let settings = document.querySelector("#settings");
settings.style.transform = "translateX(400px) rotate(-30deg)";
// Move handle out if shown
let navToggle = document.querySelector("#nav-toggle");
navToggle.style.right = "-200px";
navState = true;
currentMenu = "#"+menuName;
let menuTarget = document.querySelector(currentMenu);
menuTarget.style.transform = "translateX(0)";
// Randomize menu button transforms
if (currentMenu == '#fontbox' || currentMenu == '#instrumentbox') {
let grid = menuTarget.querySelectorAll('li');
for (let item of grid) {
item.style.transition = "0s";
item.style.transform = `translate(${Math.random()*-500}px, ${Math.random()*-1000+500}px) rotate(${Math.random()*20-10}deg)`;
}
setTimeout(() => {
for (let item of grid) {
item.style.transition = "background-color .2s, color .2s, fill .2s, transform 1s";
item.style.transform = `translate(0, 0) rotate(${Math.random()*20-10}deg)`;
}
}, 50)
}
}
function menuOut() {
let menuTarget = document.querySelector(currentMenu);
menuTarget.style.transform = "translateX(-120vw)";
if (currentMenu == '#fontbox' || currentMenu == '#instrumentbox') {
let grid = menuTarget.querySelectorAll('li');
for (let item of grid) {
item.style.transform = `translate(${Math.random()*-500}px, ${Math.random()*-200+100}px) rotate(${Math.random()*20-10}deg)`;
}
}
instrumentIn();
creditsIn();
navIn();
}
// —————————————————————————————————————————————————————————————————————
// FONTS
// —————————————————————————————————————————————————————————————————————
let fontOptions = [
'jost',
'bashful',
'powerpack',
'thatthenthis',
'minimochi',
'dreidel',
'galapagos',
'authenticremixed',
'caffeine',
'jump',
'nocturnalspaceinvaders',
'spaghettisans',
'funkyserif',
'scribblesurprise',
'studiodisplay',
'cloris',
'fungus',
'selfportraits',
'littlemonster',
'gilberto',
'corruption',
'emotype',
'garden',
'lava',
'macaroni',
'natoalphabet',
'noah',
'phromphong',
'popup',
'starfont',
'tetris',
'useless',
'whatsthepoint',
'windyday',
'xopuzzles',
'newivy',
]
let jostRemixes = [
"jost-amputation",
"jost-kilter",
"jost-pointy",
"jost-squint",
"jost-yl",
"jost-jc",
"jost-scone",
"jost-mmb",
"jost-ml",
"jost-negativespace",
"jost-sleepy",
"jost-nn",
"jost-ha",
"jost-hu",
]
// Select font from menu
function pickFont(selectedFont) {
settingsSwapColor();
let fontPath = selectedFont;
if (selectedFont == "jost-remix") {
selectedFont = jostRemixes[Math.floor(Math.random()*jostRemixes.length)];
fontPath = "remixes/" + selectedFont;
}
document.querySelector(':root').style.setProperty("--activefont", `${selectedFont}`);
fontReset();
getAxisInfo(selectedFont, `fonts/${fontPath}.ttf`);
playPercussion('C2');
creditInfo(selectedFont);
menuOut();
}
// Read user-inputted font
document.getElementById('menubox-customfont').addEventListener('click', openDialog);
function openDialog() {
// Make styled button open correct dialogue
document.getElementById('menubox-customfont-input').click();
}
var newStyle = document.createElement('style');
function handleFileSelect(event) {
if (window.FileList && window.File && window.FileReader) {
newStyle.remove();
// Validate file type
let file;
if (event.dataTransfer) {
file = event.dataTransfer.files[0]; // select via drag and drop
} else {
file = event.target.files[0]; // select via font menu
}
let fileType = file.name.split('.').pop().toLowerCase();
if (fileType != 'ttf' && fileType != 'otf' && fileType != 'woff' && fileType != 'woff2') {
window.alert('That’s not a valid font file! Try a .ttf, .otf, .woff, or .woff2 file.');
document.getElementById('menubox-customfont-input').value = null;
return;
}
let userFont = URL.createObjectURL(file);
// Add font to document by creating new font style
newStyle.appendChild(document.createTextNode(`
@font-face{font-family:user;src:url('${userFont}');}`));
document.head.appendChild(newStyle);
document.querySelector(':root').style.setProperty("--activefont", `user`);
// Reset input in case same file is selected
document.getElementById('menubox-customfont-input').value = null;
// Transition out
getAxisInfo("user", userFont);
creditInfo("userupload");
if (currentMenu != "") {
menuOut();
}
}
}
// Drag and drop font files
let dropArea = document.getElementById('drop-area');
let dropAreaHighlight = document.querySelector('.drop-area-highlight');
;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false)
})
function preventDefaults (e) {
e.preventDefault()
e.stopPropagation()
}
;['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, dropHighlight, false)
})
;['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, dropUnhighlight, false)
})
function dropHighlight(e) {
dropAreaHighlight.classList.add('drop-area-highlight-active')
}
function dropUnhighlight(e) {
dropAreaHighlight.classList.remove('drop-area-highlight-active')
}
dropArea.addEventListener('drop', handleFileSelect, false);
// Detect variable axes and limits
let axesInfo = [];
let fontName = "";
function getAxisInfo(fontFamily, fontUrl) {
let font = new Font(fontFamily, {skipStyleSheet: true});
font.src = fontUrl;
font.onload = (e) => {
axesInfo = [];
let font = e.detail.font;
let otTables = font.opentype.tables;
fontName = otTables.name.get(1);
// Get variable font axes
if (otTables.fvar != undefined) {
let axes = otTables.fvar.axes;
axes.forEach((axis, a) => {
let axisName = axis.tag;
let axisMin = axis.minValue;
let axisMax = axis.maxValue;
let axisDefault = axis.defaultValue;
axesInfo.push({name:axisName, min:axisMin, max:axisMax, default:axisDefault});
})
console.log(axesInfo);
// Set CSS variables
let temp = "";
let axisNumber = 0;
for (axisNumber; axisNumber<axesInfo.length && axisNumber<4; axisNumber++) {
for (let axisDisplay of document.querySelectorAll(`.instrument-axesinfo-${axisNumber}`)) {
axisDisplay.style.display = "flex";
}
document.querySelector(':root').style.setProperty(`--axis${axisNumber}-name`, `"${axesInfo[axisNumber].name}"`);
document.querySelector(':root').style.setProperty(`--axis${axisNumber}-min`, `${axesInfo[axisNumber].min}`);
document.querySelector(':root').style.setProperty(`--axis${axisNumber}-max`, `${axesInfo[axisNumber].max}`);
if (axisNumber>0) {
temp += ", ";
}
temp += `var(--axis${axisNumber}-name) var(--axis${axisNumber}-calculated)`;
}
for (axisNumber; axisNumber<4; axisNumber++) {
for (let axisDisplay of document.querySelectorAll(`.instrument-axesinfo-${axisNumber}`)) {
axisDisplay.style.display = "none";
}
}
document.querySelector(':root').style.setProperty(`--player-variation`, `${temp}`);
initializeInstrument();
console.log(getComputedStyle(document.body).getPropertyValue('--player-variation'));
} else {
console.log("No variable axes!");
axesInfo = [];
initializeInstrument();
}
}
}
// Reset font settings
function fontReset() {
document.querySelector(':root').style.setProperty(`--player-fontsize`, `4vmax`);
document.querySelector(':root').style.setProperty(`--player-letterspacing`, `0px`);
document.querySelector(':root').style.setProperty(`--player-lineheight`, `1em`);
document.querySelector(':root').style.setProperty(`--player-texttransform`, `unset`);
currentCase = 0;
toggleAnimations = true;
for (i of document.querySelectorAll(".instrument-display-text")) {
i.dataset.toggle = "0";
}
}
// —————————————————————————————————————————————————————————————————————
// RANDOM SENTENCE GENERATOR
// —————————————————————————————————————————————————————————————————————
let nouns = ["arrangement", "art", "artwork", "build", "body", "character", "construction", "contour", "design", "drawing", "figure", "font", "form", "formation", "glyph", "graphic", "letter", "letterform", "line", "object", "outline", "piece", "scene", "shape", "sketch", "structure", "subject", "typeface", "typography"];
let verbs = ["adapted", "adjusted", "animated", "altered", "changed", "converted", "diverged", "evolved", "interpolated", "mutated", "reshaped", "reassembled", "reconstructued", "regenerated", "transfigured", "transformed", "transmuted", "translated", "tuned", "turned", "varied"];
let adjectives = ["abstract", "absorbing", "aesthetic", "appealing", "authentic", "balanced", "bold", "clean", "colorful", "contemplative", "creative", "daring", "dazzling", "decorative", "delicate", "dense", "divine", "dramatic", "dynamic", "elegant", "elevated", "emotional", "exquisite", "fluid", "geometric", "gorgeous", "grand", "harmonious", "imaginative", "impassioned", "impeccable", "inspired", "jagged", "lifelike", "light", "maximalist", "minimalist", "moving", "musical", "organic", "ornamental", "pleasing", "polished", "profound", "radiant", "rich", "stunning", "stylish", "sublime", "surreal", "tasteful", "traditional", "tranquil", "unforgettable", "unpredictable", "varied"];
let adverbs = ["abnormally", "awkwardly", "beautifully", "briskly", "calmly", "cleverly", "cooly", "deliberately", "delightfully", "elegantly", "energetically", "excitedly", "frantically", "frightfully", "gently", "gleefully", "hastily", "intensely", "jubilantly", "kookily", "lavishly", "lazily", "lightly", "loudly", "lovingly", "majestically", "naturally", "neatly", "nervously", "noisily", "playfully", "precisely", "punctually", "quickly", "quizzically", "randomly", "rapidly", "repeatedly", "sharply", "shockingly", "sleepily", "slowly", "suddenly", "tenderly", "tremendously", "unexpectedly", "viciously", "warmly", "zestfully"];
let prepositions = ["into", "to", "toward"];
function isVowel(x) {
let result = x == "a" || x == "e" || x == "i" || x == "o" || x == "u";
return result;
}
function randomSentence() {
let noun1 = nouns[Math.floor(Math.random()*nouns.length)];
let noun2 = nouns[Math.floor(Math.random()*nouns.length)];
let verb = verbs[Math.floor(Math.random()*verbs.length)];
let adjective1 = adjectives[Math.floor(Math.random()*adjectives.length)];
let adjective2 = adjectives[Math.floor(Math.random()*adjectives.length)];
let article = "a";
if (isVowel(adjective2.charAt(0)) == true) {
article = "an";
}
let adverb = adverbs[Math.floor(Math.random()*adverbs.length)];
let preposition = prepositions[Math.floor(Math.random()*prepositions.length)];
return `The ${adjective1} ${noun1} ${adverb} ${verb} ${preposition} ${article} ${adjective2} ${noun2}`;
};
// Generate random letters
function randomLetters(quantity) {
let temp = "";
for (let i=0; i<quantity; i++) {
temp += alphabet[Math.floor(Math.random()*alphabet.length)];
}
return temp;
}
// Generate a whole bunch of the same letter
function randomLettersRepeat(quantity) {
let temp = "";
let letter = alphabet[Math.floor(Math.random()*alphabet.length)];
for (let i=0; i<quantity; i++) {
temp += letter;
}
return temp;
}
// —————————————————————————————————————————————————————————————————————
// INSTRUMENTS
// —————————————————————————————————————————————————————————————————————
let playerState = false; // If instrument is currently playing, equals true
let instrumentOptions = ['oscillator', 'sequencer', 'scrambler', 'conversator', 'alphabetizer', 'analyzer'];
let activeInstrument = "";
function instrumentIn() {
// Reset all instruments
for (let instrument of document.querySelectorAll(".instrument")) {
instrument.style.display = "none";
}
document.querySelector("#"+activeInstrument).style.display = "grid"; // Show active instrument
document.querySelector(".instrument-container").style.transform = `translateY(0) rotate(0)`; // Slide in container
}
function instrumentOut() {
document.querySelector(".instrument-container").style.transform = "translateY(150vh) rotate(10deg)";
playerState = false;
// Stop microphone input
clearInterval(volumeInterval);
}
// Select instrument from menu
function pickInstrument(selectedInstrument) {
playPercussion('C2');
fontReset();
activeInstrument = selectedInstrument;
initializeInstrument();
menuOut();
settingsSwapColor();
}
// Initalize instrument to work with font axes
function initializeInstrument() {
let instrumentDOM = document.querySelector("#"+activeInstrument);
if (activeInstrument == 'oscillator') {
// Set transition to 100ms
document.querySelector(':root').style.setProperty(`--player-variation-speed`, `linear 100ms`);
// Initialize play values
oscillatorInitialize();
// Randomize display text
let displayText = instrumentDOM.querySelector(`.instrument-display-text`);
displayText.innerText = randomSentence();
// Initalize all axes to not show
let oscillatorAxes = instrumentDOM.querySelectorAll(".instrument-slider-container");
oscillatorAxes[0].dataset.sliderActive = '0';
oscillatorAxes[1].dataset.sliderActive = '0';
oscillatorAxes[2].dataset.sliderActive = '0';
oscillatorAxes[3].dataset.sliderActive = '0';
// Check if font is actually variable and show correct controls
if (axesInfo.length == 0) {
instrumentDOM.querySelector(".instrument-error").style.display = "flex";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "none";
}
} else {
instrumentDOM.querySelector(".instrument-error").style.display = "none";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "grid";
}
for (let i=0; i<axesInfo.length && i<4; i++) {
oscillatorAxes[i].dataset.sliderActive = '1';
let axisSliderValue = 50;
document.querySelector(':root').style.setProperty(`--axis${i}-percent`, `${axisSliderValue/100}`);
}
if (playerState == false) {
playerState = true;
oscillatorLoop();
}
}
}
if (activeInstrument == 'sequencer') {
// Initalize all axes to not show
let sequencerAxes = instrumentDOM.querySelectorAll(".sequencer-beats-axis");
sequencerAxes[0].dataset.sequencerAxisActive = '0';
sequencerAxes[1].dataset.sequencerAxisActive = '0';
sequencerAxes[2].dataset.sequencerAxisActive = '0';
sequencerAxes[3].dataset.sequencerAxisActive = '0';
// Reset sound setting
sequencerSound = 0;
// Randomize display text
let displayText = instrumentDOM.querySelector(`.instrument-display-text`);
displayText.innerText = randomSentence();
// Make sure current speed toggle is active
let speedToggle = instrumentDOM.querySelector(`[data-sequencer-speed="${sequencerSpeed}"]`);
document.querySelector(':root').style.setProperty(`--player-variation-speed`, `${sequencerSpeed*.95}ms`);
speedToggle.dataset.buttonState = "1";
// Check if font is actually variable and show correct controls
if (axesInfo.length == 0) {
instrumentDOM.querySelector(".instrument-error").style.display = "flex";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "none";
}
} else {
instrumentDOM.querySelector(".instrument-error").style.display = "none";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "grid";
}
for (let i=0; i<axesInfo.length && i<4; i++) {
sequencerAxes[i].dataset.sequencerAxisActive = '1';
}
if (playerState == false) {
playerState = true;
sequencerLoop();
}
}
}
if (activeInstrument == 'scrambler') {
// Reset sound setting
scramblerSound = 0;
// Randomize display text
let displayText = instrumentDOM.querySelector(`.instrument-display-text`);
displayText.innerText = randomSentence();
displayText.innerHTML = wrapLetters(displayText.innerText);
// Make sure current speed toggle is active
let speedToggle = instrumentDOM.querySelector(`[data-scrambler-speed="${scramblerSpeed}"]`);
document.querySelector(':root').style.setProperty(`--player-variation-speed`, `${scramblerSpeed*.95}ms`);
speedToggle.dataset.buttonState = "1";
// Check if font is actually variable and show correct controls
if (axesInfo.length == 0) {
instrumentDOM.querySelector(".instrument-error").style.display = "flex";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "none";
}
} else {
instrumentDOM.querySelector(".instrument-error").style.display = "none";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "grid";
}
if (playerState == false) {
playerState = true;
scramblerLoop();
}
}
}
if (activeInstrument == 'conversator') {
// Set transition to 50ms
document.querySelector(':root').style.setProperty(`--player-variation-speed`, `50ms`);
// Randomize display text
let displayText = instrumentDOM.querySelector(`.instrument-display-text`);
displayText.innerText = randomSentence();
// Initalize all axes sliders and toggles to not show
let conversatorAxes = instrumentDOM.querySelectorAll(".instrument-slider-container");
conversatorAxes[0].dataset.sliderActive = '0';
conversatorAxes[1].dataset.sliderActive = '0';
conversatorAxes[2].dataset.sliderActive = '0';
conversatorAxes[3].dataset.sliderActive = '0';
let conversatorAxesToggles = instrumentDOM.querySelectorAll("[data-button-group='conversator-axes'] button");
conversatorAxesToggles[0].dataset.conversatorAxisActive = '0';
conversatorAxesToggles[1].dataset.conversatorAxisActive = '0';
conversatorAxesToggles[2].dataset.conversatorAxisActive = '0';
conversatorAxesToggles[3].dataset.conversatorAxisActive = '0';
// Check if font is actually variable and show correct controls
if (axesInfo.length == 0) {
instrumentDOM.querySelector(".instrument-error").style.display = "flex";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "none";
}
} else {
instrumentDOM.querySelector(".instrument-error").style.display = "none";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "grid";
}
for (let i=0; i<axesInfo.length && i<4; i++) {
conversatorAxes[i].dataset.sliderActive = '1';
conversatorAxesToggles[i].dataset.conversatorAxisActive = '1';
let axisSlider = instrumentDOM.querySelectorAll(`[data-conversator-axis="${i}"]`)[1];
let axisSliderValue = axisSlider.dataset.sliderValue;
document.querySelector(':root').style.setProperty(`--axis${i}-percent`, `${axisSliderValue/100}`);
}
if (playerState == false) {
playerState = true;
conversatorActivate();
}
}
}
if (activeInstrument == 'alphabetizer') {
// Set transition to instant
document.querySelector(':root').style.setProperty(`--player-variation-speed`, `unset`);
// Set initial display letter
alphabetizerLetterSet("A");
// Initalize all axes to not show
let alphabetizerAxes = instrumentDOM.querySelectorAll(".instrument-slider-container");
alphabetizerAxes[0].dataset.sliderActive = '0';
alphabetizerAxes[1].dataset.sliderActive = '0';
alphabetizerAxes[2].dataset.sliderActive = '0';
alphabetizerAxes[3].dataset.sliderActive = '0';
// Make sure current speed toggle is active
let speedToggle = instrumentDOM.querySelector(`[data-alphabetizer-speed="${alphabetizerSpeed}"]`);
document.querySelector(':root').style.setProperty(`--player-variation-speed`, `${alphabetizerSpeed*.95}ms`);
speedToggle.dataset.buttonState = "1";
// Check if font is actually variable and show correct controls
if (axesInfo.length == 0) {
instrumentDOM.querySelector(".instrument-error").style.display = "flex";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "none";
}
} else {
instrumentDOM.querySelector(".instrument-error").style.display = "none";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "grid";
}
for (let i=0; i<axesInfo.length && i<4; i++) {
alphabetizerAxes[i].dataset.sliderActive = '1';
let axisSliderValue = 50;
document.querySelector(':root').style.setProperty(`--axis${i}-percent`, `${axisSliderValue/100}`);
}
// Start loop
if (playerState == false) {
playerState = true;
alphabetizerLoopStart();
}
}
}
if (activeInstrument == 'analyzer') {
// Set transition to instant
document.querySelector(':root').style.setProperty(`--player-variation-speed`, `unset`);
// Randomize display text
let displayText = instrumentDOM.querySelector(`.instrument-display-text`);
displayText.innerText = randomSentence();
// Set zoom to default
let display = instrumentDOM.querySelector(".analyzer-display");
display.dataset.analyzerZoom = 0;
// Initalize all axes to not show
let analyzerAxes = instrumentDOM.querySelectorAll(".instrument-slider-container");
analyzerAxes[0].dataset.sliderActive = '0';
analyzerAxes[1].dataset.sliderActive = '0';
analyzerAxes[2].dataset.sliderActive = '0';
analyzerAxes[3].dataset.sliderActive = '0';
// Check if font is actually variable and show correct controls
if (axesInfo.length == 0) {
instrumentDOM.querySelector(".instrument-error").style.display = "flex";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "none";
}
} else {
instrumentDOM.querySelector(".instrument-error").style.display = "none";
for (let control of instrumentDOM.querySelectorAll(".instrument-function")) {
control.style.display = "grid";
}
for (let i=0; i<axesInfo.length && i<4; i++) {
analyzerAxes[i].dataset.sliderActive = '1';
let axisSliderValue = 50;
document.querySelector(':root').style.setProperty(`--axis${i}-percent`, `${axisSliderValue/100}`);
}
}
}
}
// —————————————————————————————————————————————————————————————————————
// GENERIC UI FUNCTIONS
// —————————————————————————————————————————————————————————————————————
// Initalize all state-enabled buttons to show the correct value
for (let button of document.querySelectorAll(".instrument-state")) {
instrumentStateUpdate(button)
}
// Button with multiple states
let instrumentStateNotes = ['C3','D3','E3','F3','G3','A3','B3'];
function instrumentStatePress(e) {
let fill = e.querySelector(".instrument-state-fill");
let currentState = parseInt(e.dataset.stateValue);
let maxState = parseInt(e.dataset.stateMax);
currentState++;
if (currentState > maxState) {
currentState = 0;
}
e.dataset.stateValue = (currentState).toString();
let percentFill = currentState/maxState;
fill.style.width = percentFill*100 + "%";
fill.style.height = percentFill*100 + "%";
playBlock(instrumentStateNotes[currentState]);
}
// Update button state to match current value
function instrumentStateUpdate(e) {
let fill = e.querySelector(".instrument-state-fill");
let currentState = parseInt(e.dataset.stateValue);
let maxState = parseInt(e.dataset.stateMax);
let percentFill = currentState/maxState;
fill.style.width = percentFill*100 + "%";
fill.style.height = percentFill*100 + "%";
}
// Group of toggles with one active option
function instrumentButtonGroupPress(e, group) {
let parent = document.querySelector(`[data-button-group='${group}']`);
let groupType = parent.dataset.buttonGroupType;
let groupMembers = document.querySelectorAll(`[data-button-group='${group}'] button`);
if (groupType == "toggle") {
if (e.dataset.buttonState == "1") {
e.dataset.buttonState = "0";
} else {
for (let button of groupMembers) {
button.dataset.buttonState = "0";
}
e.dataset.buttonState = "1";
}
} else if (groupType == "set") {
for (let button of groupMembers) {
button.dataset.buttonState = "0";
}
e.dataset.buttonState = "1";
} else if (groupType == "multiple") {
if (e.dataset.buttonState == "1") {
e.dataset.buttonState = "0";
} else {
e.dataset.buttonState = "1";
}
}
}
// Sliders
let activeSlider;
let activeSliderAxis;
function instrumentSlider(slider, axis) {
activeSlider = slider;
activeSliderAxis = axis;
instrumentSliderSet();
document.onmousemove = instrumentSliderSet;
document.onmouseup = instrumentSliderStop;
}
function instrumentSliderSet() {
let e = window.event;
e.preventDefault();
let mousePos = e.clientY;
let sliderHeight = activeSlider.offsetHeight - 8;
let sliderTop = activeSlider.getBoundingClientRect().top + 4;
let sliderCalc = (-((mousePos-sliderTop)/sliderHeight)+1)*100;
if (sliderCalc < 1) {
activeSlider.dataset.sliderValue = "0";
} else if (sliderCalc > 100) {
activeSlider.dataset.sliderValue = "100";
} else {
activeSlider.dataset.sliderValue = sliderCalc;
}
document.querySelector(':root').style.setProperty(`--axis${activeSliderAxis}-percent`, `${activeSlider.dataset.sliderValue/100}`);
// Play synth
if (activeSliderAxis == 0) {
playMono0(130+(activeSlider.dataset.sliderValue/100)*130);
} else if (activeSliderAxis == 1) {
playMono1(165+(activeSlider.dataset.sliderValue/100)*165);
} else if (activeSliderAxis == 2) {
playMono2(196+(activeSlider.dataset.sliderValue/100)*196);
} else if (activeSliderAxis == 3) {
playMono3(262+(activeSlider.dataset.sliderValue/100)*262);
}
}
function instrumentSliderStop() {
document.onmouseup = null;
document.onmousemove = null;
}
// Prevent formatting on content paste
let instrumentDisplays = document.querySelectorAll("[contenteditable='true']")
for (let instrument of instrumentDisplays) {