nick34992
4/19/2016 - 3:15 PM

Vector. Using p5.js library.

Vector. Using p5.js library.

var l = new p5.Vector(576, 324);
var v = new p5.Vector(16, 9);

function setup() {
  createCanvas(1152, 648);
}

function draw() {
  background(255);
  l.add(v);
  // invert velocity vector
  // location dot syntax
  // velocity dot syntax
  if ((l.x > width) || (l.x < 0)) {
    v.x = v.x * -1;
  }
  if ((l.y > height) || (l.y < 0)) {
    v.y = v.y * -1;
  }
  noStroke();
  fill(255, 0, 0);
  // location dot syntax
  ellipse(l.x, l.y, 100, 100);
  frameRate(30);
}