Skip to content

Instantly share code, notes, and snippets.

@nick3499
Created April 19, 2016 15:15
Show Gist options
  • Select an option

  • Save nick3499/b2940800f941702be38281679592019b to your computer and use it in GitHub Desktop.

Select an option

Save nick3499/b2940800f941702be38281679592019b to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment