diff --git a/flixel/util/FlxColor.hx b/flixel/util/FlxColor.hx index 48cab5013..1df39ea6b 100644 --- a/flixel/util/FlxColor.hx +++ b/flixel/util/FlxColor.hx @@ -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; /** @@ -355,6 +361,8 @@ abstract FlxColor(Int) from Int from UInt to Int to UInt return {color1: this, color2: triadic1, color3: triadic2}; } + + /** * Return a 24 bit version of this color (i.e. without an alpha value) * @@ -741,6 +749,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;