An RGB/HSB color.
A color is an immutable container for 24-bit RGB value.
Color Creation
Color companion object provides 100s of the pre-built color constants for all xterm and X11 standard colors. New color creation is an expensive process. It is highly recommended using one of the many built-in color constants or pre-create the colors you need upfront. As a rule of thumb - avoid new color creation on each frame update.
8-Bit & 24-Bit Color Depth
Most modern ANSI terminals support "True Color" 24-bit colors, the unlimited combination of Red, Green, and Blue values in RGB. Some older terminals, however, only provide support for 8-bit colors where each color is a lookup number into 256-color lookup table (LUT). These are also often called xterm colors despite the fact that xterm terminal application does support the 24-bit colors. Note that there's only an approximate translation from a true 24-bit color to 8-bit color, i.e. the closest 8-bit color will be used when translating from 24-bit color to 8-bit color. More specifically, many darker 24-bit colors will convert as 8-bit dark grey.
By default, CosPlay stores all colors in 24-bit format internally and renders all colors as 24-bit colors in both native
terminal and the built-in terminal emulator. If, however, you want to automatically convert 24-bit color to the nearest
8-bit color during rendering you need to set system property COSPLAY_FORCE_8BIT_COLOR=true
. Note that this will force
both native terminal and built-in terminal emulator to use 8-bit color conversion even though technically the
built-in terminal emulator can always display true 24-bit color. This is only necessary if running the game in the
native terminal that does not support 24-bit colors.
Note also that since 8-bit color space is much smaller many color effects like fade in and fade out, color gradients, etc. will look less smooth when using 8-bit colors.
XTerm vs X11 Color Names
Companion object provides constants for pre-built colors:
- Names starting with
C_
represent colors in xterm naming convention. - Names starting with
C_X11_
represent colors in X11 color naming convention. - Names starting with
CS_X11_
represent colors grouped by the primary color in X11 color naming convention.
You are free to use any constants with any naming convention, as well as mix and match - they are all just colors. Note that although there are many similar and identical colors across two naming groups, they do differ in some as well as offer some unique colors. CosPlay provides these two sets of constants for convenience. Please, refer to the following links for specific color references:
Attributes
- blue
Blue RGB component.
- green
Green RGB component.
- name
Optional color name. Can be
null
or empty string. For built-in color this is color's constant name in this class.- red
Red RGB component.
- Companion:
- object
- Source:
- CPColor.scala
- Graph
- Supertypes