xxxxxxxxxx
var x;
var y;
var sz;
var dice;
var cl;
var speed; // Movement speed variable
function setup() {
createCanvas(600, 600); // set canvas size
background(250); // set canvas bg color
cl = color(10, 10, 200); // agent color (blue)
x = width / 2; // agent x position
y = height / 2; // agent y position
sz = 5; // agent size
speed = 2; // movement speed
}
function draw() {
dice = random(0, 1);
// Random Walk Algorithm with varied speed and direction
if (dice < 0.25) {
// go left
x -= speed;
} else if (dice < 0.5) {
// go right
x += speed;
} else if (dice < 0.75) {
// go up
y -= speed;
} else {
// go down
y += speed;
}
// Apply random speed variation
speed = random(1, 3);
// Draw the agent with a fading trail effect
noStroke();
fill(cl, 150); // Add transparency for fading effect
circle(x, y, sz);
// Optionally draw some fading trails
fill(255, 100);
ellipse(x, y, sz * 2, sz * 2); // Create a soft trail effect
}