Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

The Type color [11/11]

Initializers are not expressions.
println statement can print expressions only, not initializers.

Exercise:

(Challenging!) There is a way to print out RGB values of a color given by marked initializer /orange. How would you do it?

Solution

To print a value of an initializer, initialize a variable by the initializer and then print out the variable.

#color myorange = /orange;
println "orange: ", myorange;


For experts only: RGB values of type color are linear, not gamma-compressed. The gamma-compressed type with values 0-255 is named rgb. The getter color.rgb performs the conversion.

* * *

Value of a named argument, like fg, can be given by an initializer or by an expression. A named argument fg is actually of type colorA, which is described in a later chapter.

Loading...