Created
April 19, 2016 15:15
-
-
Save nick3499/b2940800f941702be38281679592019b to your computer and use it in GitHub Desktop.
Vector. Using p5.js library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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