xxxxxxxxxx
31
let path = [];
const stepsize = 5;
let anglerange
function setup() {
createCanvas(600, 600);
//generate path here all at once
path = [[width/2,height/2]] //sample code
anglerange = 0.5*PI;;
}
function draw() {
background(255);
//generate path here step by step
// let direction = atan((mouseY-path[path.length-1][1])/(mouseX-path[path.length-1][0]));
let direction = atan((mouseY-path[path.length-1][1])/(mouseX-path[path.length-1][0])) + (PI/2)*Math.sign(mouseX-path[path.length-1][0]);
let step = random(stepsize);
path.push([path[path.length-1][0] + cos(direction)*step, path[path.length-1][1] + sin(direction)*step]); //sample code
drawPath(); //draws the path
}
function drawPath(){
stroke(0);
for(let i=1;i<path.length;i++){
line(path[i-1][0],path[i-1][1],path[i][0],path[i][1]);
}
}