본문 바로가기
알고리즘

바운딩 움직임(반동, Bounce Animation)

by hansoo.labs 한수댁 2013. 5. 1.

void setup(){
  size(400,400);
  background(255,255,255);
}
float ballX=200, ballY=200,vX=0,vY=0;
float speed = 0.1;
float bounce = 0.88f;
void draw(){
  vX=(vX + (mouseX-ballX)*speed)*bounce;
  vY=(vY + (mouseY-ballY)*speed)*bounce;

  ballX=ballX+vX;
  ballY=ballY+vY;
  ellipse(ballX,ballY,20,20);
}

여기서 주목해야 할 것은 이것이다.

v=(v + (targetValue - nowValue)*speed)*bounce;
nowValue += v;




댓글0