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 movingCircle = {x:100,y:300}
// This "setup" function will be called only once.
function setup() {
createCanvas(600, 600); //(width and height in pixels)
background('gray');
frameRate(60)
}
function draw() {
//Step 1. draw the "walker"
const colours = ['#937DC2', '#C689C6', '#E8A0BF', '#3330E4', '#FCC5C0', '3AB0FF', 'F8F9D7'];
fill(random(colours));
const centre = {x:300,y:300}
circle(movingCircle.x, movingCircle.y, 30);
circle (centre.x,centre.y,10);
let x1 = centre.x
let y1 = centre.y
let step = 30
movingCircle.x += random(-step, step);
movingCircle.y += random(-step, step);
placesToGo = [{x:200,y:200}, {x:400,y:200},{x:200,y:400}, {x:400,y:400}];
if (dist(x1,y1,movingCircle.x,movingCircle.y) > 250 || dist(x1,y1,movingCircle.x,movingCircle.y) < 150){
// pick random possition from array
movingCircle = random(placesToGo)
// movingCircle.x = -200
// movingCircle.y = -200
}
//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?
}