メインコンテンツまでスキップ
バージョン:23.5

Color Values in SenseTalk

A color can be represented in SenseTalk as a combination of component values in any of several different formats.

Supported Color Formats

The recognized formats are listed in the following table:

Color FormatExample ValueDescription
Basic128,0,64Red, green, and blue values from 0 to 255
Alpha128,0,64,255Red, green, blue, and alpha values from 0 to 255
HTML#800040Red, green, and blue values in hexadecimal form as used in web pages
WW, 0.241White value from 0 (black) to 1 (white)k
WAWA, 0.241, 1.000White and alpha values from 0 to 1
RGBRGB, 0.5, 0, 0.25Red, green, and blue values from 0 to 1
RGBARGBA, 0.5, 0.0, 0.25, 1.0Red, green, blue, and alpha values from 0 to 1
HSBHSB, 0.917, 1.0, 0.5Hue, saturation, and brightness values from 0 to 1
HSBAHSBA, 0.917, 1.0, 0.5, 1.0Hue, saturation, brightness and alpha values from 0 to 1
CMYKCMYK, 0.143, 0.942, 0.225, 0.274Cyan, magenta, yellow, and black values from 0 to 1
CMYKACMYKA, 0.143, 0.942, 0.225, 0.274, 1.000Cyan, magenta, yellow, black, and alpha values from 0 to 1

In addition, a number of color names are recognized, as defined by the namedColors global property.

The default color format, known as the Basic format, is a list of three numbers with values in the range 0 to 255, indicating the amounts of red, green, and blue that compose the color. The Alpha format adds a fourth number, known as the alpha value, that represents the opacity of the value, for systems that can work with partially-transparent colors. An alpha value of zero represents clear.

The HTML format is a single value consisting of a pound sign (#) followed by two hexadecimal digits each for the red, green, and blue components of the color. Each of the other formats is a list beginning with a format code, followed by numeric values in the range 0.0 to 1.0 representing the amount of each component in a particular color model.

When evaluating a value as a color, SenseTalk can accept either a list of appropriate values, or a text list (a text string consisting of values separated by commas).

In addition to the commands and functions described below, there are two SenseTalk global properties you can use to govern certain aspects of working with color in scripts:

  • The ColorFormat
  • The NamedColor

These global properties are defined on Global and Local Properties for Working with Values.

There are a number of color-related commands and functions in SenseTalk.

Color, AsColor Function

Behavior: The color function returns a color value from a string or list in one of the recognized color formats. Any of the 11 formats described for the colorFormat property are recognized, as either text lists (with items separated by commas) or as true lists of values. In addition, color names can be used, as defined by the namedColors global property.

Use the color function whenever a color is needed from a value that may not already be represented as a color. One common use of the color function is to compare two colors that may be in different formats to see if they represent the same color.

Syntax:
color( stringOrList )
the color of stringOrList

The color function converts a value to its internal representation as a color. This can also be called using the synonymous asColor function, or the as color operator.

Example:

put color("#00FFFF") is the color of "aqua" --> True
if color of stripe is color("red") then
//Do something
end if

Related:

Red, Green, Blue, Hue, Saturation, Brightness, Cyan, Magenta, Yellow, Black, White, and Alpha Functions

Behavior: These functions each return one component value of a color interpreted using a particular color space. The value returned is always in the range from 0 (the color does not contain any of that component) to 1 (the color contains the maximum possible amount of that component).

Use the red , green, and blue functions to obtain the individual components of a color as represented using the red/green/blue color space. Use the hue , saturation, and brightness functions to get the individual components of a color as represented using the hue, saturation, and brightness color space. Use the cyan , magenta , yellow, and black functions to obtain the individual components of a color as represented using the cyan/magenta/yellow/black color space that is commonly used when printing. Use the white function to evaluate a color using a greyscale color space and return the level of white from 0 (black) to 1 (white). Use the alpha function to return the opacity of a color value, from 0 (transparent) to 1 (opaque).

Syntax:
red( stringOrList ) , blue( stringOrList ) , ...
the red of stringOrList , the blue of stringOrList , ...

Each of these functions evaluates stringOrList as a color and returns a value in the range 0 to 1 representing the amount of the requested color component that is present in that color in the appropriate color space. Note that the black and white functions are not opposites, as they evaluate the color in different color spaces.

Examples:

put the red of "purple" --> 0.5
put blue("#00FFFF") --> 1
put hue("purple") --> 0.833333
put yellow("#00FFFF") --> 0.133043
put white of "purple" --> 0.268208

Related:

Is a Color Operator

Behavior: The is a color operator is an extension to the standard is a operator that tests whether a given value can be interpreted as a color.

Use the is a color operator whenever your script needs to determine if a value is valid as a color.

Syntax:
value is a color

If value is a string or list in one of the recognized color formats, or is one of the color names defined by the namedColors global property, the is a color operator will evaluate to “true”.

Examples:

put "#00FFFF"is a color --> True
if shade is a color then
//Do something
end if

STColorVersion Function

Behavior: Returns the version number of the STColor Xmodule.

You will rarely need the STColorVersion function, but might use it if there is a need to check the version of the color module in use for compatibility reasons.

Syntax:
STColorVersion()
the STColorVersion

Returns: The STColorVersion function returns a number.

Examples:

if the STColorVersion < 1.02 then
//Do something
end if