Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
PVector     startPos = new PVector();
PVector     endPos = new PVector();
int         curTime = 0;
int         animSpeed = 255;
int         animTimeanimDuration = 2000;
boolean     pFlag1drawFlag=false;
boolean     pFlag2animEndFlag = false;
boolean     animDirclick1 = truefalse;
 

void setup()
{
  size(640, 480);
  smooth();
}

  
void draw()
{
  background(51);

  
  // calc. the anim time

  if(animDir (curTime >= animDuration) {
   curTime animEndFlag += animSpeedtrue;
  else}

  if (curTime -<= animSpeed;0) {
    animEndFlag = false;
  }

  if (curTimeanimEndFlag) >={
animTime)    curTime animDir -= falseanimSpeed;
  } else if(curTime <= 0){
    curTime animDir += trueanimSpeed;
  }

  // calc. the currentproportion of timecompletion in the animation
  float normTime = curTime * 1.0 / animTimeanimDuration;

  
if  if(pFlag1 && pFlag2(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()
{
else  if (pFlag1)click1 == false) {
    stroke(255, 0, 0);
    linefill(startPos.x,startPos.y,255,0,0);
    drawFlag = true;
  mouseX,mouseY)  curTime = 0;
  }  startPos.set(mouseX, mouseY, 0);
}    endPos void= mousePressedstartPos.get();
{    if(pFlag1click1 == false)
  true;
  } else {
    pFlag1 = truestroke(255);
    fill(255);
    startPosendPos.set(mouseX, mouseY, 0);
    click1 = false;
  }
  else if(pFlag2 == false)
 println(click1);
}

void mouseMoved() {
  if (click1 pFlag2 == true;) {
    endPos.set(mouseX, mouseY, 0);
  }
  else
  {
    pFlag1 = pFlag2 = false;
  }
}}