The map function in p5.js

Please click this link, especially if it does not work on your phone. Just move the cursor up and down.

var col = 0;
var backgr = 0;

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

function draw(){
  col = mouseY
  col = map(mouseY, 0, 400, 125, 255)
  backgr = map(mouseY, 0, 400, 0, 125)
  background(backgr);
  
  
  
  fill(col)
  ellipse(200, mouseY, 64, 64)
}

Leave a Reply