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         animTime = 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 >= animTime) {
    curTimeanimEndFlag += animSpeedtrue;
  else}

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

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

  // calc. the current time in the animation
  float normTime = curTime * 1.0 / animTime;

  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);
  }
}

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