Permalink
Browse files

Merge branch 'master' of github.com:hackrockcity/domeTransmitter

  • Loading branch information...
2 parents d440b54 + a3b4290 commit a26bcf2c28267d9e6bc5f15e3fe0dce37543d4ce @potatono potatono committed May 16, 2012
Showing with 94 additions and 0 deletions.
  1. +60 −0 NightSky.pde
  2. +33 −0 NightStar.pde
  3. +1 −0 domeTransmitter.pde
View
60 NightSky.pde
@@ -0,0 +1,60 @@
+class NightSky extends Routine {
+ int NUMBER_OF_STARS = 30;
+ NightStar[] nightStars;
+ PImage grad;
+
+ void setup(PApplet parent) {
+ super.setup(parent);
+
+ color c1 = color(0, 0, 20);
+ color c2 = color(0, 20, 60);
+ grad = generateGradient(c1, c2, WIDTH*ZOOM, HEIGHT*ZOOM);
+
+ nightStars = new NightStar[NUMBER_OF_STARS];
+ for (int i=0; i<NUMBER_OF_STARS; i++) {
+ nightStars[i] = new NightStar();
+ }
+ }
+
+ void draw() {
+ background(0);
+ image(grad, 0, 0);
+ noStroke();
+ fill(0, 20, 0);
+ rect(0, HEIGHT*ZOOM * 0.7, WIDTH*ZOOM, HEIGHT*ZOOM * 0.3);
+ for (int i=0; i<NUMBER_OF_STARS; i++) {
+ nightStars[i].draw();
+ }
+
+ if (frameCount - modeFrameStart > FRAMERATE*TYPICAL_MODE_TIME) {
+ newMode();
+ }
+ }
+
+ // Generate a vertical gradient image
+ PImage generateGradient(color top, color bottom, int w, int h) {
+ int tR = (top >> 16) & 0xFF;
+ int tG = (top >> 8) & 0xFF;
+ int tB = top & 0xFF;
+ int bR = (bottom >> 16) & 0xFF;
+ int bG = (bottom >> 8) & 0xFF;
+ int bB = bottom & 0xFF;
+
+ PImage bg = createImage(w,h,RGB);
+ bg.loadPixels();
+ for(int i=0; i < bg.pixels.length; i++) {
+ int y = i/bg.width;
+ float n = y/(float)bg.height;
+ // for a horizontal gradient:
+ // float n = x/(float)bg.width;
+ bg.pixels[i] = color(
+ lerp(tR,bR,n),
+ lerp(tG,bG,n),
+ lerp(tB,bB,n),
+ 255);
+ }
+ bg.updatePixels();
+ return bg;
+ }
+}
+
View
33 NightStar.pde
@@ -0,0 +1,33 @@
+class NightStar {
+ float x;
+ float y;
+ int brightness;
+ public NightStar() {
+ this.reset();
+ }
+
+ public void draw() {
+
+ noStroke();
+ this.twinkle();
+ fill(brightness);
+ rect(x, y, 1, 1);
+
+ }
+
+ public void twinkle() {
+ brightness = brightness + round(random(-20, 20));
+ if(brightness > 255){
+ brightness = 255;
+ }
+ }
+
+ public void reset() {
+ x = random(WIDTH*ZOOM);
+ y = random(HEIGHT*ZOOM) * 0.7;
+ println("New star " + x + "/" + y + " ");
+ }
+
+}
+
+
View
1 domeTransmitter.pde
@@ -19,6 +19,7 @@ Routine[] enabledRoutines = new Routine[] {
new OppositeLines(),
new Waves(),
new RadialStars(),
+ new NightSky(),
new TargetScanner(),
new Waterfalls(),
new RGBRoutine(),

0 comments on commit a26bcf2

Please sign in to comment.