Skip to content

Commit

Permalink
feat: add luminance variable to FlxColor (#3357)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjamuffin99 authored Feb 4, 2025
1 parent 348f108 commit 5745552
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit 5745552

Please sign in to comment.