Colors (API)

From ComputerCraft Wiki
Revision as of 16:35, 12 January 2019 by CrazedProgrammer (Talk | contribs) (Colors: Remove binary value column. This column took up tons of space and was not very useful, since people usually use hex values when dealing with binary ops.)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 non-American English (e.g. gray is spelt grey and lightGray is spelt lightGrey).

Grid disk.png  Colors (API)
Function Return values Description
colors.combine(number color1, number color2, ...) number value

Combines one or more colors (or sets of colors) into a larger set.

colors.subtract(number colors, number color1, number color2, ...) number value

Removes one or more colors (or sets of colors) from an initial set.

colors.test(number colors, number color) boolean contained

Tests whether color is contained within colors.


Note: The standard addition (+) and subtraction (-) operators while able to be used on colors instead of colors.combine and colors.subtract should be avoided due to the nature of the colour format. For example
print(colors.white + colors.white)
will output 2 which is orange as opposed to
print(colors.combine(colors.white, colors.white))
will output 1 which is white.

Furthermore, the Bit (API) may be used on sets of colors. For example,

bCableLeft  = rs.getBundledInput("left")
bCableRight = rs.getBundledInput("right")

-- Get a number representing colors on in both right and left bundled cables
commonColors    = bit.band(bCableLeft, bCableRight)

-- Get all the colors active on either right or left
totalColors     = bit.bor(bCableLeft, bCableRight)

-- Get the colors which are active on right, or left, but not both at the same time
exclusiveColors = bit.bxor(bCableLeft, bCableRight)

-- Get the colors that are not active on the left
offColorsA      = bit.bnot(bCableLeft)

Colors

The following table includes; the variable name to use in ComputerCraft programs, the decimal, and hexadecimal values of the color, the number used in the 'paint' programs save files, and the actual color used to display in the ComputerCraft mod (provided in web hexadecimal format).

Color Decimal Hexadecimal Paint Display
colors.white 1 0x1 0 #F0F0F0
colors.orange 2 0x2 1 #F2B233
colors.magenta 4 0x4 2 #E57FD8
colors.lightBlue 8 0x8 3 #99B2F2
colors.yellow 16 0x10 4 #DEDE6C
colors.lime 32 0x20 5 #7FCC19
colors.pink 64 0x40 6 #F2B2CC
colors.gray 128 0x80 7 #4C4C4C
colors.lightGray 256 0x100 8 #999999
colors.cyan 512 0x200 9 #4C99B2
colors.purple 1024 0x400 a #B266E5
colors.blue 2048 0x800 b #3366CC
colors.brown 4096 0x1000 c #7F664C
colors.green 8192 0x2000 d #57A64E
colors.red 16384 0x4000 e #CC4C4C
colors.black 32768 0x8000 f #191919