xxxxxxxxxx
37
// The Bouncing Ball
// Code! Programming with p5.js
// The Coding Train / Daniel Shiffman
// https://thecodingtrain.com/beginners/p5js/3.2-bouncing-ball.html
// https://youtu.be/LO3Awjn_gyU
// https://editor.p5js.org/codingtrain/sketches/Xm4cmQvU
// println() is no longer part of p5.js use console.log(). For more info: https://p5js.org/reference/#/console/log
let x = 300;
let y = 200;
let xSpeed = 4;
let ySpeed = 2;
let r = 50;
function setup() {
createCanvas(600, 400);
}
function draw() {
background(0);
ellipse(x, y, r, r);
if (x < 0 || x > width) {
xSpeed = -xSpeed;
}
if (y < 0 || y > height) {
ySpeed = -ySpeed;
}
x = x + xSpeed;
y = y + ySpeed;
// ellipse(x, y, r, r);
}