Legacy BrickColor Library

This module is an emulation of the old BrickColor library, as it was circa 2009. With it, you can limit yourself exclusively to the exact BrickColor values that once painted Robloxia’s past.

Features: All functions that were originally present in the modeled library–and their various casings.

-- palette: Returns a legacy BrickColor from its original paletteValue.
BrickColor.palette(paletteValue: number 0 - 63) -> BrickColor
-- Random: Returns a random legacy BrickColor. Random seed is constant.
BrickColor.random/Random() -> BrickColor
-- Constructor: Takes Number, Name, or approximate RGB; returns legacy BrickColor.
BrickColor.new/New(val: string | number, number?, number?) -> BrickColor
-- Misc. Color Functions: returns the legacy BrickColor the name suggests
BrickColor.Blue() -> BrickColor -- "Bright blue"
BrickColor.White() -> BrickColor -- "White"
BrickColor.Yellow() -> BrickColor -- "Bright yellow"
BrickColor.Red() -> BrickColor -- "Bright red"
BrickColor.Gray() -> BrickColor -- "Medium stone grey"
BrickColor.Black() -> BrickColor -- "Black"
BrickColor.Green() -> BrickColor -- "Dark green"
BrickColor.DarkGray() -> BrickColor -- "Dark stone grey"

Type declarations are implemented for editor convenience.

Update I - Initial Cleanup

  • Performance of the RGB constructor for BrickColor.new/New() now more in line with that of Roblox’s implementation–additional optimizations are planned.
  • Old BrickColors that were not part of the palette are now supported in BrickColor.new/New. To reduce clutter however, type-checking only supports suggestions for colors on the palette.
  • For the sake of convenience, added _BrickColorDump: an internal property which holds an immutable array of every legacy BrickColor value. Any API additions not present in the original library are prefixed with an underscore, and will not appear in type-checking.
  • Type declarations adjusted to allow calling BrickColor.new/New() with no arguments, or with undeclared BrickColor names.

Update II - Crunching the Numbers

  • As promised, I’ve reworked the algorithm for the .new/.New() RGB constructor. It’s now faster on average–though still ever so slightly slower than Roblox’s current algorithm. This is largely due to the existence of some ‘bad ranges’ (inputs which will consistently yield worst-case complexity). I’ll be looking into optimizing them out at some point.
  • By virtue of this algorithm’s design, I’ve added a new hidden property: _BrickColorsByClosest. This is an immutable table, where every key is a legacy BrickColor value, mapped to its nearest neighbor (in terms of raw RGB value).

Update III will be substantial, as it will focus on finally bringing the finer aspects of the library’s behavior closer to the original. Happy scripting.

5 Likes