Now it's time to look at a more technical subject, namely MathMap's type system. The type system of MathMap is designed to be as invisible as possible, but in order to unleash MathMap's full potential, you will need to know one or two things about it. Don't worry, it's not very complicated.
Sometimes it's convenient to treat two or more numbers as a single value. One such example is colors. A single color is actually four distinct numbers. We have already come across three of them, namely the red, green, and blue components. The fourth is the color's transparency value, called alpha. A color with an alpha of 1 is completely opaque, like all the colors we have seen so far. An alpha component of 0 means full transparency, 0.5 means half transparent, and so on.
So far, we have always treated colors as single values. We have constructed colors using functions such as rgbColor and retrieved its components with functions like red. We can, however, do these things without using those functions. This, for example, is the half-transparent color green:
rgba:[0,1,0,0.5]
One or more numbers within square brackets, separated by commata, constitute a tuple. So, tuples are just ordered collections of numbers. They are ordered because MathMap remembers in which order you have written their components. For example, the tuple [1,2,3] is not the same as [3,2,1].
The name rgba is a
tag. The tag rgba tells MathMap that
that tuple is not just four numbers, but a color with red, green, blue
and alpha components. This begs the question whether there are other
kinds of colors. Actually, there are. MathMap also supports colors
in the so-called HSV color space. Those colors are given the tag
hsva. MathMap uses the tags to determine how to interpret
the numbers in the tuples.
Many operators and functions work on tuples as well
as on single numbers. The functions min and
max for example, calculate the minimum and
maximum values for each tuple element. To set the red component of an
image to 0, for example, you can use the
following expression:
Next topic: Animations
max(origValXY(x,y),rgba:[0,1,1,1])