Color: Difference between revisions
(3 intermediate revisions by one other user not shown) | |||
Line 6: | Line 6: | ||
==Single value format== | ==Single value format== | ||
For optimal compatibility between formats which only allow the reading and setting of a single value, the color can be read and stored as a single value as well. The numeric value corresponds to an RGB color value, calculated by combining the red, green and blue values of the desired color together, multiplied by powers of 256. The amount of red, green, and blue are values between 0 and 255, inclusive. These are added to a base value of -16777216. A proper color value can be calculated as follows: -16777216 + (red * 256²) + (green * 256) + (blue) | For optimal compatibility between formats which only allow the reading and setting of a single value, the color can be read and stored as a single value as well. The numeric value corresponds to an RGB color value, calculated by combining the red, green and blue values of the desired color together, multiplied by powers of 256. The amount of red, green, and blue are values between 0 and 255, inclusive. These are added to a base value of -16777216. | ||
A proper color value can be calculated as follows: | |||
{{code|1=color = -16777216 + (red * 256²) + (green * 256) + (blue)</code>}} | |||
RGB values (with ranges of 0-255) can be calculated as follows: | |||
{{code|1= | |||
B = ( color + 16777216) % 256 | |||
G = (( color + 16777216) / 256 ) % 256 | |||
R = (( color + 16777216) / 256² ) % 256 | |||
}} | |||
==RGB(A) format== | ==RGB(A) format== | ||
Line 15: | Line 25: | ||
See also: [https://www.w3schools.com/html/html_colors_hex.asp HTML HEX Colors] | See also: [https://www.w3schools.com/html/html_colors_hex.asp HTML HEX Colors] | ||
{{article end | |||
|seealso= | |||
*[[ Roof color (Function Value)]] | |||
*[[Ground color (Function Value) ]] | |||
*[[Extra color (Function Value) ]] | |||
*[[Top color (Function Value) ]] | |||
* [[Color (Terrain Attribute)]] | |||
* [[Color (Panel Attribute)]] | |||
}} | |||
[[Category:unit]] | [[Category:unit]] |
Latest revision as of 12:04, 21 August 2024
Color is a usually expressed through a number of values, the combination fo which expresses an exact color. An example of such a format is RGB, in which three values represent the amount of red, blue, and green displayed respectively.
Many spatial components with attributes automatically have a "COLOR" attribute added to them, indicating the color used when the components are displayed. The value is the same as the color property of that component. When that color property is changed, the attribute is changed, and vice versa.
Color values can be configured in a couple of ways.
Single value format
For optimal compatibility between formats which only allow the reading and setting of a single value, the color can be read and stored as a single value as well. The numeric value corresponds to an RGB color value, calculated by combining the red, green and blue values of the desired color together, multiplied by powers of 256. The amount of red, green, and blue are values between 0 and 255, inclusive. These are added to a base value of -16777216.
A proper color value can be calculated as follows:
color = -16777216 + (red * 256²) + (green * 256) + (blue)
RGB values (with ranges of 0-255) can be calculated as follows:
B = ( color + 16777216) % 256 G = (( color + 16777216) / 256 ) % 256 R = (( color + 16777216) / 256² ) % 256
RGB(A) format
Using Attribute arrays, a color can also be written as a list of 3 separate values in a single attribute, representing red, green, and blue respectively. Any of these colors values van range from 0 to 255. Optionally, a 4th value can be added representing the "alpha" of the color, which indicates the opacity. This value too can range from 0 (fully transparent) to 255 (fully opaque).
HEX format
When requesting an items Color by executing a Select color (TQL) query, the result is returned in a HEX format, such that it can be used directly in HTML. A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB (blue) hexadecimal integers specify the components of the color. A hexadecimal number is represented by a number from 0 to 9 or by a letter A to F, where A represents the number 10 and F the number 15. Two hexadecimal numbers support 256 unique decimal numbers.
See also: HTML HEX Colors