Color - AlsoGhostglowDev/Ghost-s-Utilities GitHub Wiki

color.lua

A utility for handling things related to color management and manipulation.

local color = require 'ghostutil.color'

Fields

Neutral Colors:

WHITE = 0xFFFFFF
GRAY = 0x808080
BLACK = 0x000000

Standard Colors:

RED = 0xFF0000
BLUE = 0x0000FF
GREEN = 0x008000
PINK = 0xFFC0CB
MAGENTA = 0xFF00FF
PURPLE = 0x800080
LIME = 0x00FF00
YELLOW = 0xFFFF00
ORANGE = 0xFFA500
CYAN = 0x00FFFF

Methods

getHexString(hex: number, ?digits: number): string

Converts 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 to 6.

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>): number

Converts 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): number

Converts 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): number

Converts 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 to 1

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): boolean

Checks 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): boolean

Checks 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): ColorChannels

Extracts 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): number

Extracts 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): number

Extracts 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): number

Extracts 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): number

Extracts 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): void

Sets 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>): void

Sets 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 are nil will 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 are nil will 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.0Docs 3.0.0, Revision 1

a Lua Library made by GhostglowDev; for Psych Engine
© 2025 GhostglowDevGhost's Utilities
Licensed under the MIT License.

⚠️ **GitHub.com Fallback** ⚠️