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

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

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

@author Joe Williamson (JoeCreates)

Constructor

new(Value:Int = 0)

Variables

brightness:Float

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

hue:Float

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

lightness:Float

The lightness of the color (from 0 to 1)

saturation:Float

The saturation of the color (from 0 to 1)

Methods

inlinegetAnalogousHarmony(Threshold:Int = 30):Harmony

Returns an Analogous Color Harmony for the given color. An Analogous harmony are hues adjacent to each other on the color wheel

Parameters:

Threshold

Control how adjacent the colors will be (default +- 30 degrees)

Returns:

Object containing 3 properties: original (the original color), warmer (the warmer analogous color) and colder (the colder analogous color)

getColorInfo():String

Get a string of color information about this color

Returns:

A string containing information about this color

inlinegetComplementHarmony():FlxColor

Returns a Complementary Color Harmony of this color. A complementary hue is one directly opposite the color given on the color wheel

Returns:

The complimentary color

getDarkened(Factor:Float = 0.2):FlxColor

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

inlinegetInverted():FlxColor

Get the inversion of this color

Returns:

The inversion of this color

inlinegetLightened(Factor:Float = 0.2):FlxColor

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

inlinegetSplitComplementHarmony(Threshold:Int = 30):Harmony

Returns an Split Complement Color Harmony for this color. A Split Complement harmony are the two hues on either side of the color's Complement

Parameters:

Threshold

Control how adjacent the colors will be to the Complement (default +- 30 degrees)

Returns:

Object containing 3 properties: original (the original color), warmer (the warmer analogous color) and colder (the colder analogous color)

inlinegetTriadicHarmony():TriadicHarmony

Returns a Triadic Color Harmony for this color. A Triadic harmony are 3 hues equidistant from each other on the color wheel.

Returns:

Object containing 3 properties: color1 (the original color), color2 and color3 (the equidistant colors)

inlinesetCMYK(Cyan:Float, Magenta:Float, Yellow:Float, Black:Float, Alpha:Float = 1):FlxColor

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

Alpha

How opaque the color should be, from 0 to 1

Returns:

This color

inlinesetHSB(Hue:Float, Saturation:Float, Brightness:Float, Alpha:Float):FlxColor

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.

Alpha

How opaque the color should be, either between 0 and 1 or 0 and 255.

Returns:

This color

inlinesetHSL(Hue:Float, Saturation:Float, Lightness:Float, Alpha:Float):FlxColor

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

Alpha

How opaque the color should be, either between 0 and 1 or 0 and 255

Returns:

This color

inlinesetRGB(Red:Int, Green:Int, Blue:Int, Alpha:Int = 255):FlxColor

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

Alpha

How opaque the color should be, from 0 to 255

Returns:

This color

inlinesetRGBFloat(Red:Float, Green:Float, Blue:Float, Alpha:Float = 1):FlxColor

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

Alpha

How opaque the color should be, from 0 to 1

Returns:

This color

inlineto24Bit():FlxColor

Return a 24 bit version of this color (i.e. without an alpha value)

Returns:

A 24 bit version of this color

inlinetoHexString(Alpha:Bool = true, Prefix:Bool = true):String

Return a String representation of the color in the format

Parameters:

Alpha

Whether to include the alpha value in the hes string

Prefix

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

Returns:

A string of length 10 in the format 0xAARRGGBB

inlinetoWebString():String

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

Returns:

A string of length 7 in the format #RRGGBB

Static variables

staticinlineread onlyBLACK:FlxColor = 0xFF000000

staticinlineread onlyBLUE:FlxColor = 0xFF0000FF

staticinlineread onlyBROWN:FlxColor = 0xFF8B4513

staticinlineread onlyCYAN:FlxColor = 0xFF00FFFF

staticinlineread onlyGRAY:FlxColor = 0xFF808080

staticinlineread onlyGREEN:FlxColor = 0xFF008000

staticinlineread onlyLIME:FlxColor = 0xFF00FF00

staticinlineread onlyMAGENTA:FlxColor = 0xFFFF00FF

staticinlineread onlyORANGE:FlxColor = 0xFFFFA500

staticinlineread onlyPINK:FlxColor = 0xFFFFC0CB

staticinlineread onlyPURPLE:FlxColor = 0xFF800080

staticinlineread onlyRED:FlxColor = 0xFFFF0000

staticinlineread onlyTRANSPARENT:FlxColor = 0x00000000

staticinlineread onlyWHITE:FlxColor = 0xFFFFFFFF

staticinlineread onlyYELLOW:FlxColor = 0xFFFFFF00

staticread onlycolorLookup:Map<String, Int> = FlxMacroUtil.buildMap("flixel.util.FlxColor")

A Map<String, Int> whose values are the static colors of FlxColor. You can add more colors for FlxColor.fromString(String) if you need.

Static methods

staticinlineadd(lhs:FlxColor, rhs:FlxColor):FlxColor

Add the RGB channels of two FlxColors

staticinlinefromCMYK(Cyan:Float, Magenta:Float, Yellow:Float, Black:Float, Alpha:Float = 1):FlxColor

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

Alpha

How opaque the color should be, from 0 to 1

Returns:

The color as a FlxColor

staticfromHSB(Hue:Float, Saturation:Float, Brightness:Float, Alpha:Float = 1):FlxColor

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.

Alpha

How opaque the color should be, either between 0 and 1 or 0 and 255.

Returns:

The color as a FlxColor

staticinlinefromHSL(Hue:Float, Saturation:Float, Lightness:Float, Alpha:Float = 1):FlxColor

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

Alpha

How opaque the color should be, either between 0 and 1 or 0 and 255.

Returns:

The color as a FlxColor

staticinlinefromInt(Value:Int):FlxColor

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

Parameters:

Value

And Int with bytes in the format 0xAARRGGBB

Returns:

The color as a FlxColor

staticinlinefromRGB(Red:Int, Green:Int, Blue:Int, Alpha:Int = 255):FlxColor

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

Alpha

How opaque the color should be, from 0 to 255

Returns:

The color as a FlxColor

staticinlinefromRGBFloat(Red:Float, Green:Float, Blue:Float, Alpha:Float = 1):FlxColor

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

Alpha

How opaque the color should be, from 0 to 1

Returns:

The color as a FlxColor

staticfromString(str:String):Null<FlxColor>

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

Examples (input -> output in hex):

  • 0x00FF00 -> 0xFF00FF00
  • 0xAA4578C2 -> 0xAA4578C2
  • #0000FF -> 0xFF0000FF
  • #3F000011 -> 0x3F000011
  • GRAY -> 0xFF808080
  • blue -> 0xFF0000FF

Parameters:

str

The string to be parsed

Returns:

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

staticgetHSBColorWheel(Alpha:Int = 255):Array<FlxColor>

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

Parameters:

Alpha

Alpha value for each color of the color wheel, between 0 (transparent) and 255 (opaque)

Returns:

HSB color wheel as Array of FlxColors

staticgradient(Color1:FlxColor, Color2:FlxColor, Steps:Int, ?Ease:Float‑>Float):Array<FlxColor>

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

staticinlineinterpolate(Color1:FlxColor, Color2:FlxColor, Factor:Float = 0.5):FlxColor

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

staticinlinemultiply(lhs:FlxColor, rhs:FlxColor):FlxColor

Multiply the RGB channels of two FlxColors

staticinlinesubtract(lhs:FlxColor, rhs:FlxColor):FlxColor

Subtract the RGB channels of one FlxColor from another