Skip to content

Instantly share code, notes, and snippets.

@joydeep-b
Created January 25, 2019 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joydeep-b/8956ab7ab21e36a0f4c12fa289f952a4 to your computer and use it in GitHub Desktop.
Save joydeep-b/8956ab7ab21e36a0f4c12fa289f952a4 to your computer and use it in GitHub Desktop.
const kWindowSize = 400;
const kBallRadius = 50;
let x = 200;
let y = 200;
let vx = 3.5;
let vy = 1.8;
let c = lib220.newCanvas(kWindowSize, kWindowSize);
while(true) {
lib220.sleep(16);
x += vx;
y += vy;
if (x < kBallRadius) {
x = kBallRadius + kBallRadius - x;
vx = -vx;
} else if (x > kWindowSize - kBallRadius) {
x = kWindowSize - kBallRadius - (x - (kWindowSize - kBallRadius));
vx = -vx;
}
if (y < kBallRadius) {
y = kBallRadius + kBallRadius - y;
vy = -vy;
} else if (y > kWindowSize - kBallRadius) {
y = kWindowSize - kBallRadius - (y - (kWindowSize - kBallRadius));
vy = -vy;
}
c.clear();
c.drawCircle(x, y, kBallRadius, [0, 0, 0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment