xxxxxxxxxx
// Declare global variables for position, speed, and color
let x, y;
let speedX, speedY;
let agentColor;
function setup() {
// Create a canvas of size 800x800
createCanvas(800, 800);
// Set a dark background
background(10);
// Initialize position at the center of the canvas
x = width / 2;
y = height / 2;
// Initialize random speeds for the agent
speedX = random(-3, 3);
speedY = random(-3, 3);
// Set an initial vibrant random color for the agent
agentColor = color(random(150, 255), random(150, 255), random(150, 255));
}
function draw() {
// Store the current position as the previous position
let px = x;
let py = y;
// Update position based on speed
x += speedX;
y += speedY;
// Bounce off the edges by reversing direction
if (x <= 0 || x >= width) speedX *= -1;
if (y <= 0 || y >= height) speedY *= -1;
// Randomly change color for variety
if (random(1) < 0.02) {
agentColor = color(random(150, 255), random(150, 255), random(150, 255));
}
// Draw the trail with a highly visible stroke
stroke(agentColor);
strokeWeight(3);
line(px, py, x, y);
// Slightly darken the canvas without obscuring the trails
noStroke();
fill(10, 10, 10, 5); // Adjust transparency to keep trails vivid
rect(0, 0, width, height);
}