// Mod50_13_1 // Red line is a streched spring, originally of 0 length // end of spring is the targetY when mouse is released // By Zsofia Ruttkay - 28.2.2009 float stiffness = 0.1; float damping = 0.9; float velocity = 0.0; float targetY; float y; void setup() { size(100, 100); noStroke(); } void draw() { background(0); fill(255); float force = stiffness * (targetY - y); // f = -kx velocity = damping * (velocity + force); y += velocity; noStroke(); rect(10, y, width - 20, 12); stroke(255,0,0); strokeWeight(3); if (mousePressed) line(width/2,y, width/2, mouseY); else line(width/2,y, width/2, targetY); } void mouseDragged() { stroke(255,0,0); strokeWeight(3); line(width/2,y, width/2, mouseY); } void mouseReleased() { targetY=mouseY; } void keyPressed() { if (key =='s') save("Mod50_13_1.jpg"); }