Permalink
Browse files

added starField effect

  • Loading branch information...
1 parent 1a7d02c commit 58fdffb9cd6147ebc3c4bb6d56f41c2ccf3f85ba @mhenstell committed Aug 22, 2011
Showing with 51 additions and 1 deletion.
  1. +51 −1 acw.pde
View
52 acw.pde
@@ -27,7 +27,8 @@ String[] enabledModes = new String[] {
// "drawSpin",
// "drawAnimation",
// "drawWaves",
- "drawMovie"
+ // "drawMovie"
+ "drawStarField"
};
String messages[] = new String[] {
@@ -50,6 +51,7 @@ PFont font;
int ZOOM = 1;
int NUMBER_OF_STARS = 30;
Star[] stars;
+RadialStar[] radialStars;
int NUMBER_OF_BURSTS = 4;
Burst[] bursts;
@@ -84,6 +86,11 @@ void setup() {
for (int i=0; i<NUMBER_OF_STARS; i++) {
stars[i] = new Star(i*1.0/NUMBER_OF_STARS*ZOOM);
}
+
+ radialStars = new RadialStar[NUMBER_OF_STARS];
+ for (int i=0; i<NUMBER_OF_STARS; i++) {
+ radialStars[i] = new RadialStar();
+ }
bursts = new Burst[NUMBER_OF_BURSTS];
for (int i = 0; i<NUMBER_OF_BURSTS; i++) {
@@ -242,6 +249,18 @@ void drawStars() {
}
}
+void drawStarField() {
+ background(0);
+
+ for (int i=0; i<NUMBER_OF_STARS; i++) {
+ radialStars[i].draw();
+ }
+
+ if (frameCount - modeFrameStart > FRAMERATE*TYPICAL_MODE_TIME) {
+ newMode();
+ }
+}
+
void drawFlash() {
long frame = frameCount - modeFrameStart;
@@ -444,6 +463,37 @@ void drawMovie() {
*
**/
+class RadialStar {
+ float x;
+ float y;
+ float theta;
+ float v;
+
+ public RadialStar() {
+ this.reset();
+ }
+
+ public void draw() {
+ x = x + (v * cos(theta));
+ y = y + (v * sin(theta));
+
+ noStroke();
+ fill(255);
+ rect(x, y, 1, 1);
+
+ if ((x > WIDTH || x < 0) || (y > HEIGHT || y < 0)) this.reset();
+
+ }
+
+ public void reset() {
+ x = 7;
+ y = 7;
+ theta = random(0, 2 * PI);
+ v = random(0.05, 1);
+ }
+
+}
+
class Star {
float x;
float y;

0 comments on commit 58fdffb

Please sign in to comment.