xxxxxxxxxx
70
//reference:
// Daniel Shiffman
// http://codingtra.in
// https://youtu.be/l__fEY1xanY
// https://thecodingtrain.com/CodingChallenges/052-random-walk.html
// chatgpt
let x, y;
let old_x, old_y;
let colors;
function setup() {
createCanvas(400, 400);
x = width / 2;
y = height / 2;
old_x = x;
old_y = y;
background(0);
colors = [
"rgba(255, 0, 0, 0.8)",
"rgba(0, 255, 0, 0.8)",
"rgba(0, 0, 255, 0.8)",
"rgba(255, 255, 0, 0.8)",
"rgba(255, 0, 255, 0.8)",
"rgba(0, 255, 255, 0.8)",
];
}
function draw() {
stroke(random(colors));
strokeWeight(10);
glowEffect();
line(x, y, old_x, old_y);
old_x = x;
old_y = y;
let stepSize = random([-50, -5, 5, 50]);
let r = floor(random(10));
switch (r) {
case 0:
x += stepSize;
break;
case 1:
x -= stepSize;
break;
case 2:
y += stepSize;
break;
case 3:
y -= stepSize;
break;
}
x = constrain(x, 0, width);
y = constrain(y, 0, height);
}
//below glowEffect() part i asked chatgpt to give me a glow effect to the lines, to create neon lights effects.
function glowEffect() {
for (let i = 10; i > 0; i--) {
strokeWeight(i);
stroke(random(colors).replace("0.8", (i * 0.08).toFixed(2)));
line(x, y, old_x, old_y);
}
}