xxxxxxxxxx
62
let twod = [];
let distances = [];
let x1 = 0;
let y1 = 0;
function setup() {
createCanvas(600, 600);
//noLoop();
}
function draw() {
background(220);
secondarray();
}
function secondarray() {
stroke("red");
noFill();
if (twod.length>0) {
x1 = twod[twod.length-1][0];
y1 = twod[twod.length-1][1];
}
let x2 = mouseX;
let y2 = mouseY;
//console.log(x1,y1, x2, y2);
let distance1 = ((x2-x1)**2 + (y2-y1)**2)**0.5
twod.push([x2,y2]);
distances.push(distance1);
console.log(distance1);
//beginShape();
for (i=0; i<twod.length-1; i++) {
//beginShape();
//strokeWeight(distances[i]);
let xa = twod[i][0];
let ya = twod[i][1];
let xb = twod[i+1][0];
let yb = twod[i+1][1];
//curveVertex(twod[i+1][0], twod[i+1][1]);
//endShape();
strokeWeight(30-distances[i]);
line(xa, ya, xb, yb);
//point(twod[i][0], twod[i][1]);
}
//endShape();
if (twod.length > 100) {
twod.splice(0,1);
distances.splice(0,1);
}
}