/* Rain1 Mod of Rain0 language construct: switch(), case The shape is defined by the sh variable, which is incremented by mousePress. For the shape of the drop alternatives are defined in drawDrap function. Depending on the sh integer variable the drwaDrop is called with, the shape will be: 0: single pixel 1: stroke of lenght long 2: ellipe of rx, ry radii (if rx=ry, we get circle) 3: own drop shape of circle + traingle cap 4: snow-flake Adding further cases in the drawDrop function, new shapes may be defined. Zs. Ruttkay 2.2.2009 using Processing 1.0.1 */ int x, y; // coordinates of the falling drop float speed=8; int ls=12; // lenght of rain stroke int thick =1; // thickness of rain stroke int rx =10; // ellipse x radius int ry = 10; // ellipse y radius, if x=y we get circle int sh = 1; // shape of drop void setup() { size(200, 200); stroke(255); // color of rain fill(255); // color of rain frameRate(30); x= width/2; y=0; strokeWeight(thick); } void mousePressed () { if (sh <4) sh++; else sh=1; } void draw() { background(0); updateDrop(); drawDrop (); } void updateDrop() { y+=speed; if(y > height) { y = 0; } } void drawDrop() { switch(sh) { // pixel case 0 : point(x, y); break; // stroke case 1 : line(x, y, x, y+ls); break; // ellipse // first two parameters specify the center of the ellipse case 2 : ellipse(x, y, rx, ry); break; // drop // here own drop shape may be defined, for now circle + traingle cap case 3 : ellipse(x, y, rx, ry); // below may not touch well teh circle - no trigonometry yet, just guessing triangle(x+rx/2, y-3, x-rx/2, y-3, x, y-6-ry); break; // here is a snow flake imitation case 4 : line(x, y-ls/2, x, y+ls/2); line(x-ls/2, y, x+ls/2, y); line(x-ls/4, y-ls/4, x+ls/4, y+ls/4); line(x-ls/4, y+ls/4, x+ls/4, y-ls/4); break; } } void keyPressed() { if (key == 's') { save("Rain1.jpg"); }