/** * sinusstem3 - stem as double sinusiod line, filled between sin(..) and sin()* sin() * mod of sinusstem2, now instead of lines we draw quads * Draw new one by mouseclick, also clean screen by any key press. * * By Zs Ruttkay on 18.2.2009 using processing 1.0.1 */ int dx=2; // size of pixels to forward on x int x, y; void setup() { size(400,400); background(255); strokeWeight(2); smooth(); noStroke(); x = width/2; y = height; noLoop(); } void draw () { //a* sin(x/b) to be drawn bewteen 0 and b*PI/2 int rx = 0; float ry=0, rdy=0; int leftright = int(random(0, 2)); // integer 0 or 1 if (leftright ==0) leftright-=1; // now leftright is -1 0r 1; float a = random(40, 400); //height of leaf float b = random(20, width/4); // width of leaf println(" leftright="+leftright +" a="+a +" b="+b); fill(random(0,255),random(0,255),random(0,255)); // colorful // fill(0, random(100,255), 0, random(150,200)); // green tints translate(x, y); // root will be (0, 0) while (abs(rx) <= b*PI/2-dx){ ry=sin(abs(rx)/b); rdy=sin((abs(rx) +dx)/b); if (leftright >0) { quad(rx, -a*ry, rx+dx, -a*rdy, rx+dx, -a*rdy*rdy, rx, -a*ry*ry); } else { quad(rx, -a*ry, rx-dx, -a*rdy, rx-dx, -a*rdy*rdy,rx, -a*ry*ry); } rx = rx +leftright*dx; } } void mousePressed() { x = width/2; y = height; redraw(); } void keyPressed() { if (key == 's') save("sinusstem3.jpg"); else { x = width/2; y = height; background(255); redraw(); } }