Skip to content

Instantly share code, notes, and snippets.

@lilbond
Created May 30, 2021 16:53
Show Gist options
  • Select an option

  • Save lilbond/902243a1a554ffddeabe7961dd8731c3 to your computer and use it in GitHub Desktop.

Select an option

Save lilbond/902243a1a554ffddeabe7961dd8731c3 to your computer and use it in GitHub Desktop.
Simple bouncing ball animation using paper js
var radius = 40;
var circle = new Path.Circle({
center: new Point(0,0),
radius: radius,
fillColor: 'blue'
});
var X = view.center.x;
var Y = view.center.y;
var x = 0;
var y = 0;
var stepX = stepY = 5;
function onFrame() {
if (circle.position.x + radius > 2*X) {
stepX *= -1;
circle.position = new Point(x,y)
}
if (circle.position.x - radius < 0) {
stepX = Math.abs(stepX);
}
if (circle.position.y + radius > 2 * Y) {
stepY *= -1;
circle.position = new Point(x,y)
}
if (circle.position.y - radius < 0) {
stepY = Math.abs(stepY);
}
x += stepX;
y += stepY;
circle.position = new Point(x, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment