forked from dcheesman/LEDStripController
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
build-tmp/ | ||
build-tmp/ | ||
*.sublime-project | ||
*.sublime-workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |