This script aids with modification of the colors used in Scripting.
This class can parse a color so you can access the red, green, blue and alpha channels.
new ParsedColor(color: ColorStringHex | ColorStringRGBA | ParsedColor)Parse a color string.
Parameters:
color: The color to parse. Only colors of the format#RGB,#RRGGBB,#RRGGBBAAandrgba(${number}, ${number}, ${number}, ${number})are supported. Named colors likelabelorsystemRedcannot be parsed.
new ParsedColor(red: number, green: number, blue: number)Create a parsed color by specifying each channel.
Parameters:
red: The red channel in the range 0 - 255green: The green channel in the range 0 - 255blue: The blue channel in the range 0 - 255
new ParsedColor(red: number, green: number, blue: number, alpha: number)Create a parsed color by specifying each channel (including the alpha channel)
Parameters:
red: The red channel in the range 0 - 255green: The green channel in the range 0 - 255blue: The blue channel in the range 0 - 255alpha: The alpha channel in the range 0 - 1
red: The red channelgreen: The green channelblue: The blue channelalpha: The alpha channel
Each property can also be set to a new value.
set(channels: {
red?: number
green?: number
blue?: number
alpha?: number
}): thisSet one or more channels to a new value and return the instance for chaining.
Parameters:
channels: The channel(s) to set
Returns:
The same instance with the new colors set.
toHex(): ColorStringHexReturns the color as a HEX string. If alpha equals 1 then it is not included, otherwise it is included in the last position as in #RRGGBBAA.
toRGBA(): ColorStringRGBARetuns the color as an rgba(...) string.
toHSL(): {
h: number
s: number
l: number
}Returns the color in HSL (hue, saturation, lightness) format in the range [0, 1].
Source: https://stackoverflow.com/a/9493060 (modified)
static fromHSL({h, s, l}: {h: number, s: number, l: number})Creates a ParsedColor instance from a color in HSL format.
Source: https://stackoverflow.com/a/9493060 (modified)
Parameters:
h: The hue of the color in the range [0, 1]s: The saturation of the color in the range [0, 1]l: The lightness of the color in the range [0, 1]
toHSV(): {
h: number
s: number
v: number
}Returns the color in HSL (hue, saturation, lightness) format in the range [0, 1].
static fromHSV({h, s, v}: {h: number, s: number, v: number})Creates a ParsedColor instance from a color in HSV format.
Source: https://stackoverflow.com/a/9493060 (modified)
Parameters:
h: The hue of the color in the range [0, 1]s: The saturation of the color in the range [0, 1]l: The lightness of the color in the range [0, 1]
getLuminance()Returns the luminance of the color (also called Y).
Source: https://gist.github.com/mnpenner/70ab4f0836bbee548c71947021f93607 and https://stackoverflow.com/a/56678483 (modified)
getPerceivedLightness()Returns the perceived lightness of the color (also called L* or L star).
Source: https://gist.github.com/mnpenner/70ab4f0836bbee548c71947021f93607 and https://stackoverflow.com/a/56678483 (modified)
export function darkenColor(
color: ColorStringHex | ColorStringRGBA | ParsedColor,
amount: number,
options?: {
adjustAlpha?: boolean
},
): ParsedColorDarkens a color.
Parameters:
color: The color to darkenamount: Amount to darken the color. Should be a number in the range 0 to 1 where 0 is no change and 1 equals blackoptions.adjustAlpha: Iftruethen also the alpha channel is adjusted. Defaults tofalse
export function brightenColor(
color: ColorStringHex | ColorStringRGBA | ParsedColor,
amount: number,
options?: {
adjustAlpha?: boolean
},
): ParsedColorBrightens a color.
Parameters:
color: The color to brightenamount: Amount to brighten the color. Should be a number in the range 0 to 1 where 0 is no change and 1 equals whiteoptions.adjustAlpha: Iftruethen also the alpha channel is adjusted. Defaults tofalse
export function adjustColor(
color: ColorStringHex | ColorStringRGBA | ParsedColor,
otherColor: ColorStringHex | ColorStringRGBA | ParsedColor,
amount: number,
options?: {
adjustAlpha?: boolean
},
): ParsedColorAdjust a color into the direction of another color.
Parameters:
color: The color to adjustotherColor: Target color to adjust toamount: Amount to adjust by. Should be a number in the range 0 to 1, where 0 means no adjustment and 1 returnsotherColoroptions.adjustAlpha: Iftruethen also the alpha channel is adjusted. Defaults tofalse