xxxxxxxxxx
let x, y; // Starting positions
let prevX, prevY; // Previous positions for drawing the line
let gap = 20; // Movement step
let strW = 1; // Stroke width
let jitterAmount = 5; // Jitter for random movement
let speed = 0.02; // Speed factor for movement randomness
let colors = []; // Array to hold pastel shades of blue and pink
function setup() {
createCanvas(windowWidth, windowHeight);
background(0); // Set black background
x = width / 2;
y = height / 2;
prevX = x;
prevY = y;
frameRate(80); // Control the speed of animation
// Define shades of blue and pink
colors = [
color(173, 216, 230), // Light Blue
color(240, 128, 128), // Light Coral (Pink)
color(255, 182, 193), // Light Pink
color(70, 130, 180), // Steel Blue
color(255, 105, 180), // Hot Pink
color(135, 206, 250) // Sky Blue
];
// Set the angle mode to DEGREES
angleMode(DEGREES);
}
function draw() {
// Randomness and jitter in movement
let randomDirection = random(360); // Random direction in degrees (0 to 360)
let randomSpeed = random(gap / 2, gap); // Random movement speed
let jitterX = cos(randomDirection) * randomSpeed + random(-jitterAmount, jitterAmount);
let jitterY = sin(randomDirection) * randomSpeed + random(-jitterAmount, jitterAmount);
// Calculate new position based on random movement
prevX = x;
prevY = y;
x += jitterX;
y += jitterY;
// Boundary check to ensure the agent stays within the canvas
x = constrain(x, 0, width);
y = constrain(y, 0, height);
// Set stroke properties and draw line
push();
let col = random(colors); // Pick a random color from shades of blue and pink
stroke(col.levels[0], col.levels[1], col.levels[2],); // Use random pastel color with fading effect
// Make stroke width gradually change as the agent moves
strW = map(dist(x, y, width / 2, height / 2), 0, width / 2, 1, 8);
strokeWeight(strW); // Change stroke width based on distance
line(x, y, prevX, prevY); // Draw the line
pop();
}