Color:
Filter:
Classes | GUI > Accessories

Color : Object

An object which stores color values
Source: Color.sc

Description

An object which stores red, green, blue, and alpha values in instance variables, and provides numerous class and instance methods for creating and manipulating these values.

Class Methods

Color.new(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)

Create a new instance with float values.

Arguments:

red

An instance of Float between 0 and 1.

green

An instance of Float between 0 and 1.

blue

An instance of Float between 0 and 1.

alpha

An instance of Float between 0 and 1.

Color.new255(red: 0, green: 0, blue: 0, alpha: 255)

Create a new instance from 8-bit integer values between 0 and 255.

Arguments:

red

An instance of Integer between 0 and 255.

green

An Integer between 0 and 255.

blue

An Integer between 0 and 255.

alpha

An Integer between 0 and 255.

Color.fromArray(array)

Same as Color.new(*array).

Arguments:

array

An instance of Array. 1-4 values between 0 and 1. See *new.

Color.fromHexString(string)

Creates a new instance from a hex color string.

Arguments:

string

A String.

Discussion:

The string should be a 6 character web color, or a 3 character CSS style color. A preceding # is optional.

Color.black

Nothing is darker.

Color.white

Nothing is lighter.

Color.clear

Nothing is more clear.

Color.gray(gray: 0.5, alpha: 1.0)

American shades of grey.

Arguments:

gray

Shades between 0 (black) and 1 (white) as Float.

alpha

Transparency of gray between 0 and 1 as Float.

Color.grey(grey: 0.5, alpha: 1.0)

British shades of grey.

Arguments:

grey

Shades between 0 (black) and 1 (white) as Float.

alpha

Transparency of grey between 0 and 1 as Float.

Color.red(val: 1.0, alpha: 1.0)

Color.green(val: 1.0, alpha: 1.0)

Color.blue(val: 1.0, alpha: 1.0)

Color.cyan(val: 1.0, alpha: 1.0)

Color.magenta(val: 1.0, alpha: 1.0)

Color.yellow(val: 1.0, alpha: 1.0)

Create a new red, green, blue, cyan, magenta or yellow Color.

Arguments:

val

An instance of Float between 0 and 1, where 1 is the bright, fully saturated color, and 0 is black.

alpha

Transparency between 0 and 1 as Float.

Color.rand(lo: 0.3, hi: 0.9)

A random RGB Color where the colors are randomly chosen between lo and hi. See Color: new.

Arguments:

lo

An instance of Float between 0 and 1.

hi

An instance of Float between 0 and 1.

Color.hsv(hue, sat, val, alpha: 1)

Maps hsv and alpha values to rgb between 0 and 1.

Arguments:

hue

Float between 0 and 0.999.

sat

Float between 0 and 1.

val

Float between 0 and 1.

alpha

Float between 0 and 1.

Inherited class methods

Instance Methods

.red

.red = value

.green

.green = value

.blue

.blue = value

.alpha

.alpha = value

Get/set one of the instance variables, red, green, blue, or alpha.

Returns:

An instance of Float between 0 and 1.

.hexString

Returns a String containing a 6 character web color code, preceded by a #.

==(that)

Binary operator.

.scaleByAlpha

Returns a Color, where red, green, and blue are scaled by the alpha value, and alpha is set to 1.

.blend(that, blend: 0.5)

Interpolates the red, green, blue, and alpha values of two Colors, linearly weighting between the first and the second.

Arguments:

that

A second Color.

blend

0 means only this, while 1 means only that.

.vary(val: 0.1, lo: 0.3, hi: 0.9, alphaVal: 0)

Returns a random variation of a Color.

Arguments:

val

Varies the RGB values +- this amount.

lo

Low-clips the RGB variation here.

hi

High-clips the RGB variation here.

alphaVal

Varies the alpha value +/- this amount, and clips it between 0 and 1.

.complementary

Returns the complementary color.

.multiply(aColor, opacity: 1.0)

Arguments:

aColor

An instance of Color.

opacity

A value between 0 and 1. Default value is 1.0.

.divide(aColor, opacity: 1.0)

Arguments:

aColor

An instance of Color.

opacity

A value between 0 and 1. Default value is 1.0.

.subtract(aColor, opacity: 1.0)

Arguments:

aColor

An instance of Color.

opacity

A value between 0 and 1. Default value is 1.0.

.add(aColor, opacity: 1.0)

Arguments:

aColor

An instance of Color.

opacity

A value between 0 and 1. Default value is 1.0.

.symmetricDifference(aColor, opacity: 1.0)

Arguments:

aColor

An instance of Color.

opacity

A value between 0 and 1. Default value is 1.0.

.screen(aColor, opacity: 1.0)

Arguments:

aColor

An instance of Color.

opacity

A value between 0 and 1. Default value is 1.0.

.lighten(aColor, opacity: 1.0)

Arguments:

aColor

An instance of Color.

opacity

A value between 0 and 1. Default value is 1.0.

.darken(aColor, opacity: 1.0)

Arguments:

aColor

An instance of Color.

opacity

A value between 0 and 1. Default value is 1.0.

.hueBlend(aColor, blend: 0.0)

Arguments:

aColor

An instance of Color.

blend

A value between 0 and 1. Default value is 0.

.saturationBlend(aColor, blend: 0.0)

Arguments:

aColor

An instance of Color.

blend

A value between 0 and 1. Default value is 0.

.valueBlend(aColor, blend: 0.0)

Arguments:

aColor

An instance of Color.

blend

A value between 0 and 1. Default value is 0.

.asHSV

Returns an array with [hue, saturation, value, alpha], as values between 0 and 1.

.asArray

Returns an array with [red, green, blue, alpha], as values between 0 and 1.

.storeArgs

Returns an array with [red, green, blue, alpha].

.setStroke

For use with Pen. Sets the stroke of Pen to this.

.setFill

For use with Pen. Sets the fill of Pen to this.

.set

For use with Pen. Sets the stroke and fill of Pen to this.

.round(val: 0.01)

Round the color.

Inherited instance methods

Examples

X-windows colors