Difference between revisions of "Colors (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m ({{Type|Int}} -> {{Type|Number}} (I may make Template:Type allow only certain datatypes.))
(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.)
 
(10 intermediate revisions by 7 users not shown)
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 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 Computer|Advanced Computers]] and [[Advanced Monitor|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).
 
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;">
 
<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]]&nbsp;&nbsp;
 
colors (API)
 
</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>
+
{{API table|Colors|image=Grid_disk.png|2=
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|number}} value</td>
+
{{API table/row|[[colors.combine]]({{Type|number}} color1, {{Type|number}} color2, ...)|{{type|number}} value|
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[colors.combine]]({{Type|number}} color1, {{Type|number}} color2, )</td>
+
Combines one or more colors (or sets of colors) into a larger set.
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Combines a set of colors (or sets of colors) into a larger set.</td></tr>
+
|odd}}
  
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|number}} value</td>
+
{{API table/row|[[colors.subtract]]({{Type|number}} colors, {{Type|number}} color1, {{Type|number}} color2, ...)|{{type|number}} value|
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[colors.subtract]]({{Type|number}} colors, {{Type|number}} color1, {{Type|number}} color2, )</td>
+
Removes one or more colors (or sets of colors) from an initial set.
<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;">{{Type|boolean}} value</td>
+
{{API table/row|[[colors.test]]({{type|number}} colors, {{type|number}} color)|{{type|boolean}} contained|
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[colors.test]]({{Type|number}} colors, {{Type|number}} color)</td>
+
Tests whether ''color'' is contained within '''colors'''.
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Tests whether <var>color</var> is contained within <var>colors</var>.</td></tr>
+
|odd}}
  
</table>
+
}}
  
  
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.  
+
'''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<pre>print(colors.white + colors.white)</pre>will output 2 which is orange as opposed to<pre>print(colors.combine(colors.white, colors.white))</pre>will output 1 which is white.
  
 
Furthermore, the [[Bit (API)]] may be used on sets of colors. For example,  
 
Furthermore, the [[Bit (API)]] may be used on sets of colors. For example,  
Line 46: Line 41:
  
 
==Colors==
 
==Colors==
Color constants include, in ascending bit order:
+
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).
  
{| class="wikitable" width="200px"
+
{| class="wikitable" style="text-align:right;"
 
! Color
 
! Color
 
! Decimal
 
! Decimal
 
! Hexadecimal
 
! Hexadecimal
! Binary
+
! Paint
 +
! Display
 
|-
 
|-
 
| colors.white
 
| colors.white
| align="right" | 1
+
| 1
| align="right" | 0x1
+
| 0x1
| align="right" | 0000000000000001
+
| 0
 +
| style="background-color:#F0F0F0;" | #F0F0F0
 
|-
 
|-
 
| colors.orange
 
| colors.orange
| align="right" | 2
+
| 2
| align="right" | 0x2
+
| 0x2
| align="right" | 0000000000000010
+
| 1
 +
| style="background-color:#F2B233;" | #F2B233
 
|-
 
|-
 
| colors.magenta
 
| colors.magenta
| align="right" | 4
+
| 4
| align="right" | 0x4
+
| 0x4
| align="right" | 0000000000000100
+
| 2
 +
| style="background-color:#E57FD8;" | #E57FD8
 
|-
 
|-
 
| colors.lightBlue
 
| colors.lightBlue
| align="right" | 8
+
| 8
| align="right" | 0x8
+
| 0x8
| align="right" | 0000000000001000
+
| 3
 +
| style="background-color:#99B2F2;" | #99B2F2
 
|-
 
|-
 
| colors.yellow
 
| colors.yellow
| align="right" | 16
+
| 16
| align="right" | 0x10
+
| 0x10
| align="right" | 0000000000010000
+
| 4
 +
| style="background-color:#DEDE6C;" | #DEDE6C
 
|-
 
|-
 
| colors.lime
 
| colors.lime
| align="right" | 32
+
| 32
| align="right" | 0x20
+
| 0x20
| align="right" | 0000000000100000
+
| 5
 +
| style="background-color:#7FCC19;" | #7FCC19
 
|-
 
|-
 
| colors.pink
 
| colors.pink
| align="right" | 64
+
| 64
| align="right" | 0x40
+
| 0x40
| align="right" | 0000000001000000
+
| 6
 +
| style="background-color:#F2B2CC;" | #F2B2CC
 
|-
 
|-
 
| colors.gray
 
| colors.gray
| align="right" | 128
+
| 128
| align="right" | 0x80
+
| 0x80
| align="right" | 0000000010000000
+
| 7
 +
| style="background-color:#4C4C4C;" | #4C4C4C
 
|-
 
|-
 
| colors.lightGray
 
| colors.lightGray
| align="right" | 256
+
| 256
| align="right" | 0x100
+
| 0x100
| align="right" | 0000000100000000
+
| 8
 +
| style="background-color:#999999;" | #999999
 
|-
 
|-
 
| colors.cyan
 
| colors.cyan
| align="right" | 512
+
| 512
| align="right" | 0x200
+
| 0x200
| align="right" | 0000001000000000
+
| 9
 +
| style="background-color:#4C99B2;" | #4C99B2
 
|-
 
|-
 
| colors.purple
 
| colors.purple
| align="right" | 1024
+
| 1024
| align="right" | 0x400
+
| 0x400
| align="right" | 0000010000000000
+
| a
 +
| style="background-color:#B266E5;" | #B266E5
 
|-
 
|-
 
| colors.blue
 
| colors.blue
| align="right" | 2048
+
| 2048
| align="right" | 0x800
+
| 0x800
| align="right" | 0000100000000000
+
| b
 +
| style="background-color:#3366CC;" | #3366CC
 
|-
 
|-
 
| colors.brown
 
| colors.brown
| align="right" | 4096
+
| 4096
| align="right" | 0x1000
+
| 0x1000
| align="right" | 0001000000000000
+
| c
 +
| style="background-color:#7F664C;" | #7F664C
 
|-
 
|-
 
| colors.green
 
| colors.green
| align="right" | 8192
+
| 8192
| align="right" | 0x2000
+
| 0x2000
| align="right" | 0010000000000000
+
| d
 +
| style="background-color:#57A64E;" | #57A64E
 
|-
 
|-
 
| colors.red
 
| colors.red
| align="right" | 16384
+
| 16384
| align="right" | 0x4000
+
| 0x4000
| align="right" | 0100000000000000
+
| e
 +
| style="background-color:#CC4C4C;" | #CC4C4C
 
|-
 
|-
 
| colors.black
 
| colors.black
| align="right" | 32768
+
| 32768
| align="right" | 0x8000
+
| 0x8000
| align="right" | 1000000000000000
+
| f
 +
| style="background-color:#191919; color:#FFFFFF;" | #191919
 
|}
 
|}
 
[[Category:APIs]]
 
[[Category:APIs]]

Latest revision as of 16:35, 12 January 2019

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