`y = m*x + b`

·

1 min read

The equation for a line, y = m*x + b was fun to learn because we used it to write some very simple 2-D video games. School was fun.

The p5js.org ecosystem offers a free online editor. Here's a very simple program moving a blue square along the screen.

function setup() {
  createCanvas(400, 400);
}

let m = 1.0;
let b = 0;
let x = 0;
let y = 0;

function draw() {
  background(220);
  y = m * x + b;
  fill('blue');
  rect(x,y,10,10);
  x = x + 1;
  x = x % width;
  y = y % height;
}