xxxxxxxxxx
38
/* Credit: The Nature of Code
Daniel Shiffman
http://natureofcode.com */
var position;
var velocity;
var balls = [];
function setup() {
createCanvas(400, 400);
fill(255, 174, 0);
stroke(255, 136, 0);
position = createVector(100, 100);
velocity = createVector(2, 4);
/* Here, we are using a class Vector that contains
*/
}
function draw() {
background(248, 232, 255);
ellipse(position.x, position.y, 20, 20);
position.add(velocity); // why is my ball only moving horizontally?
if (position.x > 400 || position.x < 0) {
velocity.x *= -1;
}
if (position.y > 400 || position.y < 0) {
velocity.y *= -1;
}
// can you use arrays to generate multiple balls?
}