-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimations.js
74 lines (72 loc) · 2.74 KB
/
animations.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
function doAnimations(){
for (let i = 0; i < animations.length; i++) {
const arrayBars = document.getElementsByClassName('array-bar');
setTimeout(() => {
if (animations[i] == "finished"){
doFinishAnimation()
}
}, i * animationSpeed);
if (animations[i] == "finished"){
break
}
const barOneIndex = animations[i][0]
const barTwoIndex = animations[i][1]
const barOneHeight = animations[i][2]
const barTwoHeight = animations[i][3]
setTimeout(() => {
arrayBars[barOneIndex].style.backgroundColor = SWAPCOLOR;
arrayBars[barTwoIndex].style.backgroundColor = SWAPCOLOR;
playNote(barTwoHeight, animationSpeed)
}, i * animationSpeed);
setTimeout(() => {
arrayBars[barOneIndex].style.height = `${barOneHeight}px`;
arrayBars[barTwoIndex].style.height = `${barTwoHeight}px`;
}, i * animationSpeed);
setTimeout(() => {
arrayBars[barOneIndex].style.backgroundColor = INITCOLOR;
arrayBars[barTwoIndex].style.backgroundColor = INITCOLOR;
}, i * animationSpeed + animationSpeed);
}
}
function doMergeAnimations(animations){
for (let i = 0; i < animations.length; i++) {
const arrayBars = document.getElementsByClassName('array-bar');
setTimeout(() => {
if (animations[i] == "finished"){
doFinishAnimation()
}
}, i * animationSpeed);
const isColorChange = i % 3 !== 2;
if (isColorChange) {
const [barOneIdx, barTwoIdx] = animations[i];
const barOneStyle = arrayBars[barOneIdx].style;
const barTwoStyle = arrayBars[barTwoIdx].style;
const color = i % 3 === 0 ? INITCOLOR : SWAPCOLOR;
setTimeout(() => {
barOneStyle.backgroundColor = color;
barTwoStyle.backgroundColor = color;
}, i * animationSpeed);
} else {
setTimeout(() => {
const [barOneIdx, newHeight] = animations[i];
const barOneStyle = arrayBars[barOneIdx].style;
barOneStyle.height = `${newHeight}px`;
}, i * animationSpeed);
}
}
}
function doFinishAnimation(){
const arrayBars = document.getElementsByClassName("array-bar")
for (let i = 0; i < arrayBars.length; i++){
setTimeout(() => {
arrayBars[i].style.backgroundColor = FINALCOLOR
barHeight = numberset[i]
playNote(barHeight, animationSpeed * 2)
}, i * animationSpeed * 2)
setTimeout(() => {
if (i == arrayBars.length - 1){
enableButtons()
}
}, i * animationSpeed * 2)
}
}