colors

The Colors API allows you to manipulate sets of colors.

This is useful in conjunction with Bundled Cables from the RedPower mod, RedNet Cables from the MineFactory Reloaded mod, and colors on Advanced Computers and Advanced Monitors.

For the non-American English version just replace colors with colours and it will use the other API, colours which is exactly the same, except in British English (e.g. colors.gray is spelt colours.grey).

On basic terminals (such as the Computer and Monitor), all the colors are converted to grayscale. This means you can still use all 16 colors on the screen, but they will appear as the nearest tint of gray. You can check if a terminal supports color by using the function term.isColor.

Grayscale colors are calculated by taking the average of the three components, i.e. (red + green + blue) / 3.

Default Colors
Color Value Default Palette Color
DecHexPaint/Blit PreviewHexRGBGrayscale
colors.white 10x10 #F0F0F0240, 240, 240
colors.orange 20x21 #F2B233242, 178, 51
colors.magenta 40x42 #E57FD8229, 127, 216
colors.lightBlue 80x83 #99B2F2153, 178, 242
colors.yellow 160x104 #DEDE6C222, 222, 108
colors.lime 320x205 #7FCC19127, 204, 25
colors.pink 640x406 #F2B2CC242, 178, 204
colors.gray 1280x807 #4C4C4C76, 76, 76
colors.lightGray 2560x1008 #999999153, 153, 153
colors.cyan 5120x2009 #4C99B276, 153, 178
colors.purple 10240x400a #B266E5178, 102, 229
colors.blue 20480x800b #3366CC51, 102, 204
colors.brown 40960x1000c #7F664C127, 102, 76
colors.green 81920x2000d #57A64E87, 166, 78
colors.red 163840x4000e #CC4C4C204, 76, 76
colors.black 327680x8000f #11111117, 17, 17

See also

white = 0x1White: Written as 0 in paint files and term.blit, has a default terminal colour of #F0F0F0.
orange = 0x2Orange: Written as 1 in paint files and term.blit, has a default terminal colour of #F2B233.
magenta = 0x4Magenta: Written as 2 in paint files and term.blit, has a default terminal colour of #E57FD8.
lightBlue = 0x8Light blue: Written as 3 in paint files and term.blit, has a default terminal colour of #99B2F2.
yellow = 0x10Yellow: Written as 4 in paint files and term.blit, has a default terminal colour of #DEDE6C.
lime = 0x20Lime: Written as 5 in paint files and term.blit, has a default terminal colour of #7FCC19.
pink = 0x40Pink: Written as 6 in paint files and term.blit, has a default terminal colour of #F2B2CC.
gray = 0x80Gray: Written as 7 in paint files and term.blit, has a default terminal colour of #4C4C4C.
lightGray = 0x100Light gray: Written as 8 in paint files and term.blit, has a default terminal colour of #999999.
cyan = 0x200Cyan: Written as 9 in paint files and term.blit, has a default terminal colour of #4C99B2.
purple = 0x400Purple: Written as a in paint files and term.blit, has a default terminal colour of #B266E5.
blue = 0x800Blue: Written as b in paint files and term.blit, has a default terminal colour of #3366CC.
brown = 0x1000Brown: Written as c in paint files and term.blit, has a default terminal colour of #7F664C.
green = 0x2000Green: Written as d in paint files and term.blit, has a default terminal colour of #57A64E.
red = 0x4000Red: Written as e in paint files and term.blit, has a default terminal colour of #CC4C4C.
black = 0x8000Black: Written as f in paint files and term.blit, has a default terminal colour of #111111.
combine(...)Combines a set of colors (or sets of colors) into a larger set.
subtract(colors, ...)Removes one or more colors (or sets of colors) from an initial set.
test(colors, color)Tests whether color is contained within colors.
packRGB(r, g, b)Combine a three-colour RGB value into one hexadecimal representation.
unpackRGB(rgb)Separate a hexadecimal RGB colour into its three constituent channels.
rgb8(...)Either calls colors.packRGB or colors.unpackRGB, depending on how many arguments it receives.
toBlit(color)Converts the given color to a paint/blit hex character (0-9a-f).
white = 0x1Source

White: Written as 0 in paint files and term.blit, has a default terminal colour of #F0F0F0.

orange = 0x2Source

Orange: Written as 1 in paint files and term.blit, has a default terminal colour of #F2B233.

magenta = 0x4Source

Magenta: Written as 2 in paint files and term.blit, has a default terminal colour of #E57FD8.

lightBlue = 0x8Source

Light blue: Written as 3 in paint files and term.blit, has a default terminal colour of #99B2F2.

yellow = 0x10Source

Yellow: Written as 4 in paint files and term.blit, has a default terminal colour of #DEDE6C.

lime = 0x20Source

Lime: Written as 5 in paint files and term.blit, has a default terminal colour of #7FCC19.

pink = 0x40Source

Pink: Written as 6 in paint files and term.blit, has a default terminal colour of #F2B2CC.

gray = 0x80Source

Gray: Written as 7 in paint files and term.blit, has a default terminal colour of #4C4C4C.

lightGray = 0x100Source

Light gray: Written as 8 in paint files and term.blit, has a default terminal colour of #999999.

cyan = 0x200Source

Cyan: Written as 9 in paint files and term.blit, has a default terminal colour of #4C99B2.

purple = 0x400Source

Purple: Written as a in paint files and term.blit, has a default terminal colour of #B266E5.

blue = 0x800Source

Blue: Written as b in paint files and term.blit, has a default terminal colour of #3366CC.

brown = 0x1000Source

Brown: Written as c in paint files and term.blit, has a default terminal colour of #7F664C.

green = 0x2000Source

Green: Written as d in paint files and term.blit, has a default terminal colour of #57A64E.

red = 0x4000Source

Red: Written as e in paint files and term.blit, has a default terminal colour of #CC4C4C.

black = 0x8000Source

Black: Written as f in paint files and term.blit, has a default terminal colour of #111111.

combine(...)Source

Combines a set of colors (or sets of colors) into a larger set. Useful for Bundled Cables.

Parameters

  1. ... number The colors to combine.

Returns

  1. number The union of the color sets given in ...

Usage

subtract(colors, ...)Source

Removes one or more colors (or sets of colors) from an initial set. Useful for Bundled Cables.

Each parameter beyond the first may be a single color or may be a set of colors (in the latter case, all colors in the set are removed from the original set).

Parameters

  1. colors number The color from which to subtract.
  2. ... number The colors to subtract.

Returns

  1. number The resulting color.

Usage

test(colors, color)Source

Tests whether color is contained within colors. Useful for Bundled Cables.

Parameters

  1. colors number A color, or color set
  2. color number A color or set of colors that colors should contain.

Returns

  1. boolean If colors contains all colors within color.

Usage

packRGB(r, g, b)Source

Combine a three-colour RGB value into one hexadecimal representation.

Parameters

  1. r number The red channel, should be between 0 and 1.
  2. g number The red channel, should be between 0 and 1.
  3. b number The blue channel, should be between 0 and 1.

Returns

  1. number The combined hexadecimal colour.

Usage

unpackRGB(rgb)Source

Separate a hexadecimal RGB colour into its three constituent channels.

Parameters

  1. rgb number The combined hexadecimal colour.

Returns

  1. number The red channel, will be between 0 and 1.
  2. number The red channel, will be between 0 and 1.
  3. number The blue channel, will be between 0 and 1.

Usage

See also

rgb8(...)Source
Deprecated Use packRGB or unpackRGB directly.

Either calls colors.packRGB or colors.unpackRGB, depending on how many arguments it receives.

Parameters

  1. r number The red channel, as an argument to colors.packRGB.
  2. g number The green channel, as an argument to colors.packRGB.
  3. b number The blue channel, as an argument to colors.packRGB.

Or

  1. rgb number The combined hexadecimal color, as an argument to colors.unpackRGB.

Returns

  1. number The combined hexadecimal colour, as returned by colors.packRGB.

Or

  1. number The red channel, as returned by colors.unpackRGB
  2. number The green channel, as returned by colors.unpackRGB
  3. number The blue channel, as returned by colors.unpackRGB

Usage

toBlit(color)Source

Converts the given color to a paint/blit hex character (0-9a-f).

This is equivalent to converting floor(log_2(color)) to hexadecimal.

Parameters

  1. color number The color to convert.

Returns

  1. string The blit hex code of the color.