Skip to content

Commit

Permalink
more flxcolor
Browse files Browse the repository at this point in the history
Co-authored-by: TheLeerName <[email protected]>
Co-authored-by: Leer <[email protected]>
  • Loading branch information
3 people authored Aug 4, 2024
1 parent 85de821 commit 2335c8f
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 53 deletions.
108 changes: 108 additions & 0 deletions source/psychlua/CustomFlxColor.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package psychlua;

#if HSCRIPT_ALLOWED
@:publicFields
class CustomFlxColor
{
static var instance:CustomFlxColor = new CustomFlxColor();
function new() {}

// colors
var TRANSPARENT(default, null):Int = FlxColor.TRANSPARENT;
var WHITE(default, null):Int = FlxColor.WHITE;
var GRAY(default, null):Int = FlxColor.GRAY;
var BLACK(default, null):Int = FlxColor.BLACK;

var GREEN(default, null):Int = FlxColor.GREEN;
var LIME(default, null):Int = FlxColor.LIME;
var YELLOW(default, null):Int = FlxColor.YELLOW;
var ORANGE(default, null):Int = FlxColor.ORANGE;
var RED(default, null):Int = FlxColor.RED;
var PURPLE(default, null):Int = FlxColor.PURPLE;
var BLUE(default, null):Int = FlxColor.BLUE;
var BROWN(default, null):Int = FlxColor.BROWN;
var PINK(default, null):Int = FlxColor.PINK;
var MAGENTA(default, null):Int = FlxColor.MAGENTA;
var CYAN(default, null):Int = FlxColor.CYAN;

// new functions which original FlxColor doesnt have
function getRGB(color:Int):Array<Int> {
var flxcolor:FlxColor = FlxColor.fromInt(color);
return [flxcolor.red, flxcolor.green, flxcolor.blue, flxcolor.alpha];
}
function getRGBFloat(color:Int):Array<Float> {
var flxcolor:FlxColor = FlxColor.fromInt(color);
return [flxcolor.redFloat, flxcolor.greenFloat, flxcolor.blueFloat, flxcolor.alphaFloat];
}
function getCMYK(color:Int):Array<Float> {
var flxcolor:FlxColor = FlxColor.fromInt(color);
return [flxcolor.cyan, flxcolor.magenta, flxcolor.yellow, flxcolor.black, flxcolor.alphaFloat];
}
function getHSB(color:Int):Array<Float> {
var flxcolor:FlxColor = FlxColor.fromInt(color);
return [flxcolor.hue, flxcolor.saturation, flxcolor.brightness, flxcolor.alphaFloat];
}
function getHSL(color:Int):Array<Float> {
var flxcolor:FlxColor = FlxColor.fromInt(color);
return [flxcolor.hue, flxcolor.saturation, flxcolor.lightness, flxcolor.alphaFloat];
}

// functions from original FlxColor, i know its unreadable, but u can find them in https://api.haxeflixel.com/flixel/util/FlxColor.html
function fromRGB(Red:Int, Green:Int, Blue:Int, Alpha:Int = 255):Int
return cast FlxColor.fromRGB(Red, Green, Blue, Alpha);
function fromRGBFloat(Red:Float, Green:Float, Blue:Float, Alpha:Float = 1):Int
return cast FlxColor.fromRGBFloat(Red, Green, Blue, Alpha);
function fromCMYK(Cyan:Float, Magenta:Float, Yellow:Float, Black:Float, Alpha:Float = 1):Int
return cast FlxColor.fromCMYK(Cyan, Magenta, Yellow, Black, Alpha);
function fromHSB(Hue:Float, Sat:Float, Brt:Float, Alpha:Float = 1):Int
return cast FlxColor.fromHSB(Hue, Sat, Brt, Alpha);
function fromHSL(Hue:Float, Sat:Float, Light:Float, Alpha:Float = 1):Int
return cast FlxColor.fromHSL(Hue, Sat, Light, Alpha);
function fromString(str:String):Int
return cast FlxColor.fromString(str);
function getHSBColorWheel(Alpha:Int = 255):Array<Int>
return cast FlxColor.getHSBColorWheel(Alpha);
function interpolate(Color1:Int, Color2:Int, Factor:Float = 0.5):Int
return cast FlxColor.interpolate(Color1, Color2, Factor);
function gradient(Color1:Int, Color2:Int, Steps:Int, ?Ease:Float->Float):Array<Int>
return cast FlxColor.gradient(Color1, Color2, Steps, Ease);
function multiply(lhs:Int, rhs:Int):Int
return cast FlxColor.multiply(lhs, rhs);
function add(lhs:Int, rhs:Int):Int
return cast FlxColor.add(lhs, rhs);
function subtract(lhs:Int, rhs:Int):Int
return cast FlxColor.subtract(lhs, rhs);
function getComplementHarmony(color:Int):Int
return cast FlxColor.fromInt(color).getComplementHarmony();
function getAnalogousHarmony(color:Int, Threshold:Int = 30):CustomHarmony
return cast FlxColor.fromInt(color).getAnalogousHarmony(Threshold);
function getSplitComplementHarmony(color:Int, Threshold:Int = 30):CustomHarmony
return cast FlxColor.fromInt(color).getSplitComplementHarmony(Threshold);
function getTriadicHarmony(color:Int):CustomTriadicHarmony
return cast FlxColor.fromInt(color).getTriadicHarmony();
function to24Bit(color:Int):Int
return color & 0xffffff;
function toHexString(color:Int, Alpha:Bool = true, Prefix:Bool = true):String
return cast FlxColor.fromInt(color).toHexString(Alpha, Prefix);
function toWebString(color:Int):String
return cast FlxColor.fromInt(color).toWebString();
function getColorInfo(color:Int):String
return cast FlxColor.fromInt(color).getColorInfo();
function getDarkened(color:Int, Factor:Float = 0.2):Int
return cast FlxColor.fromInt(color).getDarkened(Factor);
function getLightened(color:Int, Factor:Float = 0.2):Int
return cast FlxColor.fromInt(color).getLightened(Factor);
function getInverted(color:Int):Int
return cast FlxColor.fromInt(color).getInverted();
}
typedef CustomHarmony = {
original:Int,
warmer:Int,
colder:Int
}
typedef CustomTriadicHarmony = {
color1:Int,
color2:Int,
color3:Int
}
#end
55 changes: 2 additions & 53 deletions source/psychlua/HScript.hx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class HScript extends SScript
set('FlxTimer', flixel.util.FlxTimer);
set('FlxTween', flixel.tweens.FlxTween);
set('FlxEase', flixel.tweens.FlxEase);
set('FlxColor', CustomFlxColor);
set('FlxColor', CustomFlxColor.instance);
set('Countdown', backend.BaseStage.Countdown);
set('PlayState', PlayState);
set('Paths', Paths);
Expand Down Expand Up @@ -438,55 +438,4 @@ class HScript extends SScript
super.destroy();
}
}

class CustomFlxColor {
public static var TRANSPARENT(default, null):Int = FlxColor.TRANSPARENT;
public static var BLACK(default, null):Int = FlxColor.BLACK;
public static var WHITE(default, null):Int = FlxColor.WHITE;
public static var GRAY(default, null):Int = FlxColor.GRAY;

public static var GREEN(default, null):Int = FlxColor.GREEN;
public static var LIME(default, null):Int = FlxColor.LIME;
public static var YELLOW(default, null):Int = FlxColor.YELLOW;
public static var ORANGE(default, null):Int = FlxColor.ORANGE;
public static var RED(default, null):Int = FlxColor.RED;
public static var PURPLE(default, null):Int = FlxColor.PURPLE;
public static var BLUE(default, null):Int = FlxColor.BLUE;
public static var BROWN(default, null):Int = FlxColor.BROWN;
public static var PINK(default, null):Int = FlxColor.PINK;
public static var MAGENTA(default, null):Int = FlxColor.MAGENTA;
public static var CYAN(default, null):Int = FlxColor.CYAN;

public static function fromInt(Value:Int):Int
{
return cast FlxColor.fromInt(Value);
}

public static function fromRGB(Red:Int, Green:Int, Blue:Int, Alpha:Int = 255):Int
{
return cast FlxColor.fromRGB(Red, Green, Blue, Alpha);
}
public static function fromRGBFloat(Red:Float, Green:Float, Blue:Float, Alpha:Float = 1):Int
{
return cast FlxColor.fromRGBFloat(Red, Green, Blue, Alpha);
}

public static inline function fromCMYK(Cyan:Float, Magenta:Float, Yellow:Float, Black:Float, Alpha:Float = 1):Int
{
return cast FlxColor.fromCMYK(Cyan, Magenta, Yellow, Black, Alpha);
}

public static function fromHSB(Hue:Float, Sat:Float, Brt:Float, Alpha:Float = 1):Int
{
return cast FlxColor.fromHSB(Hue, Sat, Brt, Alpha);
}
public static function fromHSL(Hue:Float, Sat:Float, Light:Float, Alpha:Float = 1):Int
{
return cast FlxColor.fromHSL(Hue, Sat, Light, Alpha);
}
public static function fromString(str:String):Int
{
return cast FlxColor.fromString(str);
}
}
#end
#end

0 comments on commit 2335c8f

Please sign in to comment.