Skip to content

Instantly share code, notes, and snippets.

@adegard
Last active May 18, 2021 18:57
Show Gist options
  • Save adegard/7c26e7d006b14b81c3be606165a39666 to your computer and use it in GitHub Desktop.
Save adegard/7c26e7d006b14b81c3be606165a39666 to your computer and use it in GitHub Desktop.
Random walk colored
//https://editor.p5js.org/adegard/present/FaaJjJpXw
let x;
let y;
function setup() {
createCanvas(600, 600);
x = width / 2;
y = height / 2;
background(10);
}
function draw() {
stroke( random(255), random(255), random(255));
strokeWeight(10);
speed=floor(random(10))+1;
point(x, y);
const r = floor(random(4));
switch (r) {
case 0:
x = x +speed;
break;
case 1:
x = x -speed;
break;
case 2:
y = y +speed;
break;
case 3:
y = y -speed;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment