Colors API
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The Colors API allows you to mess with colors. For the British English version just replace 'color' with 'colour' and it will use the other API, colours, which is exactly the same, except in British English (gray is grey and lightGray is lightGrey). The methods for this API are listed below.
Contents
colors.combine
Function colors.combine | |
Syntax | colors.combine(int color1, int color2, …) |
Returns | int the union of sets color1, color2, … |
Description | Computes the union of sets of colors; each parameter may be a single color or may be a set of colors |
Examples
Description | Combine white, magenta, and light blue to yield 13 (the bitwise combination of the colors) |
Code |
print(colors.combine(colors.white, colors.magenta, colours.lightBlue)) |
Output | 13 |
colors.subtract
Function colors.subtract | |
Syntax | colors.subtract(int colors, int color1, int color2, …) |
Returns | int the set colors after removing sets color1, color2, … |
Description | Computes the difference of a set by removing colors from it; 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) |
Examples
Description | Beginning with white, magenta, and light blue, remove magenta to yield 9 (the bitwise combination of white and light blue) |
Code |
print(colors.subtract(colors.combine(colors.white, colors.magenta, colours.lightBlue), colors.magenta)) |
Output | 9 |
colors.test
Function colors.test | |
Syntax | colors.test(int colors, int color) |
Returns | boolean whether or not all elements of color are contained in the set colors |
Description | Tests whether color is contained within colors; color may be a single color or may be a set of colors (in the latter case, true is returned only if all colors in color are contained in colors) |
Examples
Description | Combine white, magenta, and light blue, then check if light blue is within the set |
Code |
print(colors.test(colors.combine(colors.white, colors.magenta, colours.lightBlue), colors.lightBlue)) |
Output | true |
Colors
Color constants include, in ascending bit order:
Color | Decimal | Hexadecimal |
---|---|---|
colors.white | 1 | 0x1 |
colors.orange | 2 | 0x2 |
colors.magenta | 4 | 0x4 |
colors.lightBlue | 8 | 0x8 |
colors.yellow | 16 | 0x10 |
colors.lime | 32 | 0x20 |
colors.pink | 64 | 0x40 |
colors.gray | 128 | 0x80 |
colors.lightGray | 256 | 0x100 |
colors.cyan | 512 | 0x200 |
colors.purple | 1024 | 0x400 |
colors.blue | 2048 | 0x800 |
colors.brown | 4096 | 0x1000 |
colors.green | 8192 | 0x2000 |
colors.red | 16384 | 0x4000 |
colors.black | 32768 | 0x8000 |
A example can be found here.
Retrieved from ‘http://ftb-wiki.com/w/index.php?title=Colors_API&oldid=1472’
Cookies help us deliver our services. By using our services, you agree to our use of cookies.