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:
Value parameters
- 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.
Attributes
- Companion
- object
- Source
- CPColor.scala
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
Creates a new black-and-white version of this color. It is using basic averaging method.
Creates a new black-and-white version of this color. It is using basic averaging method.
Attributes
- Source
- CPColor.scala
Creates a new black-and-white version of this color. It is method that is weighted for lighter greens and darker blues.
Creates a new black-and-white version of this color. It is method that is weighted for lighter greens and darker blues.
Attributes
- Source
- CPColor.scala
Attributes
- Definition Classes
-
Ordered
- Source
- CPColor.scala
Creates a new darker color.
Creates a new darker color.
Value parameters
- factor
-
Mixing factor in
[0,1]
range.0.9
means 90% darker,0.1
means 10% darker.
Attributes
- Source
- CPColor.scala
Gets the degree of difference in [0,1] range between this color and the given one. This color is considered as 100%.
Gets the degree of difference in [0,1] range between this color and the given one. This color is considered as 100%.
Value parameters
- c
-
Color to get a delta for.
Attributes
- Source
- CPColor.scala
Gets optional color name. Can be null
or empty string. For built-in color this is color's constant name in this class.
Gets optional color name. Can be null
or empty string. For built-in color this is color's constant name in this class.
Attributes
- Source
- CPColor.scala
Creates a new lighter color.
Creates a new lighter color.
Value parameters
- factor
-
Mixing factor in
[0.1]
range.1.0
means pure white,0.9
means 90% lighter,0.1
means 10% lighter.
Attributes
- Source
- CPColor.scala
Creates new color by multiplying this color by given delta.
Creates new color by multiplying this color by given delta.
Value parameters
- delta
-
3-element array by which each of the RGB channels will be multiplied.
Attributes
- See also
- Source
- CPColor.scala
Creates new color with given blue channel value.
Creates new color with given blue channel value.
Value parameters
- newBlue
-
Value for blue channel.
Attributes
- Source
- CPColor.scala
Creates new color with given green channel value.
Creates new color with given green channel value.
Value parameters
- newGreen
-
Value for green channel.
Attributes
- Source
- CPColor.scala
Creates new color with given red channel value.
Creates new color with given red channel value.
Value parameters
- newRed
-
Value for red channel.
Attributes
- Source
- CPColor.scala
Returns a string representation of the object.
Returns a string representation of the object.
The default representation is platform dependent.
Attributes
- Returns
-
a string representation of the object.
- Definition Classes
-
CPIntTuple -> Any
- Source
- CPColor.scala
Creates a new color by multiplying HSB values by given channel-specific factor
s. Note that result value must be valid HSB value.
Creates a new color by multiplying HSB values by given channel-specific factor
s. Note that result value must be valid HSB value.
Value parameters
- factorB
-
Factor to multiply each brightness value by.
- factorH
-
Factor to multiply each hue value by.
- factorS
-
Factor to multiply each saturation value by.
Attributes
- Source
- CPColor.scala
Creates a new color by multiplying RGB values by given factor
. Note that result value must be valid RGB value.
Creates a new color by multiplying RGB values by given factor
. Note that result value must be valid RGB value.
Value parameters
- factor
-
Factor to multiply each RGB value by.
Attributes
- Source
- CPColor.scala
Creates a new color by multiplying RGB values by given channel-specific factor
s. Note that result value must be valid RGB value.
Creates a new color by multiplying RGB values by given channel-specific factor
s. Note that result value must be valid RGB value.
Value parameters
- factorB
-
Factor to multiply each blue-channel value by.
- factorG
-
Factor to multiply each green-channel value by.
- factorR
-
Factor to multiply each red-channel value by.
Attributes
- Source
- CPColor.scala
Inherited methods
Multiplies given value with each member of this tuple.
Multiplies given value with each member of this tuple.
Value parameters
- x
-
Value to multiple by.
Attributes
- Returns
-
New tuple as a result of multiplication.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Multiple two tuples by multiplying their corresponding values.
Multiple two tuples by multiplying their corresponding values.
Value parameters
- x
-
Other tuple to multiply with.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Adds given value to each member of this tuple.
Adds given value to each member of this tuple.
Value parameters
- x
-
Value to add.
Attributes
- Returns
-
New tuple as a result of addition.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Adds two tuples by adding their corresponding values.
Adds two tuples by adding their corresponding values.
Value parameters
- x
-
Tuple to add.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Subtracts given value from each member of this tuple.
Subtracts given value from each member of this tuple.
Value parameters
- x
-
Value to subtract.
Attributes
- Returns
-
New tuple as a result of subtraction.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Subtracts given tuple from this one by subtracting their corresponding values.
Subtracts given tuple from this one by subtracting their corresponding values.
Value parameters
- x
-
Tuple to subtract.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Divides each member of this tuple by the given value.
Divides each member of this tuple by the given value.
Value parameters
- x
-
Value to divide by.
Attributes
- Returns
-
New tuple as a result of division.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Device this tuple by the given tuple by dividing their corresponding values.
Device this tuple by the given tuple by dividing their corresponding values.
Value parameters
- x
-
Other tuple to divide by.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Less-then '<' operator for int
.
Less-then '<' operator for int
.
Value parameters
- x
-
Other tuple to compare.
Attributes
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Less-then '<' operator for tuples.
Less-then '<' operator for tuples.
Value parameters
- x
-
Other tuple to compare.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Less-then-or-equal '<=' operator for tuples.
Less-then-or-equal '<=' operator for tuples.
Value parameters
- x
-
Other tuple to compare.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Less-then-or-equal '<=' operator for int
.
Less-then-or-equal '<=' operator for int
.
Value parameters
- x
-
Other tuple to compare.
Attributes
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Greater-then '>' operator for tuples.
Greater-then '>' operator for tuples.
Value parameters
- x
-
Other tuple to compare.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Greater-then '>' operator for int
.
Greater-then '>' operator for int
.
Value parameters
- x
-
Other tuple to compare.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Greater-then-or-equal '>=' operator for tuples.
Greater-then-or-equal '>=' operator for tuples.
Value parameters
- x
-
Other tuple to compare.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Greater-then-or-equal '>=' operator for int
.
Greater-then-or-equal '>=' operator for int
.
Value parameters
- x
-
Other tuple to compare.
Attributes
- Note
-
Tuples must have the same arity.
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Creates a copy of this tuple.
Creates a copy of this tuple.
Attributes
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Any implementation of this method should be an equivalence relation:
- It is reflexive: for any instance
x
of typeAny
,x.equals(x)
should returntrue
. - It is symmetric: for any instances
x
andy
of typeAny
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any instances
x
,y
, andz
of typeAny
ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
.
If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode
to ensure that objects which are "equal" (o1.equals(o2)
returns true
) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)
).
Value parameters
- that
-
the object to compare against this object for equality.
Attributes
- Returns
-
true
if the receiver object is equivalent to the argument;false
otherwise. - Definition Classes
-
CPIntTuple -> Any
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Tests whether all values in this tuple are one.
Tests whether all values in this tuple are one.
Attributes
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Checks if this tuple contains only positive (> 0) numbers.
Checks if this tuple contains only positive (> 0) numbers.
Attributes
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Checks if this tuple contains only whole (>= 0) numbers.
Checks if this tuple contains only whole (>= 0) numbers.
Attributes
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Tests whether all values in this tuple are zero.
Tests whether all values in this tuple are zero.
Attributes
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Maps this tuple using given function.
Maps this tuple using given function.
Value parameters
- f
-
Mapping function.
Attributes
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala
Attributes
- Inherited from:
- Product
Attributes
- Inherited from:
- Product
Concrete fields
Standard Java AWT color. It automatically accounts for 8-bit or 24-bit color rendering.
Standard Java AWT color. It automatically accounts for 8-bit or 24-bit color rendering.
Attributes
- Source
- CPColor.scala
ANSI background color sequence for this color. It automatically accounts for 8-bit or 24-bit color rendering.
ANSI background color sequence for this color. It automatically accounts for 8-bit or 24-bit color rendering.
Attributes
- Source
- CPColor.scala
Color's brightness.
If 24-bit color space is used (default behavior).
If 24-bit color space is used (default behavior).
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.
Attributes
- Source
- CPColor.scala
If 8-bit color space is used.
If 8-bit color space is used.
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.
Attributes
- Source
- CPColor.scala
Hexadecimal CSS string representation of this color's RGB value in #000000
upper case format
Hexadecimal CSS string representation of this color's RGB value in #000000
upper case format
Attributes
- Source
- CPColor.scala
ANSI foreground color sequence for this color. It automatically accounts for 8-bit or 24-bit color rendering.
ANSI foreground color sequence for this color. It automatically accounts for 8-bit or 24-bit color rendering.
Attributes
- Source
- CPColor.scala
Hexadecimal string representation of this color's RGB value in 0x000000
upper case format
Hexadecimal string representation of this color's RGB value in 0x000000
upper case format
Attributes
- Source
- CPColor.scala
HSB (Hue, Saturation, Brightness) values as 3-element array for this color.
HSB (Hue, Saturation, Brightness) values as 3-element array for this color.
Attributes
- See also
- Source
- CPColor.scala
Color's hue.
Color's luma (brightness) according per ITU-R BT.709. The smaller the number the darker the color. The result value is in [0,255] range with 128 considered to be a "dark" color.
Color's luma (brightness) according per ITU-R BT.709. The smaller the number the darker the color. The result value is in [0,255] range with 128 considered to be a "dark" color.
Attributes
- Source
- CPColor.scala
RGB value of this color.
Color's saturation.
8-bit xterm lookup number for this color.
8-bit xterm lookup number for this color.
Note that if converted from 24-bit color this is only an approximation unless there's a direct match between 24-bit color space and 8-bit color space.
Attributes
- Source
- CPColor.scala
Inherited fields
Arity of this tuple.
Attributes
- Inherited from:
- CPIntTuple (hidden)
- Source
- CPIntTuple.scala