xxxxxxxxxx
function setup() {
createCanvas(windowWidth, windowHeight);
}
let a = [];
function draw() {
// background(220);
if (mouseIsPressed) {
fill(255, 220);
rect(0, 0, width, height);
a.push({mouseX, mouseY, xdist: mouseX-pmouseX, ydist: mouseY-pmouseY});
a.forEach(({mouseX, mouseY, xdist, ydist}, index) => {
// a[index].mouseX +=random(-1, 1)/(xdist+0.5);
// a[index].mouseY += random(-1, 1)/(ydist+0.5);
const m = 3;
a[index].mouseX += random(-1, 1) * m
a[index].mouseY += random(-1, 1) * m
a[index].xdist /= 2;
a[index].ydist /= 2;
//print(a.length - index)
stroke(a.length - index);
for( let i = 1; i < 4; i++ ) {
if (a[index -i]) {
line(a[index].mouseX, a[index].mouseY, a[index - i].mouseX, a[index -i].mouseY);
}
}
});
} else {
a = [];
}
}