Last active
March 1, 2020 06:08
-
-
Save gabrielflorit/31051d77904a3379e8bd58e3c83647d1 to your computer and use it in GitHub Desktop.
SCRIPT-8
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
{} |
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
// title: Break | |
const ball = { | |
x: 30, | |
y: 60, | |
dx: 1, | |
dy: 1, | |
r: 3 | |
} | |
const moveBall = ball => { | |
ball.x += ball.dx | |
ball.y += ball.dy | |
} | |
const bounceBall = ball => { | |
if (ball.x < 0 || ball.x > 128) { | |
ball.dx *= -1 | |
} | |
if (ball.y < 0 || ball.y > 128) { | |
ball.dy *= -1 | |
} | |
} | |
const drawBall = ball => { | |
circFill(ball.x, ball.y, ball.r, 4) | |
} | |
init = state => { | |
state.ball = ball | |
} | |
update = (state, input, elapsed) => { | |
bounceBall(state.ball) | |
moveBall(state.ball) | |
} | |
draw = state => { | |
clear() | |
rectStroke(0, 0, 128, 128, 5) | |
drawBall(state.ball) | |
} |
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
[] |
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
{ | |
"iframeVersion": "0.1.280", | |
"lines": [ | |
43, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0 | |
] | |
} |
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
{} |
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
{} |
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
{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment