/**
snow city - The day 18 door for my 2010 Advent calendar
by Guru
*/
PImage skyline;
PVector flakes[];
int FLAKES = 200;
void setup() {
size( 600, 300, P2D);
skyline = makeSkyline();
flakes = new PVector[FLAKES];
for ( int i =0; i < FLAKES; i++) {
flakes[i] = new PVector( random( width ), random( height ), random( 10 ));
}
frameRate( 25 );
smooth();
}
void draw() {
for (int h = 0; h < height; h++) {
stroke(0,0,map(h,0,height,255,0));
line( 0, height - h, width, height -h);
}
starfield();
image( skyline, 0,0 );
}
PImage makeSkyline() {
PGraphics g = createGraphics(600,300,P2D);
g.beginDraw();
for ( int i = 0; i < 15; i++) {
g.fill(0);
g.stroke(0);
float x = i * width / 15;
float w= int(random( 4 )) * 10 + 24;
float h = int(random( 15 )) * 10 + 50;
g.rect(x, g.height - h, w, h );
g.noStroke();
g.fill(255,255,0);
for( int wx = 0; wx +1 < w/10 ; wx++) {
for( int wy = 0; wy < h/10; wy++) {
if ( random( 100 ) > 70 ) {
g.rect( x + 5 + wx*10 , height - h + 5 + wy* 10, 5, 5 );
}
}
}
}
g.endDraw();
return g;
}
void keyPressed() {
skyline = makeSkyline();
}
void starfield() {
strokeWeight( 4 );
for ( int i =0; i < FLAKES; i++) {
stroke( flakes[i].z * 25);
point( flakes[i].x, flakes[i].y );
flakes[i].y += flakes[i].z;
if (flakes[i].y > height) {
flakes[i] = new PVector( random(width), 0, sqrt(random( 100 )));
}
}
}