home/ atoms/ processing-norm-lerp-map

norm(), lerp(), and map() convert and interpolate values between numeric ranges

Three Processing math functions handle range conversion. norm(value, low, high) normalises value to 0.0-1.0; it’s equivalent to (value-low)/(high-low). lerp(start, stop, t) interpolates linearly between start and stop by fraction t (0.0 to 1.0). map(value, low1, high1, low2, high2) scales value from one range to another — equivalent to lerp(low2,high2, norm(value,low1,high1)) but more direct. map() is ubiquitous for converting mouse position (0 to width) to a useful parameter range (e.g., 0 to TWO_PI for rotation). These three functions are the core of data-to-visual mapping.

Examples

float angle = map(mouseX, 0, width, 0, TWO_PI); float x = norm(50.0, 0.0, 100.0); // = 0.5 float y = lerp(10, 90, 0.25); // = 30.0

Assessment

Use map() to convert a sound amplitude (0.0-1.0) to a circle radius (10-200px); explain what happens if the input value falls outside the source range.

“float x = map(20.0, 0.0, 255.0, -1.0, 1.0);// Assign -0.84 to x”
corpus · processing-handbook-no-login-mirror-pdf-reas-and-fry · chunk 24