/* This sketch demonstrates toggling of a Boolean variable to allow the user to switch between two views with a mouse click. Processing Sketch by Michael Goldwasser */ int W = 300; // actual width of canvas boolean daytime = true; color nightsky = color(25, 25, 112); color daysky = color(135, 206, 235); void setup() { size(300, 200); drawDaytime(); // start with daytime scene before first mouse click } void draw() { // nothing done here. All drawing done in response to mouse press } void mousePressed() { if (daytime) { daytime = false; drawNighttime(); } else { daytime = true; drawDaytime(); } } void drawDaytime() { background(daysky); // sun noStroke(); fill(255, 255, 0); ellipse(250, 50, 30, 30); // sunrays strokeWeight(3); stroke(255, 255, 0); line(230, 70, 215, 85); line(270, 70, 285, 85); line(270, 30, 285, 15); line(230, 30, 215, 15); strokeWeight(1); drawCommon(); } void drawNighttime() { background(nightsky); // draw a skyfull of stars that twinkle with each draw stroke(255); for (int j=0; j < 100; j++) { point(random(300), random(110)); } // moon noStroke(); fill(180, 200, 220); ellipse(250, 50, 30, 30); fill(nightsky); ellipse(260, 50, 30, 30); // mask to leave cresent shape drawCommon(); // include the common stuff } // this includes all of the stuff that is common to day and night void drawCommon() { // grass fill(0, 255, 0); stroke(0, 255, 0); strokeWeight(1); rect(0, 120, 300, 80); // tree stroke(0); fill(0, 100, 0); triangle(50, 80, 30, 140, 70, 140); // house facade fill(255); rect(110, 100, 60, 60); // house roof fill(127); quad(105, 105, 175, 105, 170, 85, 110, 85); // chimney stroke(255, 0, 0); fill(255, 0, 0); rect(148, 72, 15, 28); // window fill(0); strokeWeight(2); rect(123, 110, 15, 20); }