Data types: color

Represents a color value with its red, green, blue and alpha (opacity) information.

Type syntax

color

Literal syntax

#RRGGBBAA

Discussion

The color information is stored as four individual 8-bit unsigned integer components. Every component is expressed in range 0 .. 255, with the value 255 representing the maximum intensity of the respective component. In particular, the value of the alpha component determines the opacity of the entire color. If it is 0, the color is fully transparent. If it is 255, the color is fully opaque. All remaining values lying in between represent a semitransparent color.

The color literal must begin with the # (number sign) followed by exact eight hexadecimal digits RRGGBBAA, where RR, GG, BB and AA determine the hexadecimal values for the corresponding red, green, blue and alpha components. The literal can be used within expressions wherever a color operand is expected. The type name color, in turn, is designated to be used in declarations of data members. For example:

var color textColor   = #812244FF; // red=129, green=34, blue=68, alpha=255
var color background  = #000000AA; // black, semitransparent with alpha=170
var color transparent = #00000000; // fully transparent

Instant constructors

With the instant constructor color() you can initialize color operands dynamically at the runtime.

Instant properties

With the following instant properties you can individually access, evaluate and modify the components of a color operand:

Instant property name

Short description

alpha

Corresponds to the alpha component of a color operand.

blue

Corresponds to the blue component of a color operand.

green

Corresponds to the green component of a color operand.

red

Corresponds to the red component of a color operand.

Arithmetic operations

You can combine a color operand with other operands to arithmetic expressions. The following table provides an overview of the possible operations:

Operator

Short description

+

Component-wise addition of two color operands.

-

Component-wise subtraction of two color operands.

Blending operations

You can combine color operands in alpha blending or color modulation operations. The following table provides an overview of the possible operations:

Operator

Short description

*

Alpha blending between two color values.

*

Modulating a color value with an integer value.

Comparison operations

You can compare two color operands in order to test whether these are equal or not. The following table provides an overview of the possible operations:

Operator

Short description

==

Equality test for two color operands.

!=

Inequality test for two color operands.