The Processing map function is a very useful function which converts a value from one range into a corresponding value in a second range. Processing.org: map function
Re-maps a number from one range to another.
map(value, start1, stop1, start2, stop2)
Map Function - Parameters
The map function takes 5 input parameters: the first 3 values correspond to the known value in first range, and the first range endpoints. The last 2 values are the 2 endpoints for the second range.
In the image below, we can see a visual illustration of the map function with parameter values listed below:
float value2 = map( value1, 50, 200, 10, 360);
We can see that if value1 = 157, then value2 is calculated to be 259.
We can use the Map function to create relationships between features of our programs.
In Project 1, we can use the changing value of the length parameter for drawn patterns as the known value that is changing, we can use it to give us changing values of color components, such as hue, saturation, or brightness.
Example code below shows how we can use the map function to vary size and color of a rectangle drawn at the mouse position. (Include setup() to set size() and colorMode to HSB)