Created
January 25, 2019 17:12
-
-
Save joydeep-b/8956ab7ab21e36a0f4c12fa289f952a4 to your computer and use it in GitHub Desktop.
This file contains 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
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