/* amy martin water clock, part one, storm clock interactive seminar • chris noessel cca 2009 minutes display as dark shadows at the bottom of the screen. halfway across is 30 minutes. at the top of the minute, lightning strikes and then the thunder hits at the second that equals to the same number as the hour (so if you count one-onethousand, two-onethousand, etc, you can guess the hour) */ import ddf.minim.*; Minim thunderMinim, moreRainMinim; AudioPlayer thunder, moreRain; Animation animationKite, animationTree; int disp_hour = hour()%12; boolean firstpress; int q = 0; int millisOff; int s = second(); float xpos, ypos; void setup(){ firstpress = false; size(600,360); while(s == second()); millisOff = millis(); animationKite = new Animation ("kite_0", 4); // kite animation animationTree = new Animation ("tree_0", 4); // tree animation thunderMinim = new Minim(this); thunder = thunderMinim.loadFile("thunder.wav"); // load thunder moreRainMinim = new Minim(this); moreRain = moreRainMinim.loadFile("moreRain.wav"); // load more rain frameRate(10); } void draw(){ background(9,19,55); noStroke(); fill(0); int sec = second(); animationKite.display(389,9); // kite GO animationTree.display(0,0); // kite GO moreRain.play(); // more background rain GO // set rain height variables int ms = (millis() - millisOff)%1000; float rainY = map (ms, 0, 1000, 0, 350); // make random rain for (float q = 0; q < 600; q = q + random(30)) { rect (q, rainY + random(350), 1, 10); } for (float q = 0; q < 600; q = q + random(30)) { rect (q, rainY - random(350), 1, 10); } // set lightning strikes for each minute if (sec == 59) { PImage strikeB; strikeB = loadImage("bg_lightning_strike.jpg"); background(strikeB); } // set thunder to represent the hour by playing after the hour's number // in seconds, so it will be like counting between the lightning and // the thunder to tell how far away the storm is, except it's just telling // the hour... have to set millis too or the sample will try to start over // the entire second and it sounds like a firing squad int secondsIntoHours = hour()%12; if (sec == secondsIntoHours && ms < 100) { thunder.play(); } // set moving ground for the minutes int m = minute(); if (sec != 59) { for (int p = 0; p < m; p = p + 1) { fill(0,200); noStroke(); smooth(); rect ((10*p) + random(5), 340 + random(5), 10, 35); } } } void stop() { thunder.close(); moreRain.close(); moreRainMinim.stop(); thunderMinim.stop(); super.stop(); }