xxxxxxxxxx
44
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Example 1-1: Bouncing Ball, no vectors
//velocity and vectors one effects the another and acceleration all are connected
// let x = 100;
// let y = 100;
// let xspeed = 2.5;
// let yspeed = 2;
function setup() {
createCanvas(640, 360);
background(51);
}
function draw() {
let positions =createVector(13,9);
let velocity= createVector(5,14);
// Add the current speed to the position.
// x = x + xspeed;
// y = y + yspeed;
positions.add(velocity);
if ((positions.x > width ) || (positions.x < 0)) {
// xspeed = xspeed * -1;
velocity.x= velocity.x*-1;
}
if ((positions.y > height) || (positions.y < 0)) {
// yspeed = yspeed * -1;
velocity.y= velocity.y * -1;
}
// Display circle at x position
stroke(0);
strokeWeight(2);
fill(127);
ellipse(positions.x, positions.y, 48);
}