xxxxxxxxxx
var x, y; // Initial position
var px, py; // Previous position
var stepSize; // Step size
var colors = []; // Color palette
function setup() {
createCanvas(800, 800);
background(10);
// Set initial position to center
x = width / 2;
y = height / 2;
px = x;
py = y;
stepSize = 20; // Initial step size
// Color palette
colors = [
color(255, 100, 100),
color(100, 255, 100),
color(100, 100, 255),
color(255, 255, 100),
color(100, 255, 255)
];
}
function draw() {
// Random movement
px = x;
py = y;
var direction = floor(random(4)); // Choose random direction (0-3)
if (direction === 0) {
x += stepSize; // Right
} else if (direction === 1) {
x -= stepSize; // Left
} else if (direction === 2) {
y += stepSize; // Down
} else {
y -= stepSize; // Up
}
// Check boundaries
if (x < 0 || x > width || y < 0 || y > height) {
x = width / 2;
y = height / 2;
stepSize = random(10, 50); // Choose a new random step size
}
// Drawing settings
strokeWeight(random(1, 4));
stroke(random(colors)); // Random color for stroke
line(px, py, x, y); // Draw line representing movement
// Add circular pattern at the current position
noStroke();
fill(random(colors)); // Random color for the circle
ellipse(x, y, random(5, 15)); // Draw circle with random size
}