forked from dcheesman/LEDStripController
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flashes.pde
58 lines (48 loc) · 1 KB
/
Flashes.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
class Flashes extends Effect{
ArrayList <Flash> flashes;
Flashes(int _millis){
super(_millis);
flashes = new ArrayList();
}
void update(){
super.update();
// make a new flash every frame
Flash newF = new Flash();
flashes.add(newF);
// clear out finished flashes. Update the others
for(int i=flashes.size()-1; i>=0; i--){
Flash f = flashes.get(i);
if(f.isDead()){
flashes.remove(i);
} else {
f.update();
imageBuffer.beginDraw();
// load buffer's pixels in to pixel[] array
imageBuffer.loadPixels();
imageBuffer.pixels[f.id] = color(f.value);
// load pixel[] array back into image
imageBuffer.updatePixels();
imageBuffer.endDraw();
}
}
}
// starts a pixel at 255 brightness. Fade to zero
class Flash{
int id;
float value;
float dimSpeed = .90;
Flash(){
id = floor(random(LEDCount));
value = 255;
}
void update(){
value *= dimSpeed;
}
boolean isDead(){
if(value < 1){
return true;
}
return false;
}
}
}