Color: Difference between revisions

From Tygron Preview Support Wiki
Jump to navigation Jump to search
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 9: Line 9:


A proper color value can be calculated as follows:
A proper color value can be calculated as follows:
{{code|1=color = -16777216 + (red * 256²) + (green * 256) + (blue)</code>}}
{{code|1=color = -16777216 + (alpha * 256³) + (red * 256²) + (green * 256) + (blue)</code>}}


RGB values (with ranges of 0-255) can be calculated as follows:
RGB values (with ranges of 0-255) can be calculated as follows:
{{code|1=
{{code|1=
B =  ( color + 16777216)          % 256
B =  ( color + 16777216 )          % 256
G = (( color + 16777216) / 256  ) % 256
G = (( color + 16777216 ) / 256  ) % 256
R = (( color + 16777216) / 256² ) % 256
R = (( color + 16777216 ) / 256² ) % 256
}}
}}
In which the result of each division is strictly rounded down.
===Alpha value===
An alpha value is included in the calculation as follows:
{{code|1=color = ( 2147483648 + (red * 256²) + (green * 256) + (blue) ) % 4294967296 ) - 2147483648 </code>}}
RGBA values (with ranges of 0-255) can be calculated as follows:
{{code|1=
B =  ( color % 4294967296 )          % 256
G = (( color % 4294967296 ) / 256  ) % 256
R = (( color % 4294967296 ) / 256² ) % 256
A = (( color % 4294967296 ) / 256³ ) % 256
}}
In which the result of each division is strictly rounded down.


==RGB(A) format==
==RGB(A) format==
Line 26: Line 40:
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
{{article end
|notes=
* For single value notation, including a transparency (alpha) value involves adding an additional value based on a base value of 256³. However, in this situation an integer roll-over may occur while calculating the required value, which leads to the slightly more complex formula.
|seealso=
|seealso=
*[[ Roof color (Function Value)]]
* [[Roof color (Function Value)]]
*[[Ground color (Function Value) ]]
* [[Ground color (Function Value)]]
*[[Extra color (Function Value) ‎]]
* [[Extra color (Function Value)‎]]
*[[Top color (Function Value) ‎]]
* [[Top color (Function Value)‎]]
* [[Color (Terrain Attribute)]]
* [[Color (Terrain Attribute)]]
* [[Color (Panel Attribute)]]
* [[Color (Panel Attribute)]]
}}
}}
[[Category:unit]]
[[Category:unit]]

Latest revision as of 13:50, 11 February 2026

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 + (alpha * 256³) + (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

In which the result of each division is strictly rounded down.

Alpha value

An alpha value is included in the calculation as follows:

color = ( 2147483648 + (red * 256²) + (green * 256) + (blue) ) % 4294967296 ) - 2147483648 

RGBA values (with ranges of 0-255) can be calculated as follows:

B =  ( color % 4294967296 )          % 256
G = (( color % 4294967296 ) / 256  ) % 256
R = (( color % 4294967296 ) / 256² ) % 256
A = (( color % 4294967296 ) / 256³ ) % 256

In which the result of each division is strictly rounded down.

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

Notes

  • For single value notation, including a transparency (alpha) value involves adding an additional value based on a base value of 256³. However, in this situation an integer roll-over may occur while calculating the required value, which leads to the slightly more complex formula.

See also