Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var w;
- function setup() {
- createCanvas(640, 360);
- background(35);
- noStroke();
- w = new Walker();
- }
- function draw() {
- background(51);
- w.update();
- w.display();
- }
- function Walker() {
- this.pos = createVector(width / 2, height / 2);
- this.vel = createVector(0, 0);
- this.update = function() {
- var mouse = createVector(mouseX, mouseY);
- this.acc = p5.Vector.sub(mouse, this.pos);
- this.acc.normalize();
- //this.acc.mult(0.5);
- this.vel.add(this.acc);
- this.pos.add(this.vel);
- }
- this.display = function() {
- fill(238);
- ellipse(this.pos.x, this.pos.y, 30, 30);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement