Modes are local to the file they appear in. Within that file modes may be changed as many times as wished, though that is to be discouraged as it could make for very hard-to-read code. The main place you are likely to find many changes of modes is in library files where it may make sense to define things in different modes to make the meaning of the definition clearer.
Modes get stored as special reserved variables (e.g. #version) which can be read by the language like any other variable. Most are read-only from within the scripting and can only be altered using the actual set command.
Example:
Example:
Example:
Example:
Example:
Example:
Most common is 0 to 1 range, so that is the default.
Hardware uses 0 to 256 range and it is quite natural for some of us to use powers of 2 for such things. If the keyword hex is given then that is the same as using the number 256. Note that even if another mode is set, color can be given as a hexadecimal number and will be correctly interpreted. Hexadecimal numbers for color are written the same way they are in html (for example white is #ffffff or red fully on is r=#ff) with or without quotes.
Something that may feel more natural to many people and easier to write is 0 to 100 -- a percent system.
360 is a quite magical number, being evenly divisible by 20 other numbers: 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 36, 40, 45, 60, 72, 90, 120, 180
100 only has 7 divisors: 2, 4, 5, 10, 20, 25, 50
256 has only 7, and worse, they are all only even numbers 2, 4, 8, 16, 32, 64, 128
It is important to understand that changing the color setting normally doesn't affect the fact that color calculations generally use 8 bits per color. This can be changed by using the 'hdr' keyword.
If 'hdr' is used in the color mode then High Dynamic Range colors are used. These are expressed as rgbe, where 'e' is an 8 bit exponent. Read more about hdr colors at http://www.debevec.org/Research/HDR/.
Example:
Mode is not actually a setting. It lets you query the mode settings.
Example:
Maintained by Miriam English