[][src]Static p5_sys::global::map

pub static map: MapInternalType

Re-maps a number from one range to another.

In the first example above, the number 25 is converted from a value in the range of 0 to 100 into a value that ranges from the left edge of the window (0) to the right edge (width).

Examples

let value = 25;
let m = map(value, 0, 100, 0, width);
ellipse(m, 50, 10, 10);
function setup() {
  noStroke();
}

function draw() {
  background(204);
  let x1 = map(mouseX, 0, width, 25, 75);
  ellipse(x1, 25, 25, 25);
  //This ellipse is constrained to the 0-100 range
  //after setting withinBounds to true
  let x2 = map(mouseX, 0, width, 0, 100, true);
  ellipse(x2, 75, 25, 25);
}

Parameters

value the incoming value to be converted

start1 lower bound of the value's current range

stop1 upper bound of the value's current range

start2 lower bound of the value's target range

stop2 upper bound of the value's target range

withinBounds? constrain the value to the newly mapped range