xxxxxxxxxx
56
/*
Based on Daniel Shiffman's Random Walker
http://codingtra.in
https://youtu.be/l__fEY1xanY
https://thecodingtrain.com/CodingChallenges/052-random-walk.html
See also Introduction to the Nature of Code v2.0 by Daniel Shiffman:
https://drive.google.com/file/d/1G_16tPKByN9ya6l2Ws58X-OJK1yex9IX/view
*/
let x, y;
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
stroke(255);
strokeWeight(4);
x = width / 2;
y = height / 2;
}
function draw() {
point(x, y);
let randomNum = floor(random(4));
if (randomNum == 0) {
x += 4;
} else if (randomNum == 1) {
x -= 4;
} else if (randomNum == 2) {
y += 4;
} else {
y -= 4;
}
if (x > width || x < 0) {
x = width / 2;
}
if (y > height || y < 0) {
y = height / 2;
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
background(0)
}
function mousePressed(){
background(0)
x = mouseX;
y = mouseY
}