pub static norm: NormInternalTypeExpand description
Normalizes a number from another range into a value between 0 and 1. Identical to map(value, low, high, 0, 1). Numbers outside of the range are not clamped to 0 and 1, because out-of-range values are often intentional and useful. (See the example above.)
Examples
function draw() {
background(200);
let currentNum = mouseX;
let lowerBound = 0;
let upperBound = width; //100;
let normalized = norm(currentNum, lowerBound, upperBound);
let lineY = 70;
stroke(3);
line(0, lineY, width, lineY);
//Draw an ellipse mapped to the non-normalized value.
noStroke();
fill(50);
let s = 7; // ellipse size
ellipse(currentNum, lineY, s, s);
// Draw the guide
let guideY = lineY + 15;
text('0', 0, guideY);
textAlign(RIGHT);
text('100', width, guideY);
// Draw the normalized value
textAlign(LEFT);
fill(0);
textSize(32);
let normalY = 40;
let normalX = 20;
text(normalized, normalX, normalY);
}Parameters
value incoming value to be normalized
start lower bound of the value’s current range
stop upper bound of the value’s current range