-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmusic_remember.js
executable file
·84 lines (72 loc) · 1.76 KB
/
music_remember.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
let old_loudest = 0;
// vocal, drum, bass, and other are volumes ranging from 0 to 100
function draw_one_frame(words, vocal, drum, bass, other) {
background(20);
rectMode(CENTER);
textAlign(CENTER);
textSize(40);
let bar_spacing = width/5;
let bar_pos_y = 2*height/3;
let loudest = 0; // loudest should be 1, 2, 3, 4 (which of the 4 channels is strongest)
//
if(vocal > drum && vocal > bass && vocal > other) {
loudest = 1;
}
else if(drum > vocal && drum > bass && drum > other) {
loudest = 2;
}
else if(bass > vocal && bass > drum && bass > other) {
loudest = 3;
}
else {
loudest = 4;
}
if(loudest == old_loudest) {
background(20);
}
else if(loudest == 1) {
background(200, 0, 0);
}
else if(loudest == 2) {
background(0, 200, 0);
}
else if(loudest == 3) {
background(0, 0, 200);
}
else {
background(200, 200, 200);
}
old_loudest = loudest;
// by default all bars are skinny
let bar_width1 = width/12;
let bar_width2 = width/12;
let bar_width3 = width/12;
let bar_width4 = width/12;
// but make the loudest section fatter
if(loudest == 1) {
bar_width1 = width/5;
}
else if(loudest == 2) {
bar_width2 = width/5;
}
else if(loudest == 3) {
bar_width3 = width/5;
}
else {
bar_width4 = width/5;
}
fill(200, 200, 0);
text(words, width/2, height/3);
// vocal bar is red
fill(200, 0, 0);
rect(1 * bar_spacing, bar_pos_y, bar_width1, 4 * vocal);
// drum bar is green
fill(0, 200, 0);
rect(2 * bar_spacing, bar_pos_y, bar_width2, 4 * drum);
// bass bar is blue
fill(0, 0, 200);
rect(3 * bar_spacing, bar_pos_y, bar_width3, 4 * bass);
// other bar is white
fill(200, 200, 200);
rect(4 * bar_spacing, bar_pos_y, bar_width4, 4 * other);
}