xxxxxxxxxx
51
var index = 0;
var pointArray = [];
function setup() {
createCanvas(600, 600);
background(255);
}
function draw() {
point2DArray();
}
function point2DArray(){
if (mouseIsPressed === true) {
pointArray[index] = new point2D();
index++;
noFill();
stroke(color("black"));
background(255);
for (var i = 1; i < pointArray.length; i++){
beginShape();
strokeWeight(pointArray[i].weight);
for (var j = 0; j < 2;j++){
let X = 0 ; let Y = 0;
X = pointArray[i-1].x;
Y = pointArray[i-1].y;
vertex(X, Y);
X = pointArray[i].x;
Y = pointArray[i].y;
vertex(X, Y);
}
endShape();
}
}
}
class point2D {
constructor(prev) {
this.x = mouseX;
this.y = mouseY;
//this one is cooler: directly proportional
this.weight = ((map(sqrt((mouseX - pmouseX)*(mouseX - pmouseX) + (mouseY - pmouseY)*(mouseY - pmouseY)), 0, height, 0, 10)));
//this.weight = ((map(1/sqrt((mouseX - pmouseX)*(mouseX - pmouseX) + (mouseY - pmouseY)*(mouseY - pmouseY)), 0, 1, 0, 5)));
}
}