/** IsoBlox.pde Dave Bollinger, Sep 2006 http://www.davebollinger.com for Processing 0115 Beta (updated 08/16/2006 for 0125 Beta) CONTROLS: mouse -- click and drag to create blocks 1 2 3 4 5 -- select size range (smaller to larger, default 3) q w e r t -- select color range (pastel to saturated, default e) space -- clear entire screen z -- clear just z-buffer (for overlap effects) f -- toggle "fast" mode (no particle animation) */ // all the various particles live here: ArrayList movers; // our own zbuffer to make it workable even with the JAVA2D renderer // (could save some memory by hacking into and repurposing P3D's zbuffer) ZBuffer zbuffer; // range of sizes to create blocks int minSize = 3; int maxSize = 14; // if you spawn TOO frequently you'll potentially get weird zbuffer artifacts // when later/smaller boxes overtake earlier/larger boxes at the same mouse x/y.. int spawnFrequency = 4; // ..this setting gets around that problem by turning off the particle animation // by completely drawing an entire box during the frame that it's created, but // it also completely RUINS all the fun of watching the particle mechanism! :( boolean fastMode = false; // brightness and saturation float sat = 160f; float bri = 192f; void setup() { size(500,500); frameRate(60); zbuffer = new ZBuffer(width,height); movers = new ArrayList(); background(255); } void draw() { // spawn? if ((mousePressed) && (mouseButton==LEFT)) { if ((fastMode) || ((frameCount%spawnFrequency)==0)) { int xo = (int)((mouseX+4)/8) * 8; int yo = (int)((mouseY+2)/4) * 4; int zo = 0; int xd = int(random(minSize,maxSize))*2; int yd = int(random(minSize,maxSize))*2; int zd = int(random(minSize,maxSize))*2; movers.add(new IsoMaker(xo, yo, zo, xd, yd, zd, sat, bri)); } } // update do { for (int i=movers.size()-1; i>=0; i--) { Mover m = (Mover)movers.get(i); if (!m.move()) movers.remove(m); } } while ((fastMode) && (movers.size()>0)); } void keyPressed() { if (key=='`') saveFrame("frame.png"); if (key=='1') { minSize=1; maxSize=6; } if (key=='2') { minSize=2; maxSize=10; } if (key=='3') { minSize=3; maxSize=14; } if (key=='4') { minSize=4; maxSize=18; } if (key=='5') { minSize=5; maxSize=22; } if (key=='0') { minSize=1; maxSize=22; } // any size if (key=='q') { bri=255f; sat=32f; } if (key=='w') { bri=204f; sat=128f; } if (key=='e') { bri=160f; sat=192f; } if (key=='r') { bri=204f; sat=224f; } if (key=='t') { bri=255f; sat=255f; } if (key==' ') { movers.clear(); zbuffer.clear(); background(255); } if (key=='z') { zbuffer.clear(); } if (key=='f') { fastMode=!fastMode; } }