Learn creative coding writing simple programs

45. Convert distances into colors or widths

The map() function is very useful when you want to convert numbers from one range to another range. When do we want to do that? well, we use different ranges of numbers for different things. For example the sin() function returns values between -1 and 1. The valid X positions for drawing on our screen might be between 0 and 400. The right values for RGB colors usually are between 0 and 255.
Sometimes we want to make the color depend on a distance, or maybe the width depend on a speed. You can link any two concepts that come into your mind in your program. Using map() is the easiest way to convert values from one range to another.

Tags: map, range, numbers, software tutorial, education

Code editor

You can make changes to the code below. Then
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus