xxxxxxxxxx
29
// The Nature Of Code 2
// Chapter 1 : Vectors
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
let pos = createVector(width / 2, height / 2);
let mouse = createVector(mouseX, mouseY);
let v = p5.Vector.sub(mouse, pos);
// let m = v.mag();
// v.div(m);
// v.mult(50);
// v.normalize();
// v.mult(50);
// v.normalize().mult(50);
v.setMag(50);
stroke(255);
strokeWeight(2);
translate(width / 2, height / 2);
line(0, 0, v.x, v.y);
}