xxxxxxxxxx
let path = []; // Array to store the path positions
let currentPos; // Current position of the moving point
function setup() {
createCanvas(400, 400);
currentPos = createVector(width / 2, height / 2); // Start in the center
background(250);
}
function draw() {
// Move the current position randomly
let step = createVector(random(-10, 10), random(-10, 10));
currentPos.add(step);
// Store the current position in the path array
path.push(currentPos.copy());
// Draw the path
noFill();
stroke(0);
beginShape();
for (let i = 0; i < path.length; i++) {
vertex(path[i].x, path[i].y);
}
endShape();
// Constrain the path length to prevent it from growing indefinitely
if (path.length > 1000) {
path.shift(); // Remove the oldest position
}
}