본문 바로가기
알고리즘

반동 움직임(Bounce Animation)

by hansoo.labs 한수댁 2020. 8. 13.

// p5.js
var ballX=200, ballY=200, vX=0, vY=0;
var speed = 0.1;
var bounce = 0.88;

function setup() {
  createCanvas(320, 320);
  background(255);
}

function 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