-
Notifications
You must be signed in to change notification settings - Fork 7
/
Twinkle.pde
45 lines (35 loc) · 1.2 KB
/
Twinkle.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
// Take all the functions and variables from the Effects class
class Twinkle extends Effect{
// Which noise x-position to start at
int[] noiseID;
// speed that this ID will move through
float[] noiseSpeed;
// sets the color of this effect
color baseColor;
Twinkle(int _millis, color _c){
// run the all of the commands from the Effects parent class
super(_millis);
baseColor = _c;
noiseID = new int[LEDCount];
noiseSpeed = new float[LEDCount];
for(int i=0;i<noiseID.length;i++){
noiseID[i] = round(random(0,LEDCount));
noiseSpeed[i] = random(.015, .035);
}
}
void update(){
// do any commands in the Effect class update function
imageBuffer.beginDraw();
// create the pixel array
imageBuffer.loadPixels();
super.update();
for(int i=0; i<noiseID.length; i++){
// get the grayscale amount for the noise
float noiseAmount = noise(noiseID[i], frameCount* noiseSpeed[i]) * 255;
imageBuffer.pixels[i] = color(red(baseColor), green(baseColor), blue(baseColor), noiseAmount);
}
// load the pixel array into the buffer
imageBuffer.updatePixels();
imageBuffer.endDraw();
}
}