Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hackrockcity/domeTransmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
potatono committed May 16, 2012
2 parents d440b54 + a3b4290 commit a26bcf2
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
60 changes: 60 additions & 0 deletions 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;
}
}

33 changes: 33 additions & 0 deletions 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 + " ");
}

}


1 change: 1 addition & 0 deletions domeTransmitter.pde
Expand Up @@ -19,6 +19,7 @@ Routine[] enabledRoutines = new Routine[] {
new OppositeLines(), new OppositeLines(),
new Waves(), new Waves(),
new RadialStars(), new RadialStars(),
new NightSky(),
new TargetScanner(), new TargetScanner(),
new Waterfalls(), new Waterfalls(),
new RGBRoutine(), new RGBRoutine(),
Expand Down

0 comments on commit a26bcf2

Please sign in to comment.