Created
May 30, 2021 16:53
-
-
Save lilbond/902243a1a554ffddeabe7961dd8731c3 to your computer and use it in GitHub Desktop.
Simple bouncing ball animation using paper js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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