18. November 2010
![](../../../../files/2010/11/Bildschirmfoto-2010-11-17-um-21.44.57-300x194.png)
PVector startPos = new PVector(); PVector endPos = new PVector(); int curTime = 0; int animSpeed = 10; int animTime = 2000; boolean drawFlag=false; void setup() { size(640, 480); smooth(); } void draw() { background(51); // calc. the anim time curTime += animSpeed; if(curTime >= animTime || curTime < 0) //curTime = 0; animSpeed=animSpeed*-1; // calc. the current time in the animation float normTime = curTime * 1.0 / animTime; 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() { drawFlag = true; curTime = 0; startPos.set(mouseX,mouseY,0); endPos = startPos.get(); } void mouseDragged() { endPos.set(mouseX,mouseY,0); } void mouseReleased() { drawFlag = true; println("released"); }
PVector startPos = new PVector(); PVector endPos = new PVector(); int curTime = 0; int animSpeed = 10; int animTime = 2000; boolean drawFlag=false; boolean secondClick=false; void setup() { size(640, 480); smooth(); } void draw() { background(51); // calc. the anim time curTime += animSpeed; if(curTime >= animTime || curTime < 0) //curTime = 0; animSpeed=animSpeed*-1; // calc. the current time in the animation float normTime = curTime * 1.0 / animTime; 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(!secondClick) { startPos.set(mouseX,mouseY,0); secondClick=true; drawFlag = false; } else { endPos.set(mouseX,mouseY,0); secondClick=false; drawFlag = true; } curTime = 0; } /*void mouseDragged() { endPos.set(mouseX,mouseY,0); } void mouseReleased() { drawFlag = true; println("released"); } */