xxxxxxxxxx
let dice = 0;
let x = 0;
let y = 0;
let prex = 0;
let prey = 0;
let gap = 50;
let strW = 1; // Initial stroke weight
let colorChange = 0; // Color cycling variable
let alphaChange = 180; // Transparency variable
function setup() {
createCanvas(windowWidth, windowHeight);
background(0); // Set a black background
}
function draw() {
// Assign previous coordinates
prex = x;
prey = y;
// Generate random dice value
dice = random(0, 4);
// 25% chance to move left
if (dice < 1.0) {
x -= gap;
}
// 25% chance to move right
else if (dice < 2.0) {
x += gap;
}
// 25% chance to move up
else if (dice < 3.0) {
y -= gap;
}
// 25% chance to move down
else if (dice < 4.0) {
y += gap;
}
x = constrain(x, -width / 2, width / 2);
y = constrain(y, -height / 2, height / 2);
strW = map(sin(frameCount * 0.05), -1, 1, 1, 5);
colorChange = map(sin(frameCount * 0.01), -1, 1, 0, 255);
alphaChange = map(cos(frameCount * 0.03), -1, 1, 100, 255);
gap = map(sin(frameCount * 0.02), -1, 1, 30, 70);
push();
translate(width / 2, height / 2); // Center the drawing
strokeWeight(strW);
stroke(255 - colorChange, colorChange, 150, alphaChange);
line(prex, prey, x, y); // Draw the line
pop();
}