xxxxxxxxxx
//This is a starting point for a random walk challenge.
//
// You will need to fix it - the circle currently just walks in a dull straight line.
// It should move randomly but it should only ever take a SMALL step from where it was, each frame of animation.
// Variables to track position of "walker" (initialised in setup()). You could use an object if you prefer.
let x;
let y;
// This "setup" function will be called only once.
function setup() {
createCanvas(600, 600); //(width and height in pixels)
//initialise our position variables. You can change these numbers.
x = 300;
y = 100;
background('gray');
// Let's slow down the animation to 2 "FPS" so you can see what's happening
frameRate(2) // (You can speed this up to 60 when you want.)
}
// This "draw" function will be found and called over and over to make an animation (up to 60 times per second!)
function draw() {
//Step 1. draw the "walker"
const colour = random( ["blue", "yellow"] )
fill(colour)
//fill('yellow');
circle(x, y, 30);
//Step 2. move the walker a little bit. This is no good - it always goes in the same direction!
// Not very random! Can you fix it? what about vertical movement?
x+= 5;
y += random(-5, 5);
}