-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrands.pde
140 lines (112 loc) · 3.31 KB
/
strands.pde
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
class Strands {
int strandNumber = 10;
ArrayList<Strand> strandArr = new ArrayList<Strand>();
ArrayList<Strand> hitStrands = new ArrayList<Strand>();
int currentStrand;
boolean isFlashing = false;
int lastFlash = 0;
int flashInterval = 3000;
int flashDuration = 300;
Song song;
PApplet parent;
Strands(PApplet theParent) {
parent = theParent;
int i = 0;
while (i < strandNumber) {
strandArr.add(new Strand(randomCurveCoordinates(), parent));
i++;
}
song = new Song(parent, new ArrayList<float[]>());
}
void update() {
int now = millis();
// if is flashing and has been doing so for the last 2000ms, stop flashing
if (isFlashing == true && now - lastFlash > flashDuration * strandNumber) {
strand(currentStrand).deactivate();
isFlashing = false;
currentStrand = -1;
}
// if is not flashing and hasn't done so in 2000ms, start flashing
if (isFlashing == false &&
(now - lastFlash > flashInterval) &&
(isFinished() == false)) {
lastFlash = now;
isFlashing = true;
currentStrand = randomStrandIndex();
strand(currentStrand).activate();
}
}
void draw() {
renderRemainingStrands();
noFill();
if (isFlashing && strandArr.size() > 0) {
strand(currentStrand).draw();
}
for (Strand hitStrand : hitStrands) {
hitStrand.draw();
}
song.play();
}
void renderRemainingStrands() {
int i = 0;
int len = strandArr.size();
int width = 25;
for (i = 0; i < len; i += 1) {
noStroke();
//stroke(255);
fill(255, random(255), random(255));
ellipse(i * (width + 10) + width, width + 10, width, width);
}
}
void hit() {
hitStrands.add(strand(currentStrand));
strand(currentStrand).deactivate();
song.addSheetToSheet(strand(currentStrand).sheet());
strandArr.remove(currentStrand);
strandNumber -= 1;
currentStrand = -1;
isFlashing = false;
}
int randomStrandIndex() {
if (strandArr.size() < 1) {
return -1;
}
return int(random(strandNumber));
}
Strand strand(int index) {
if (index < 0) {
return null;
}
return strandArr.get(index);
}
Strand hitStrand() {
if (hitStrands.size() < 1) {
return null;
}
int index = int(random(hitStrands.size()));
return hitStrands.get(index);
}
float[] randomCurveCoordinates() {
float[] coordinates = {
random(width), random(height),
random(width), random(height),
random(width), random(height),
random(width), random(height)
};
return coordinates;
}
boolean isFinished() {
return strandArr.size() < 1;
}
void destroy() {
song.pause();
}
void distortHitStrand(int amount) {
Strand strand = hitStrand();
if (strand == null) {
return;
}
amount = random(10) > 6 ? amount * -1 : amount;
strand.distort(amount);
}
}