Skip to content
/ Color Public

A Roblox Luau library for color management and manipulation

License

Notifications You must be signed in to change notification settings

Blupo/Color

Repository files navigation

Color

Install Documentation

Color is a Roblox Luau library for color management and manipulation, inspired by chroma.js.

Installing

The module is available in the library here if you want to install it using the Toolbox. You can also grab a release from GitHub and install it manually.

If you know how to use Rojo, you can build the latest code from the development branch to get the newest features. Keep in mind that this is development code, and things can break or change quickly.

Features

Some of the library's features includes:

  • Reading colors from many different formats
  • Converting colors to many different formats
  • Color interpolation in different spaces
  • Creating gradients

For a full introduction to the library, you can read the documentation. Some example code of the library's features is included below:

-- Accessing the modules
local ColorLib = require(...)

local Color = ColorLib.Color
local Gradient = ColorLib.Gradient

-- Constructors
local pink = Color.fromHex("#ff69b4")
local blue = Color.from("HSB", 240, 1, 1)
local yellow = Color.fromLab(0.97139, -0.21554, 0.94478)

local newYeller = Color.fromBrickColor(BrickColor.new("New Yeller"))
local white = Color.new(1, 1, 1) -- or Color.gray(1)

local hotpink = Color.named("hotpink")

-- Conversions
print(blue:toHex()) --> "0000ff"
print(blue:toHSB()) --> 240, 1, 1
print(blue:to("Lab")) --> 0.32297, 0.79188, -1.07860
print(blue:components()) --> 0, 0, 1

-- Interpolation
local red = Color.named("red")
local aqua = Color.named("aqua")

red:mix(aqua, 0.5)
red:mix(aqua, 0.5, "XYZ")
red:mix(aqua, 0.5, "Lab")
red:mix(aqua, 0.5, "Luv")

-- Gradients
local gradient = Gradient.fromColors(
    Color.named("red"),
    Color.named("green"),
    Color.named("blue")
)

print(gradient:color(0.6, "XYZ"):toHex()) --> "00737c"
print(gradient:color(0.6, "HSB", "Increasing"):to("Hex")) --> "00993d"

gradient:colors(50, "XYZ")
gradient:colorSequence(nil, "XYZ")