-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:hackrockcity/domeTransmitter
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
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 |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
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,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 + " "); | ||
} | ||
|
||
} | ||
|
||
|
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