Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions flixel/util/FlxColor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ abstract FlxColor(Int) from Int from UInt to Int to UInt
*/
public var lightness(get, set):Float;

/**
* The luminance, or "percieved brightness" of a color (from 0 to 1)
* RGB -> Luma calculation from https://www.w3.org/TR/AERT/#color-contrast
*/
public var luminance(get, never):Float;

static var COLOR_REGEX = ~/^(0x|#)(([A-F0-9]{2}){3,4})$/i;

/**
Expand Down Expand Up @@ -741,6 +747,11 @@ abstract FlxColor(Int) from Int from UInt to Int to UInt
return maxColor();
}

inline function get_luminance():Float
{
return (redFloat * 299 + greenFloat * 587 + blueFloat * 114) / 1000;
}

inline function get_saturation():Float
{
return (maxColor() - minColor()) / brightness;
Expand Down