class Animator {
PVector startPos = new PVector();
PVector endPos = new PVector();
int
}
}
class Animator {
constructor(x, y){
this.drawFlag = true;
this.curTime = 0;
curTimethis.startPos = createVector(x,y,0);
int this.endPos= this.startPos;
this.animSpeed = 5;
int this.animDuration = 2000;
boolean drawFlag=false;
boolean this.animEndFlag = false;
Animator(int X, int Y) {
drawFlag = true;
curTime = 0;
startPos.set(X, Y, 0);
endPos = startPos.get();
}
void endClick(int X, int Y) {
this.endPos.set(X, Y, 0);
}
void drawAnimator() {
// calc. the anim time
if (this.curTime >= this.animDuration) {
this.animEndFlag = true;
}
if (this.curTime <= 0) {
this.animEndFlag = false;
}
if (this.animEndFlag) {
this.curTime -= this.animSpeed;
} else {
this.curTime += this.animSpeed;
}
// calc. the proportion of completion in the animation
floatvar normTime = this.curTime * 1.0 / this.animDuration;
if (this.drawFlag)
{
line(this.startPos.x, this.startPos.y,
this.endPos.x, this.endPos.y);
// calculate the position of the circle on the line
PVectorlet dir = PVectorp5.Vector.sub(this.endPos, this.startPos);
PVectorlet pos = PVectorp5.Vector.add( this.startPos, PVectorp5.Veector.mult(dir, normTime));
ellipse(pos.x, pos.y, 20, 20);
}
}
} |