v1.3.0.0

Description

Provides functions for working with color.

New instances can be created with new Color(input) or just Color(input). Static functions are invoked with Color. qualifier.

Library originally from TinyColor. This object can also be invoked with tinycolor().

The library has been extended with extra functions described below. For the rest of the documentation, with examples, please see original reference at https://github.com/bgrins/TinyColor#usage
There is also a basic demo page with some more details at http://bgrins.github.io/TinyColor/

The official documentation has examples, but as a summary, a new Color instance may be created from a wide variety of input formats and types.

  • Supported string format examples:
    • Named standard CSS color, eg: "red"
    • "#f00" or "f00"
    • "#ff0000" or "ff0000"
    • "#ff000000" or "ff000000"
    • "rgb 255 0 0" or "rgb (255, 0, 0)"
    • "rgb 1.0 0 0" or "rgb (1, 0, 0)"
    • "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
    • "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
    • "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
    • "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
    • "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
  • Object types in various color models:
    • {r, g, b [, a]}
    • {h, s, l [, a]}
    • {h, s, v [, a]}

The following methods are aliases of their longer counterparts (unlinked ones are documented at TinyColor site):

  • originalInput() = getOriginalInput();
  • format() = getFormat();
  • alpha() = getAlpha();
  • brightness() = getBrightness();
  • luminance() = getLuminance();
  • saturation() = getSaturation();
  • hsv() = toHsvString();
  • hsl() = toHslString();
  • hex() = toHexString();
  • rgba() = toHex8String();
  • argb() = toArgbHexString();
  • rgb() = toRgbString();
  • prgb() = toPercentageRgbString();

In addition, the toString() method is extended with "argb" and "hex8a" format specifiers (both are analogous), see toArgbHexString().

Public Member Functions

string tpcolor ()
 
string toArgbHex ()
 
string toArgbHexString ()
 
string toWebColor (allowShortFormat=false)
 
number getSaturation ()
 
Color mixWith (Color color2, number amount)
 
Color tint (number amount)
 
Color shade (number amount)
 
Color polyad (number n)
 
bool isDarkerThan (Color secondColor)
 
bool isLighterThan (Color secondColor)
 
bool isWarm ()
 
bool isCool ()
 
bool isWarmerThan (Color secondColor)
 
bool isCoolerThan (Color secondColor)
 

Static Public Member Functions

Color fromArgb (string argbString)
 
string argb2rgba (string argbString)
 
Color mix (Color color1, Color color2, number amount)
 
Color tint (Color color, number amount)
 
Color shade (Color color, number amount)
 
Color complement (Color color)
 
Color polyad (Color color, number n)
 
bool isDarker (Color color1, Color color2)
 
bool isLighter (Color color1, Color color2)
 
bool isWarmer (Color color1, Color color2)
 
bool isCooler (Color color1, Color color2)
 

Member Function Documentation

◆ tpcolor()

string tpcolor ( )

Returns color formatted in #AARRGGBB format (this is suitable for use with Touch Portal's "Set Text/Background color from plug-in state" action).


Same as argb() and toArgbHexString().

◆ toArgbHex()

string toArgbHex ( )

Returns color formatted in AARRGGBB format.

◆ toArgbHexString()

string toArgbHexString ( )

Returns color formatted in #AARRGGBB format.

Alias: argb(), tpcolor()

In addition, the toString() method is extended with "argb" and "hex8a" format specifiers (both are analogous).

◆ toWebColor()

string toWebColor (   allowShortFormat = false)

Returns color formatted in #RRGGBB or #RRGGBBAA format if this color's alpha channel is not fully opaque.

If allowShortFormat is set to true then may return #RBA or #RGBA format if current color can be accurately expressed that way.

Aliases: web(), toString("web")

◆ getSaturation()

number getSaturation ( )

Returns the saturation value of this color.

Alias: saturation()

◆ mixWith()

Color mixWith ( Color  color2,
number  amount 
)

Returns a new color with this color and color2 mixed by amount.

amount should be in range of 0-100.

◆ tint() [1/2]

Color tint ( number  amount)

Returns a new color with this color tinted by amount.

amount should be in range of 0-100.

◆ shade() [1/2]

Color shade ( number  amount)

Returns a new color with this color shaded by amount.

amount should be in range of 0-100.

◆ polyad() [1/2]

Color polyad ( number  n)

Returns an array of up to n colors harmonious with this color.

Same as triad() and tetrad() when called with values 3 and 4, respectively.

◆ isDarkerThan()

bool isDarkerThan ( Color  secondColor)

The color with less brightness value is considered as Darker.

◆ isLighterThan()

bool isLighterThan ( Color  secondColor)

Return the opposite value of isDarkerThan().

◆ isWarm()

bool isWarm ( )

Returns true if this color is considered "warm" (higher red value than blue).

◆ isCool()

bool isCool ( )

Returns true if this color is considered "cool" (higher blue value than red).

◆ isWarmerThan()

bool isWarmerThan ( Color  secondColor)

Returns true if the color is warmer i.e.

have more red value. If both colors have the same red value the one with less green and blue values is considered warmer.

◆ isCoolerThan()

bool isCoolerThan ( Color  secondColor)

Return the opposite value of isWarmer().

◆ fromArgb()

Color fromArgb ( string  argbString)
static

Returns a new Color instance from an "#AARRGGBB" or "#RRGGBB" string input.

The leading "#" is optional.

See also
argb2rgba()

◆ argb2rgba()

string argb2rgba ( string  argbString)
static

Converts a "#AARRGGBB" color format string to "#RRGGBBAA" format.

The leading "#" is optional in the input string, but will always be present in the output. If input is less than 8 hex characters long then no conversion is done and the original string is returned (with "#" prepended if necessary).

See also
fromArgb()

◆ mix()

Color mix ( Color  color1,
Color  color2,
number  amount 
)
static

Returns a new color with color1 and color2 mixed by amount.

amount should be in range of 0-100.

This is a static function. Use it like Color.mix("red", "blue", 50)

◆ tint() [2/2]

Color tint ( Color  color,
number  amount 
)
static

Returns a new Color of color by amount.

amount should be in range of 0-100.

This is a static function. Use it like Color.tint("red", 50)

◆ shade() [2/2]

Color shade ( Color  color,
number  amount 
)
static

Returns a new Color with color shaded by amount.

amount should be in range of 0-100.

This is a static function. Use it like Color.shade("red", 50)

◆ complement()

Color complement ( Color  color)
static

Returns a new Color which is complimentary to color.

This is a static function. Use it like Color.complement("green")

◆ polyad() [2/2]

Color polyad ( Color  color,
number  n 
)
static

Returns an array of up to n colors harmonious to color.

Same as triad(color) and tetrad(color) when called with values 3 and 4, respectively.

This is a static function. Use it like Color.polyad("green", 3)

◆ isDarker()

bool isDarker ( Color  color1,
Color  color2 
)
static

The color with less brightness value is considered as Darker.

This is a static function. Use it like Color.isDarker("white", "black")

◆ isLighter()

bool isLighter ( Color  color1,
Color  color2 
)
static

Return the opposite value of isDarker().

This is a static function. Use it like Color.isLighter("white", "black")

◆ isWarmer()

bool isWarmer ( Color  color1,
Color  color2 
)
static

Returns true if the color is warmer i.e, has more red value.

If both colors have the same red value the one with less green and blue values is considered warmer.
This is a static function. Use it like Color.isWarmer("red", "blue")

◆ isCooler()

bool isCooler ( Color  color1,
Color  color2 
)
static

Return the opposite value of isWarmer().

This is a static function. Use it like Color.isCooler("red", "blue")