xxxxxxxxxx
let x, y; // Position of the agent
let angle = 0; // Angle for movement
let stepSize; // Step size for movement
let timer = 0; // Timer for cyclic changes
let colorHue = 0; // Cyclic value for color change
function setup() {
createCanvas(800, 800);
background(10); // Set the canvas background to black
x = width / 2;
y = height / 2;
stepSize = 5;
colorMode(HSB, 360, 100, 100); // Use HSB color mode
}
function draw() {
// Save the previous position
let prevX = x;
let prevY = y;
// Random angle adjustment and movement
angle += random(-PI / 4, PI / 4); // Add randomness to the angle
x += cos(angle) * stepSize;
y += sin(angle) * stepSize;
// Constrain position to keep the agent within the canvas
x = constrain(x, 50, width - 50);
y = constrain(y, 50, height - 50);
// Cyclic color change
colorHue = (colorHue + 1) % 360;
// Drawing properties
stroke(colorHue, 80, 100, 0.8); // Set the stroke color
strokeWeight(2);
line(prevX, prevY, x, y); // Draw the movement path
// Change step size cyclically with a timer
timer++;
if (timer > 60) { // Every 60 frames, update step size
stepSize = random(2, 10);
timer = 0;
}
}
// To export the animation, you can use screen recording
// or functions like "saveCanvas" or "p5.createLoop".