10. November 2010
I edited the patch by adding a start click without starting the animation -not before clicking the end point.PVector startPos = new PVector(); PVector endPos = new PVector(); int curTime = 0; int animSpeed = 5; int animTime = 2000; boolean drawFlag=false; boolean flagDir=true; //direction boolean pressedOnce=false; void setup() { size(640, 480); smooth(); } void draw() { curTime += animSpeed; background(51); // calc. the animation time //VARIANTE 1 /*if(curTime== animTime) flagDir=false; else if(curTime== 0) flagDir=true; if(!flagDir) curTime -= animSpeed; else curTime += animSpeed;*/ //VARIANTE 2 if(curTime==animTime || curTime==0) animSpeed*=-1; // calc. the current time in the animation float normTime = curTime * 1.0 / animTime; //prozentzahl von 0..1 ; if(drawFlag) { stroke(255); line(startPos.x,startPos.y, endPos.x,endPos.y); // calculate the position of the circle on the line PVector dir = PVector.sub(endPos,startPos); PVector pos = PVector.add( startPos, PVector.mult(dir,normTime)); ellipse(pos.x,pos.y, 20,20); } } void mousePressed() { if(pressedOnce) { endPos.set(mouseX,mouseY,0); curTime = 0; drawFlag=true; pressedOnce=false; } else { startPos.set(mouseX,mouseY,0); pressedOnce=true; drawFlag=false; } } void mouseDragged() { } void mouseReleased() { println("pressedOnce: " +pressedOnce +" | " + "drawFlag: "+drawFlag); }