Color
The creation, blending, and application of colors to shapes and text is a common task performed in all Omni applications. This page details how to work with color values in various color spaces.
Color Functions
RGB(redValue, greenValue, blueValue, alphaValue or nil) (Color) • Makes a new color in the RGB colorspace, with the given components. If the alpha component is not given, 1.0 is used.
HSB(hueValue, saturationValue, brillianceValue, alphaValue or nil) • Makes a new color in the HSB colorspace, with the given components. If the alpha component is not given, 1.0 is used.
White(whiteValue, alphaValue or nil) • Makes a new color in the White colorspace, with the given components. If the alpha component is not given, 1.0 is used. A White value of: 0 is black, .5 is 50% gray.
Here’s a script example that creates a green circle (in the RGB color space) with a 50% transparency (alpha value) overlaid on a blue square:
Using RGB ColorSpace | ||
01 | cnvs = document.windows[0].selection.canvas | |
02 | square = cnvs.addShape('Rectangle',new Rect(72,72,200,200)) | |
03 | square.fillColor = Color.RGB(0, 0, 1, 1) | |
04 | circle = cnvs.addShape('Circle',new Rect(150,150,200,200)) | |
05 | circle.fillColor = Color.RGB(0, 1, 0, 0.5) |
Here’s a script example that adds grayscale tint swatches, from black to white in increments of 10%, to the current canvas:
Grayscale Bar - 10% Increments | ||
01 | cnvs = document.windows[0].selection.canvas | |
02 | objSize = 48 | |
03 | offset = 0 | |
04 | swatches = new Array() | |
05 | for(i = 0; i < 11; i++){ | |
06 | offset = offset + objSize | |
07 | aRect = new Rect(offset, objSize, objSize, objSize) | |
08 | graphic = cnvs.addShape('Rectangle', aRect) | |
09 | color = Color.White(i*.1,1) | |
10 | graphic.fillColor = color | |
11 | swatches.push(graphic) | |
12 | } | |
13 | swatchStrip = new Group(swatches) |
Color Class Properties
Some common colors can be represented with the following property values instead of using one of the Color methods.
Color Property | ||
01 | graphic.fillColor = Color.blue |
black (Color) • A color in the White colorspace with white component of 0.0.
blue (Color) • A color in the RGB colorspace with components (0, 0, 1, 1).
brown (Color) • A color in the RGB colorspace with components (0.6, 0.4, 0.2, 1).
clear (Color) • A color in the White colorspace with white component of 0.0 and alpha of 0.0 (“transparent black”).
cyan (Color) • A color in the RGB colorspace with components (0, 1, 1, 1).
darkGray (Color) • A color in the White colorspace with white component of 0.333.
gray (Color) • A color in the White colorspace with white component of 0.5.
green (Color) • A color in the RGB colorspace with components (0, 1, 0, 1).
lightGray (Color) • A color in the White colorspace with white component of 0.667.
magenta (Color) • A color in the RGB colorspace with components (1, 0, 1, 1).
orange (Color) • A color in the RGB colorspace with components (1, 0.5, 0, 1).
purple (Color) • A color in the RGB colorspace with components (1, 0, 1, 1).
red (Color) • A color in the RGB colorspace with components (1, 0, 0, 1).
white (Color) • A color in the White colorspace with white component of 1.0.
yellow (Color) • A color in the RGB colorspace with components (1, 1, 0, 1).
Color Instance Properties
Once a Color object has been created, you can use the following instance properties to gather information about the color object.
alpha (Number r/o) • Returns the alpha component of the color.
blue (Number r/o) • Returns the blue component of the color, after converting to a RGB colorspace.
brightness (Number r/o) • Returns the brightness component of the color, after converting to a HSB colorspace.
colorSpace (ColorSpace r/o) • Returns the colorspace of the instance.
green (Number r/o) • Returns the green component of the color, after converting to a RGB colorspace.
hue (Number r/o) • Returns the hue component of the color, after converting to a HSB colorspace.
red (Number r/o) • Returns the red component of the color, after converting to a RGB colorspace.
saturation (Number r/o) • Returns the saturation component of the color, after converting to a HSB colorspace.
white (Number r/o) • Returns the white component of the color, after converting to a White colorspace.
Color Instance Functions
Color objects can be blended to create new colors, using the blend() method:
blend(otherColor, fractionNumber) (Color or nil) • Returns a new color that is a linear combination of the receiver and fraction of the other color (so, a fraction of 1.0 would just return the otherColor. If the colors cannot be blended (for example, if they cannot be converted to the same colorspace), then null is returned.
Here’s an example of blending colors: creating an orange circle by blending red and yellow
Blending Colors | ||
01 | cnvs = document.windows[0].selection.canvas | |
02 | graphic = cnvs.addShape('Circle',new Rect(0,0,200,200)) | |
03 | colorA = Color.red | |
04 | colorB = Color.yellow | |
05 | blendColor = colorA.blend(colorB,0.5) | |
06 | graphic.fillColor = blendColor |
ColorSpace
Curabitur blandit tempus porttitor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec ullamcorper nulla non metus auctor fringilla. Etiam porta sem malesuada magna mollis euismod. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
CMYK (ColorSpace r/o) • A colorspace with cyan, magenta, yellow, black, and alpha components.
HSB (ColorSpace r/o) • A colorspace with hue, saturation, and value (or brightness) components.
Named (ColorSpace r/o) • A space for named colors, like system defined colors, or specific color palette spaces.
Pattern (ColorSpace r/o) • A colorspace that wraps a pattern image.
RGB (ColorSpace r/o) • The sRGB colorspace with red, green, blue, and alpha components.
White (ColorSpace r/o) • A colorspace with white and alpha components.
This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.