Difference between revisions of "Colors (API)"
From ComputerCraft Wiki
(zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz) |
(Small clarification to text, show return values, use type template, update a description to match detail page) |
||
Line 1: | Line 1: | ||
The Colors API allows you to utilize Bundled Cables from the RedPower mod, and colors on [[Advanced Computer|Advanced Computers]] and [[Advanced Monitor|Advanced Monitors]]. | The Colors API allows you to utilize Bundled Cables from the RedPower mod, and colors on [[Advanced Computer|Advanced Computers]] and [[Advanced Monitor|Advanced Monitors]]. | ||
− | For the non-American English version just replace ' | + | 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). |
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;"> | <table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;"> | ||
− | <tr><td colspan=" | + | <tr><td colspan="3" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;"> |
[[File:Grid_disk.png|24px]] | [[File:Grid_disk.png|24px]] | ||
colors (API) | colors (API) | ||
</td></tr> | </td></tr> | ||
− | <tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr> | + | <tr><td style="width: 100px; background: #E0E0E0; padding: .4em; font-weight:bold;">Return</td><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr> |
− | <tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[colors.combine]](color1, color2, …)</td> | + | <tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|int}} value</td> |
+ | <td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[colors.combine]]({{Type|int}} color1, {{Type|int}} color2, …)</td> | ||
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Combines a set of colors (or sets of colors) into a larger set.</td></tr> | <td style="border-top: solid #C9C9C9 1px; padding: .4em;">Combines a set of colors (or sets of colors) into a larger set.</td></tr> | ||
− | <tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[colors.subtract]](colors, color1, color2, …)</td> | + | <tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|int}} value</td> |
+ | <td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[colors.subtract]]({{Type|int}} colors, {{Type|int}} color1, {{Type|int}} color2, …)</td> | ||
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Removes one or more colors (or sets of colors) from an initial set.</td></tr> | <td style="border-top: solid #C9C9C9 1px; padding: .4em;">Removes one or more colors (or sets of colors) from an initial set.</td></tr> | ||
− | <tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[colors.test]](colors, color)</td> | + | <tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|boolean}} value</td> |
− | <td style="border-top: solid #C9C9C9 1px; padding: .4em;">Tests whether | + | <td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[colors.test]]({{Type|int}} colors, {{Type|int}} color)</td> |
+ | <td style="border-top: solid #C9C9C9 1px; padding: .4em;">Tests whether <var>color</var> is contained within <var>colors</var>.</td></tr> | ||
</table> | </table> |
Revision as of 14:23, 22 April 2013
The Colors API allows you to utilize Bundled Cables from the RedPower 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).
Return | Method Name | Description |
int value | colors.combine(int color1, int color2, …) | Combines a set of colors (or sets of colors) into a larger set. |
int value | colors.subtract(int colors, int color1, int color2, …) | Removes one or more colors (or sets of colors) from an initial set. |
boolean value | colors.test(int colors, int color) | Tests whether color is contained within colors. |
Note: Since the colors are just integers, the standard addition (+) and subtraction (-) operators may be used on colors instead of colors.combine and colors.subtract.
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
Color constants include, in ascending bit order:
Color | Decimal | Hexadecimal | Binary |
---|---|---|---|
colors.white | 1 | 0x1 | 0000000000000001 |
colors.orange | 2 | 0x2 | 0000000000000010 |
colors.magenta | 4 | 0x4 | 0000000000000100 |
colors.lightBlue | 8 | 0x8 | 0000000000001000 |
colors.yellow | 16 | 0x10 | 0000000000010000 |
colors.lime | 32 | 0x20 | 0000000000100000 |
colors.pink | 64 | 0x40 | 0000000001000000 |
colors.gray | 128 | 0x80 | 0000000010000000 |
colors.lightGray | 256 | 0x100 | 0000000100000000 |
colors.cyan | 512 | 0x200 | 0000001000000000 |
colors.purple | 1024 | 0x400 | 0000010000000000 |
colors.blue | 2048 | 0x800 | 0000100000000000 |
colors.brown | 4096 | 0x1000 | 0001000000000000 |
colors.green | 8192 | 0x2000 | 0010000000000000 |
colors.red | 16384 | 0x4000 | 0100000000000000 |
colors.black | 32768 | 0x8000 | 1000000000000000 |