-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
146 lines (115 loc) · 3.58 KB
/
settings.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
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
console.log("hi")
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
function updateGain(){
//console.log(document.getElementById("gainSlider").value)
gain.gain.value = document.getElementById("gainSlider").value
}
function updateRainbowSpeed(){
movingRainbowSpeed = document.getElementById("rainbowSpeed").value
//console.log(movingRainbowSpeed)
}
function getRadioValue(name){
var radios = document.getElementsByName(name);
var radioValue;
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
// do whatever you want with the checked radio
return radios[i].value;
// only one radio can be logically checked, don't check the rest
}
}
}
function updateColoring(){
barColor = document.getElementById("singleColor").value;
currentColor = getRadioValue("coloring");
if(currentColor == undefined){
currentColor = "rainbow"
}
updateRainbowMode()
}
function updateRainbowMode(){
if(currentColor == "rainbow"||currentColor == "movingRainbow"||currentColor == "verticalRainbow"||currentColor == "movingVerticalRainbow" )
if(document.getElementById("rainbowMoving").checked && !document.getElementById("rainbowVertical").checked){
currentColor = "movingRainbow";
}else if(document.getElementById("rainbowMoving").checked && document.getElementById("rainbowVertical").checked){
currentColor = "movingVerticalRainbow";
}else if(!document.getElementById("rainbowMoving").checked && document.getElementById("rainbowVertical").checked){
currentColor = "verticalRainbow";
}else if(!document.getElementById("rainbowMoving").checked && !document.getElementById("rainbowVertical").checked){
currentColor = "rainbow"
}
}
function updateSingleColor(){
barColor = document.getElementById("singleColor").value;
if(barColor == undefined){
barColor = "#ff00ff"
}
}
function updateStyle(){
currentStyle = getRadioValue("style");
if(currentStyle == undefined){
currentStyle = "circleMode"
showDisabledBlocks = true; //enable because it looks better :)
}
}
function updateBackgroundColor(){
backgroundColor = document.getElementById("backgroundColor").value;
if(backgroundColor == ""){
backgroundColor = "#000000"
}
generateSquares()
}
function updateOffBlocks(){
showDisabledBlocks = document.getElementById("offBlocks").checked
if(showDisabledBlocks == undefined){
showDisabledBlocks = true;
}
}
function updateLineModeFilled(){
lineModeFilled = document.getElementById("lineModeFilled").checked
}
function changeBarCount(){
var count = parseInt(document.getElementById("barCount").value)
function power_of_2(n) {
if (typeof n !== 'number'){
return false;
}
return n && (n & (n - 1)) === 0;
}
if(power_of_2(count)&&count>=16){
barCount = count;
fftSize = count *2;
barCount-= rightBarCutoff;
analyser.fftSize = fftSize;
generateSquares()
generateRainbow();
}
}
window.onload = function(){
changeBarCount()
updateOffBlocks()
updateBackgroundColor()
updateColoring()
updateLineModeFilled()
updateSingleColor()
updateStyle()
}