xxxxxxxxxx
var xpos = 0;
var ypos = 0;
var dice;
var cl;
var r;
var g;
var b;
var speedX;
var speedY;
var trailLength = 100;
var trail = [];
function setup() {
createCanvas(800, 800);
background(250);
xpos = width / 2;
ypos = height / 2;
cl = "#fefefe";
r = 0;
g = 0;
b = 0;
speedX = random(-2, 2);
speedY = random(-2, 2);
background(10);
}
function draw() {
for (var i = 0; i < 25; i++) {
walker();
}
drawTrail();
}
function walker() {
// Autonomous agent logic with random movement
dice = random(0, 1);
// Movement direction and speed are now more variable
if (dice < 0.25) {
speedX = random(-3, -1);
} else if (dice < 0.5) {
speedX = random(1, 3);
} else if (dice < 0.75) {
speedY = random(-3, -1);
} else if (dice < 1) {
speedY = random(1, 3);
}
// Move the agent
xpos += speedX;
ypos += speedY;
// Wrap-around effect if the agent goes off-screen
if (xpos > width) xpos = 0;
if (xpos < 0) xpos = width;
if (ypos > height) ypos = 0;
if (ypos < 0) ypos = height;
// Randomize color with smoother transitions
r += random(-5, 5);
g += random(-5, 5);
b += random(-5, 5);
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
fill(r, g, b, 155);
noStroke();
circle(xpos, ypos, abs(sin(frameCount * 0.01) * 20));
// Store the agent's position for drawing a trail
trail.push(createVector(xpos, ypos));
// Limit the trail length
if (trail.length > trailLength) {
trail.shift();
}
}
function drawTrail() {
// Draw the trail as fading circles
noFill();
stroke(r, g, b, 100);
strokeWeight(2);
beginShape();
for (var i = 0; i < trail.length; i++) {
var pos = trail[i];
var alpha = map(i, 0, trail.length, 255, 0);
stroke(r, g, b, alpha);
ellipse(pos.x, pos.y, i * 0.5);
}
endShape();
}
function keyPressed() {
if (key == 's') {
saveCanvas();
}
}