# Random Walker

const WIDTH = Math.min(window.innerWidth, window.innerHeight, 480);
var x;
var y;
var step = 4;

function reset() {
  x = width / 2;
  y = height / 2;
  background(51);
}

function setup() {
  createCanvas(WIDTH, WIDTH);
  reset();
}

function draw() {
  background(51, 51, 51, 10);
  stroke(255);
  strokeWeight(2);
  point(x, y);

  var r = floor(random(4));

  if (r === 0) {
    x += step * 1;
  } else if (r === 1) {
    x += step * -1;
  } else if (r === 2) {
    y += step * 1;
  } else if (r === 3) {
    y += step * -1;
  }

  if (x <= 0 || y <= 0 || x >= width || y >= height) {
    reset();
  }
}