Color - AlsoGhostglowDev/Ghost-s-Utilities GitHub Wiki
A utility for handling things related to color management and manipulation.
local color = require 'ghostutil.color'Neutral Colors:
WHITE = 0xFFFFFF
GRAY = 0x808080
BLACK = 0x000000Standard Colors:
RED = 0xFF0000
BLUE = 0x0000FF
GREEN = 0x008000
PINK = 0xFFC0CB
MAGENTA = 0xFF00FF
PURPLE = 0x800080
LIME = 0x00FF00
YELLOW = 0xFFFF00
ORANGE = 0xFFA500
CYAN = 0x00FFFFgetHexString(hex: number, ?digits: number): stringConverts a hexadecimal integer to a hexadecimal string.
Parameters:
-
hex: The hexadecimal integer -
digits(optional): The amount of digits the hexadecimal string should have. Excess digits will be padded on the left. Defaults to6.
Returns: The converted hexadecimal; returns '000000' instead if hex was invalid.
View Example
-- returns "00FFABCC"
-- the "00" padded on the left was because the passed hexadecimal only contained 6 digits.
color.getHexString(0xFFABCC, 8)
-- returns "AA112233"
color.getHexString(0xAA112233)─────────────────────────
rgbToHex(rgb: table<number>): numberConverts RGB values to a 24-bit hexadecimal integer.
Parameters:
-
rgb: Table where indices 1 to 3 corresponds to red, blue, green values respectively.
Returns: The hexadecimal value.
View Example
-- returns 0xFF7D1B
color.rgbToHex({255, 125, 27})─────────────────────────
argbToRGB(argb: number): numberConverts a 32-bit hexadecimal (AARRGGBB) to a 24-bit hexadecimal following the RRGGBB rule.
Parameters:
-
argb: The 32-bit hexadecimal integer.
Returns: The 24-bit hexadecimal; returns 0x0 instead if argb was invalid.
View Example
-- returns 0xAABBCC
color.argbToRGB(0xFFAABBCC)─────────────────────────
rgbToARGB(rgb: number, ?alpha: number): numberConverts a 24-bit hexadecimal (RRGGBB) to a 32-bit hexadecimal following the AARRGGBB rule.
Parameters:
-
rgb: The 24-bit hexadecimal integer -
alpha(optional): The value of the color's alpha, ranges from 0 to 1. Defaults to1
Returns: The 32-bit hexadecimal; ; returns 0x0 instead if rgb was invalid.
View Example
-- returns 0x80AABBCC
-- the "80" is the alpha, and is the equivalent form of math.ceil(255 * 0.5) in hexadecimal.
color.rgbToARGB(0xAABBCC, 0.5)─────────────────────────
usingARGB(int: number): booleanChecks if the hexadecimal integer uses the ARGB format.
Parameters:
-
int: The hexadecimal integer.
Returns: true if int uses ARGB.
View Example
-- returns true
color.usingARGB(0xAABBCCDD)─────────────────────────
usingRGB(int: number): booleanChecks if the hexadecimal integer uses the RGB format.
Parameters:
-
int: The hexadecimal integer.
Returns: true if int uses RGB.
View Example
-- returns false
color.usingRGB(0xFFAABBCC)─────────────────────────
extractChannels(int: number): ColorChannelsExtracts the individual color channels (alpha, red, green, blue) from a hexadecimal integer.
Parameters:
-
int: The hexadecimal integer.
Returns: The color channels, refer to ColorChannels. However, the alpha value will equal 0 if the given hexadecimal didn't have an alpha channel present.
View Example
--[[
returns {
alpha = 170,
red = 187,
green = 204,
blue = 221
}
]]
color.extractChannels(0xAABBCCDD)
-- the alpha channel isn't present,
-- so, accessing the alpha field here would just return 0.
color.extractChannels(0x11A6B2)─────────────────────────
getAlpha(int: number): numberExtracts the alpha value from a hexadecimal integer.
(Shortcut to color.extractChannels(int).alpha)
Parameters:
-
int: The hexadecimal integer.
Returns: The alpha value. If the given hexadecimal didn't have an alpha channel present, it'll return 0 instead. Ranges from 0 to 1.
─────────────────────────
getRed(int: number): numberExtracts the red value from a hexadecimal integer.
(Shortcut to color.extractChannels(int).red)
Parameters:
-
int: The hexadecimal integer.
Returns: The value of red's channel. Ranges from 0 to 255.
─────────────────────────
getGreen(int: number): numberExtracts the green value from a hexadecimal integer.
(Shortcut to color.extractChannels(int).green)
Parameters:
-
int: The hexadecimal integer.
Returns: The value of green's channel. Ranges from 0 to 255.
─────────────────────────
getBlue(int: number): numberExtracts the blue value from a hexadecimal integer.
(Shortcut to color.extractChannels(int).blue)
Parameters:
-
int: The hexadecimal integer.
Returns: The value of blue's channel. Ranges from 0 to 255.
─────────────────────────
setColor(tag: string, color: number): voidSets the color multiplier of a sprite.
(Shortcut to setProperty('tag.color', color))
Parameters:
-
tag: The sprite tag. -
color: The target color; alpha channel is ignored.
View Example
-- sets boyfriend's color to a sunset-ish color
color.setColor('boyfriend', 0xFFDB8E)─────────────────────────
setColorTransform(tag: string, ?multiplier: table<number>, ?offset: table<number>): voidSets the color transform of a sprite.
(Shortcut to callMethod('tag.setColorTransform', {...}))
Parameters:
-
tag: The sprite tag -
multiplier: Table containing the red, green, blue and alpha multiplier value respectively. Those values that arenilwill be replaced with 0. Excess values are voided until table's length is 4. -
offset: Table containing the red, green, blue and alpha offset value respectively. Those values that arenilwill be replaced with 0. Excess values are voided until table's length is 4.
View Example
-- sets dad's color transform to be like bad apple's full-white color.
color.setColorTransform('dad', {0, 0, 0, 1}, {255, 255, 255, 0})
-- to reset a sprite's colorTransform, just do:
color.setColorTransform('sprite', {1, 1, 1, 1}, {0, 0, 0, 0})
GhostUtil 3.0.0 • Docs 3.0.0, Revision 1
a Lua Library made by GhostglowDev; for Psych Engine
© 2025 GhostglowDev — Ghost's Utilities
Licensed under the MIT License.