/**
a rotating mini-planet with a skyline by http://www.local-guru.net/blog
click on the planet to switch between day- and night-mode
*/
int[] h;
int[] w;
PImage[] night_houses;
PImage[] day_houses;
PGraphics bg_night;
PGraphics bg_day;
int mode = 0;
void setup() {
size(300, 300);
smooth();
h = new int[10];
w = new int[10];
night_houses = new PImage[10];
day_houses = new PImage[10];
for ( int i =0; i < h.length; i++) {
h[i] = int( random(5)) * 20 + 110;
w[i] = int( random(5)) * 20 + 110;
PGraphics tmp = createGraphics( w[i], h[i], P2D);
tmp.beginDraw();
tmp.background(0);
tmp.noStroke();
tmp.fill(255,255,0);
for( int wx = 0; wx +1 < w[i]/20 ; wx++) {
for( int wy = 0; wy < h[i]/20; wy++) {
if ( random( 100 ) > 70 ) {
tmp.rect( 10 + wx*20 , 10 + wy* 20, 10, 10 );
}
}
}
tmp.endDraw();
night_houses[i] = tmp;
PGraphics tmp2 = createGraphics( w[i], h[i], P2D);
tmp2.beginDraw();
tmp2.background(200);
tmp2.noStroke();
tmp2.fill(0);
for( int wx = 0; wx +1 <= w[i]/20 ; wx++) {
for( int wy = 0; wy <= h[i]/20; wy++) {
tmp2.rect( 10 + wx*20 , 10 + wy* 20, 10, 10 );
}
}
tmp2.endDraw();
day_houses[i] = tmp2;
}
noStroke();
bg_night = createGraphics(300,300,P2D);
bg_night.beginDraw();
bg_night.background( 0 );
bg_night.noFill();
for( int i= 0; i < 800; i++) {
bg_night.stroke( 0, 0, map( i , 0, 800, 200, 50 ) );
bg_night.ellipse( width/2, height + 150, 300 + i, 300 + i );
}
bg_night.endDraw();
bg_day = createGraphics(300,300,P2D);
bg_day.beginDraw();
bg_day.background( 0 );
bg_day.strokeWeight(2);
bg_day.noFill();
for( int i= 0; i < 800; i++) {
bg_day.stroke( map( i , 0, 800, 255,0 ), map( i , 0, 800,255, 0 ), map( i , 0, 800, 255, 200 ) );
bg_day.ellipse( width/2, height + 150, 300 + i, 300 + i );
}
bg_day.endDraw();
}
void draw() {
image(mode == 0 ? bg_night : bg_day,0,0);
float a = TWO_PI/h.length;
float r1 = 200;
noStroke();
fill(0);
for ( int i =0; i < h.length; i++) {
pushMatrix();
translate( width/2, height + 150 );
rotate( a * i + float(frameCount) / 200);
translate( 0, -200);
image( mode == 0 ? night_houses[i] : day_houses[i], -w[i]/2, -h[i]);
popMatrix();
}
strokeWeight( 4 );
stroke( 100 );
fill( 50 );
ellipse( width/2, height + 150, 450, 450 );
}
public void mouseClicked() {
if ( mode == 0 ) {
mode = 1;
} else {
mode = 0;
}
}