[ view source ]
abstract Color(Int)
package ceramic
from Int, UInt to Int, UInt,
Available on all targets
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
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]
Static methods
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>
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
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
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
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
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
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