Skip to content

Commit

Permalink
Adding Flashes class
Browse files Browse the repository at this point in the history
  • Loading branch information
dcheesman committed Jan 3, 2014
1 parent d61d475 commit 0ff7f27
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
build-tmp/
build-tmp/
*.sublime-project
*.sublime-workspace
58 changes: 58 additions & 0 deletions Flashes.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 = 90;
}

void update(){
value *= dimSpeed;
}

boolean isDead(){
if(value < 1){
return true;
}
return false;
}
}
}

0 comments on commit 0ff7f27

Please sign in to comment.