Advertisement
xeromino

vid8

May 4th, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var w;
  2.  
  3. function setup() {
  4.   createCanvas(640, 360);
  5.   background(35);
  6.   noStroke();
  7.   w = new Walker();
  8. }
  9.  
  10. function draw() {
  11.   background(51);
  12.   w.update();
  13.   w.display();
  14. }
  15.  
  16. function Walker() {
  17.   this.pos = createVector(width / 2, height / 2);
  18.   this.vel = createVector(0, 0);
  19.  
  20.   this.update = function() {
  21.     var mouse = createVector(mouseX, mouseY);
  22.     this.acc = p5.Vector.sub(mouse, this.pos);
  23.     this.acc.normalize();
  24.     //this.acc.mult(0.5);
  25.  
  26.     this.vel.add(this.acc);
  27.     this.pos.add(this.vel);
  28.   }
  29.  
  30.   this.display = function() {
  31.     fill(238);
  32.     ellipse(this.pos.x, this.pos.y, 30, 30);
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement