Last active
May 18, 2021 18:57
-
-
Save adegard/7c26e7d006b14b81c3be606165a39666 to your computer and use it in GitHub Desktop.
Random walk colored
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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