xxxxxxxxxx
47
// Daniel Shiffman
// http://codingtra.in
// https://youtu.be/l__fEY1xanY
// https://thecodingtrain.com/CodingChallenges/052-random-walk.html
let x;
let y;
let h = 0;
function setup() {
createCanvas(400, 400);
colorMode(HSB);
x = width / 2;
y = height / 2;
background(51);
}
function draw() {
stroke(h, 100, 100, 100);
h = h + 1;
if (h > 360) {
h = 0;
}
strokeWeight(2);
point(x, y);
const r = floor(random(4));
switch (r) {
case 0:
x = x + 1;
y = y + 0;
break;
case 1:
x = x - 1;
y = y + 0;
break;
case 2:
x = x + 0;
y = y + 1;
break;
case 3:
x = x + 0;
y = y - 1;
break;
}
}