Class representing a color, based on Int. Provides a variety of methods for creating and converting colors.

Colors can be written as Ints. This means you can pass a hex value such as 0x123456 to a function expecting a Color, and it will automatically become a Color "object". Similarly, Colors may be treated as Ints.

Note that when using properties of a Color other than RGB, the values are ultimately stored as RGB values, so repeatedly manipulating HSB/HSL/CMYK values may result in a gradual loss of precision.

Static variables

@:value(-1)staticinlineread onlyNONE:Color = -1

@:value(0xFFFFFF)staticinlineread onlyWHITE:Color = 0xFFFFFF

@:value(0x808080)staticinlineread onlyGRAY:Color = 0x808080

@:value(0x000000)staticinlineread onlyBLACK:Color = 0x000000

@:value(0x008000)staticinlineread onlyGREEN:Color = 0x008000

@:value(0x00FF00)staticinlineread onlyLIME:Color = 0x00FF00

@:value(0xFFFF00)staticinlineread onlyYELLOW:Color = 0xFFFF00

@:value(0xFFA500)staticinlineread onlyORANGE:Color = 0xFFA500

@:value(0xFF0000)staticinlineread onlyRED:Color = 0xFF0000

@:value(0x800080)staticinlineread onlyPURPLE:Color = 0x800080

@:value(0x0000FF)staticinlineread onlyBLUE:Color = 0x0000FF

@:value(0x8B4513)staticinlineread onlyBROWN:Color = 0x8B4513

@:value(0xFFC0CB)staticinlineread onlyPINK:Color = 0xFFC0CB

@:value(0xFF00FF)staticinlineread onlyMAGENTA:Color = 0xFF00FF

@:value(0x00FFFF)staticinlineread onlyCYAN:Color = 0x00FFFF

@:value(0x6495ED)staticinlineread onlyCORNFLOWERBLUE:Color = 0x6495ED

@:value(0xC71585)staticinlineread onlyMEDIUMVIOLETRED:Color = 0xC71585

@:value(0xFF1493)staticinlineread onlyDEEPPINK:Color = 0xFF1493

@:value(0xDB7093)staticinlineread onlyPALEVIOLETRED:Color = 0xDB7093

@:value(0xFF69B4)staticinlineread onlyHOTPINK:Color = 0xFF69B4

@:value(0xFFB6C1)staticinlineread onlyLIGHTPINK:Color = 0xFFB6C1

@:value(0x8B0000)staticinlineread onlyDARKRED:Color = 0x8B0000

@:value(0xB22222)staticinlineread onlyFIREBRICK:Color = 0xB22222

@:value(0xDC143C)staticinlineread onlyCRIMSON:Color = 0xDC143C

@:value(0xCD5C5C)staticinlineread onlyINDIANRED:Color = 0xCD5C5C

@:value(0xF08080)staticinlineread onlyLIGHTCORAL:Color = 0xF08080

@:value(0xFA8072)staticinlineread onlySALMON:Color = 0xFA8072

@:value(0xE9967A)staticinlineread onlyDARKSALMON:Color = 0xE9967A

@:value(0xFFA07A)staticinlineread onlyLIGHTSALMON:Color = 0xFFA07A

@:value(0xFF4500)staticinlineread onlyORANGERED:Color = 0xFF4500

@:value(0xFF6347)staticinlineread onlyTOMATO:Color = 0xFF6347

@:value(0xFF8C00)staticinlineread onlyDARKORANGE:Color = 0xFF8C00

@:value(0xFF7F50)staticinlineread onlyCORAL:Color = 0xFF7F50

@:value(0xBDB76B)staticinlineread onlyDARKKHAKI:Color = 0xBDB76B

@:value(0xFFD700)staticinlineread onlyGOLD:Color = 0xFFD700

@:value(0xF0E68C)staticinlineread onlyKHAKI:Color = 0xF0E68C

@:value(0xFFDAB9)staticinlineread onlyPEACHPUFF:Color = 0xFFDAB9

@:value(0xEEE8AA)staticinlineread onlyPALEGOLDENROD:Color = 0xEEE8AA

@:value(0xFFE4B5)staticinlineread onlyMOCCASIN:Color = 0xFFE4B5

@:value(0xFFEFD5)staticinlineread onlyPAPAYAWHIP:Color = 0xFFEFD5

@:value(0xFFFACD)staticinlineread onlyLEMONCHIFFON:Color = 0xFFFACD

@:value(0xFFFFE0)staticinlineread onlyLIGHTYELLOW:Color = 0xFFFFE0

@:value(0xA0522D)staticinlineread onlySIENNA:Color = 0xA0522D

@:value(0xD2691E)staticinlineread onlyCHOCOLATE:Color = 0xD2691E

@:value(0xCD853F)staticinlineread onlyPERU:Color = 0xCD853F

@:value(0xD2B48C)staticinlineread onlyTAN:Color = 0xD2B48C

@:value(0x556B2F)staticinlineread onlyDARKOLIVEGREEN:Color = 0x556B2F

@:value(0x808000)staticinlineread onlyOLIVE:Color = 0x808000

@:value(0x008080)staticinlineread onlyTEAL:Color = 0x008080

@:value(0x40E0D0)staticinlineread onlyTURQUOISE:Color = 0x40E0D0

@:value(0x000080)staticinlineread onlyNAVY:Color = 0x000080

@:value(0x4B0082)staticinlineread onlyINDIGO:Color = 0x4B0082

@:value(0xDA70D6)staticinlineread onlyORCHID:Color = 0xDA70D6

@:value(0xE6E6FA)staticinlineread onlyLAVENDER:Color = 0xE6E6FA

@:value(0xF0FFFF)staticinlineread onlyAZURE:Color = 0xF0FFFF

@:value(0xFFFFF0)staticinlineread onlyIVORY:Color = 0xFFFFF0

@:value(0x696969)staticinlineread onlyDIMGREY:Color = 0x696969

@:value(0x708090)staticinlineread onlySLATEGREY:Color = 0x708090

@:value(0xFFFAFA)staticinlineread onlySNOW:Color = 0xFFFAFA

@:value(["NONE" => -1, "WHITE" => 0xFFFFFF, "GRAY" => 0x808080, "BLACK" => 0x000000, "GREEN" => 0x008000, "LIME" => 0x00FF00, "YELLOW" => 0xFFFF00, "ORANGE" => 0xFFA500, "RED" => 0xFF0000, "PURPLE" => 0x800080, "BLUE" => 0x0000FF, "BROWN" => 0x8B4513, "PINK" => 0xFFC0CB, "MAGENTA" => 0xFF00FF, "CYAN" => 0x00FFFF, "CORNFLOWERBLUE" => 0x6495ED, "MEDIUMVIOLETRED" => 0xC71585, "DEEPPINK" => 0xFF1493, "PALEVIOLETRED" => 0xDB7093, "HOTPINK" => 0xFF69B4, "LIGHTPINK" => 0xFFB6C1, "DARKRED" => 0x8B0000, "FIREBRICK" => 0xB22222, "CRIMSON" => 0xDC143C, "INDIANRED" => 0xCD5C5C, "LIGHTCORAL" => 0xF08080, "SALMON" => 0xFA8072, "DARKSALMON" => 0xE9967A, "LIGHTSALMON" => 0xFFA07A, "ORANGERED" => 0xFF4500, "TOMATO" => 0xFF6347, "DARKORANGE" => 0xFF8C00, "CORAL" => 0xFF7F50, "DARKKHAKI" => 0xBDB76B, "GOLD" => 0xFFD700, "KHAKI" => 0xF0E68C, "PEACHPUFF" => 0xFFDAB9, "PALEGOLDENROD" => 0xEEE8AA, "MOCCASIN" => 0xFFE4B5, "PAPAYAWHIP" => 0xFFEFD5, "LEMONCHIFFON" => 0xFFFACD, "LIGHTYELLOW" => 0xFFFFE0, "SIENNA" => 0xA0522D, "CHOCOLATE" => 0xD2691E, "PERU" => 0xCD853F, "TAN" => 0xD2B48C, "DARKOLIVEGREEN" => 0x556B2F, "OLIVE" => 0x808000, "TEAL" => 0x008080, "TURQUOISE" => 0x40E0D0, "NAVY" => 0x000080, "INDIGO" => 0x4B0082, "ORCHID" => 0xDA70D6, "LAVENDER" => 0xE6E6FA, "AZURE" => 0xF0FFFF, "IVORY" => 0xFFFFF0, "DIMGREY" => 0x696969, "SLATEGREY" => 0x708090, "SNOW" => 0xFFFAFA])staticread onlycolorLookup:Map<String, Int> = ["NONE" => -1, "WHITE" => 0xFFFFFF, "GRAY" => 0x808080, "BLACK" => 0x000000, "GREEN" => 0x008000, "LIME" => 0x00FF00, "YELLOW" => 0xFFFF00, "ORANGE" => 0xFFA500, "RED" => 0xFF0000, "PURPLE" => 0x800080, "BLUE" => 0x0000FF, "BROWN" => 0x8B4513, "PINK" => 0xFFC0CB, "MAGENTA" => 0xFF00FF, "CYAN" => 0x00FFFF, "CORNFLOWERBLUE" => 0x6495ED, "MEDIUMVIOLETRED" => 0xC71585, "DEEPPINK" => 0xFF1493, "PALEVIOLETRED" => 0xDB7093, "HOTPINK" => 0xFF69B4, "LIGHTPINK" => 0xFFB6C1, "DARKRED" => 0x8B0000, "FIREBRICK" => 0xB22222, "CRIMSON" => 0xDC143C, "INDIANRED" => 0xCD5C5C, "LIGHTCORAL" => 0xF08080, "SALMON" => 0xFA8072, "DARKSALMON" => 0xE9967A, "LIGHTSALMON" => 0xFFA07A, "ORANGERED" => 0xFF4500, "TOMATO" => 0xFF6347, "DARKORANGE" => 0xFF8C00, "CORAL" => 0xFF7F50, "DARKKHAKI" => 0xBDB76B, "GOLD" => 0xFFD700, "KHAKI" => 0xF0E68C, "PEACHPUFF" => 0xFFDAB9, "PALEGOLDENROD" => 0xEEE8AA, "MOCCASIN" => 0xFFE4B5, "PAPAYAWHIP" => 0xFFEFD5, "LEMONCHIFFON" => 0xFFFACD, "LIGHTYELLOW" => 0xFFFFE0, "SIENNA" => 0xA0522D, "CHOCOLATE" => 0xD2691E, "PERU" => 0xCD853F, "TAN" => 0xD2B48C, "DARKOLIVEGREEN" => 0x556B2F, "OLIVE" => 0x808000, "TEAL" => 0x008080, "TURQUOISE" => 0x40E0D0, "NAVY" => 0x000080, "INDIGO" => 0x4B0082, "ORCHID" => 0xDA70D6, "LAVENDER" => 0xE6E6FA, "AZURE" => 0xF0FFFF, "IVORY" => 0xFFFFF0, "DIMGREY" => 0x696969, "SLATEGREY" => 0x708090, "SNOW" => 0xFFFAFA]

staticred:Int

Red color component as Int between 0 and 255

staticgreen:Int

Green color component as Int between 0 and 255

staticblue:Int

Blue color component as Int between 0 and 255

staticredFloat:Float

Red color component as Float between 0.0 and 1.0

staticgreenFloat:Float

Green color component as Float between 0.0 and 1.0

staticblueFloat:Float

Blue color component as Float between 0.0 and 1.0

staticcyan:Float

staticblack:Float

statichue:Float

The hue of the color in degrees (from 0 to 359)

staticsaturation:Float

The saturation of the color (from 0 to 1)

staticbrightness:Float

The brightness (aka value) of the color (from 0 to 1)

staticlightness:Float

The lightness of the color (from 0 to 1)

statichueHSLuv:Float

The HSLuv hue of the color in degrees (from 0 to 359)

staticsaturationHSLuv:Float

The HSLuv saturation of the color (from 0 to 1)

staticlightnessHSLuv:Float

The HSLuv lightness of the color (from 0 to 1)

Static methods

@:tostaticinlinetoAlphaColor(this:Int):AlphaColor

Get the color as AlphaColor

@:value({ minBrightness : 0.5, minSatutation : 0.5 })staticinlinerandom(minSatutation:Float = 0.5, minBrightness:Float = 0.5):Color

Generate a random color (away from white or black)

Returns:

The color as a Color

staticinlinefromInt(value:Int):Color

Create a color from the least significant three bytes of an Int

Parameters:

value

And Int with bytes in the format 0xRRGGBB

Returns:

The color as a Color

staticinlinefromRGB(red:Int, green:Int, blue:Int):Color

Generate a color from integer RGB values (0 to 255)

Parameters:

red

The red value of the color from 0 to 255

green

The green value of the color from 0 to 255

blue

The green value of the color from 0 to 255

Returns:

The color as a Color

staticinlinefromRGBFloat(red:Float, green:Float, blue:Float):Color

Generate a color from float RGB values (0 to 1)

Parameters:

red

The red value of the color from 0 to 1

green

The green value of the color from 0 to 1

blue

The green value of the color from 0 to 1

Returns:

The color as a Color

staticinlinefromCMYK(cyan:Float, magenta:Float, yellow:Float, black:Float):Color

Generate a color from CMYK values (0 to 1)

Parameters:

cyan

The cyan value of the color from 0 to 1

magenta

The magenta value of the color from 0 to 1

yellow

The yellow value of the color from 0 to 1

black

The black value of the color from 0 to 1

Returns:

The color as a Color

staticfromHSB(hue:Float, saturation:Float, brightness:Float):Color

Generate a color from HSB (aka HSV) components.

Parameters:

hue

A number between 0 and 360, indicating position on a color strip or wheel.

saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

brightness

(aka value) A number between 0 and 1, indicating how bright the color should be. 0 is black, 1 is full bright.

Returns:

The color as a Color

staticinlinefromHSL(hue:Float, saturation:Float, lightness:Float):Color

Generate a color from HSL components.

Parameters:

hue

A number between 0 and 360, indicating position on a color strip or wheel.

saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

lightness

A number between 0 and 1, indicating the lightness of the color

Returns:

The color as a Color

staticfromString(str:String):Null<Color>

Parses a String and returns a Color or null if the String couldn't be parsed.

Examples (input -> output in hex):

  • 0x00FF00 -> 0x00FF00
  • #0000FF -> 0x0000FF
  • GRAY -> 0x808080
  • blue -> 0x0000FF

Parameters:

str

The string to be parsed

Returns:

A Color or null if the String couldn't be parsed

staticgetHSBColorWheel():Array<Color>

Get HSB color wheel values in an array which will be 360 elements in size

Returns:

HSB color wheel as Array of Colors

@:value({ factor : 0.5 })staticinlineinterpolate(color1:Color, color2:Color, factor:Float = 0.5):Color

Get an interpolated color based on two different colors.

Parameters:

color1

The first color

color2

The second color

factor

value from 0 to 1 representing how much to shift color1 toward color2

Returns:

The interpolated color

staticgradient(color1:Color, color2:Color, steps:Int, ?ease:Float ‑> Float):Array<Color>

Create a gradient from one color to another

Parameters:

color1

The color to shift from

color2

The color to shift to

steps

How many colors the gradient should have

ease

An optional easing function, such as those provided in FlxEase

Returns:

An array of colors of length steps, shifting from color1 to color2

@:op(A * B)staticinlinemultiply(lhs:Color, rhs:Color):Color

Multiply the RGB channels of two Colors

@:op(A + B)staticinlineadd(lhs:Color, rhs:Color):Color

Add the RGB channels of two Colors

@:op(A - B)staticinlinesubtract(lhs:Color, rhs:Color):Color

Subtract the RGB channels of one Color from another

@:value({ prefix : true })staticinlinetoHexString(this:Int, prefix:Bool = true):String

Return a String representation of the color in the format

Parameters:

prefix

Whether to include "0x" prefix at start of string

Returns:

A string of length 8 in the format 0xRRGGBB

staticinlinetoWebString(this:Int):String

Return a String representation of the color in the format #RRGGBB

Returns:

A string of length 7 in the format #RRGGBB

staticgetColorInfo(this:Int):String

Get a string of color information about this color

Returns:

A string containing information about this color

@:value({ factor : 0.2 })staticgetDarkened(this:Int, factor:Float = 0.2):Color

Get a darkened version of this color

Parameters:

factor

value from 0 to 1 of how much to progress toward black.

Returns:

A darkened version of this color

@:value({ factor : 0.2 })staticinlinegetLightened(this:Int, factor:Float = 0.2):Color

Get a lightened version of this color

Parameters:

factor

value from 0 to 1 of how much to progress toward white.

Returns:

A lightened version of this color

staticinlinegetInverted(this:Int):Color

Get the inversion of this color

Returns:

The inversion of this color

staticinlinesetRGB(this:Int, red:Int, green:Int, blue:Int):Color

Set RGB values as integers (0 to 255)

Parameters:

red

The red value of the color from 0 to 255

green

The green value of the color from 0 to 255

blue

The green value of the color from 0 to 255

Returns:

This color

staticinlinesetRGBFloat(this:Int, red:Float, green:Float, blue:Float):Color

Set RGB values as floats (0 to 1)

Parameters:

red

The red value of the color from 0 to 1

green

The green value of the color from 0 to 1

blue

The green value of the color from 0 to 1

Returns:

This color

staticinlinesetCMYK(this:Int, cyan:Float, magenta:Float, yellow:Float, black:Float):Color

Set CMYK values as floats (0 to 1)

Parameters:

cyan

The cyan value of the color from 0 to 1

magenta

The magenta value of the color from 0 to 1

yellow

The yellow value of the color from 0 to 1

black

The black value of the color from 0 to 1

Returns:

This color

staticinlinesetHSB(this:Int, hue:Float, saturation:Float, brightness:Float):Color

Set HSB (aka HSV) components

Parameters:

hue

A number between 0 and 360, indicating position on a color strip or wheel.

saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

brightness

(aka value) A number between 0 and 1, indicating how bright the color should be. 0 is black, 1 is full bright.

Returns:

This color

staticinlinesetHSL(this:Int, hue:Float, saturation:Float, lightness:Float):Color

Set HSL components.

Parameters:

hue

A number between 0 and 360, indicating position on a color strip or wheel.

saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

lightness

A number between 0 and 1, indicating the lightness of the color

Returns:

This color

staticinlinetoString(this:Int):String

staticinlinefromHSLuv(hue:Float, saturation:Float, lightness:Float):Color

Generate a color from HSLuv components.

Parameters:

hue

A number between 0 and 360, indicating position on a color strip or wheel.

saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

lightness

A number between 0 and 1, indicating the lightness of the color

Returns:

The color as a Color

staticinlinesetHSLuv(this:Int, hue:Float, saturation:Float, lightness:Float):Color

Set HSLuv components.

Parameters:

hue

A number between 0 and 360, indicating position on a color strip or wheel.

saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

lightness

A number between 0 and 1, indicating the lightness of the color

Returns:

This color

staticinlinegetHSLuv(this:Int, ?result:Array<Float>):Array<Float>

Get HSLuv components from the color instance.

Parameters:

result

A pre-allocated array to store the result into.

Returns:

The HSLuv components as a float array