CPColor

final case class CPColor(red: Int, green: Int, blue: Int, name: String) extends Ordered[CPColor] with Serializable

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:

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.

Companion:
object
Source:
CPColor.scala
trait Product
trait Equals
trait Ordered[CPColor]
trait Comparable[CPColor]
trait Serializable
class Object
trait Matchable
class Any

Value members

Concrete methods

inline def bw(): CPColor

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.

Source:
CPColor.scala
inline def bw2(): CPColor

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.

Source:
CPColor.scala
override def compare(that: CPColor): Int
Definition Classes
Ordered
Source:
CPColor.scala
inline def darker(factor: Float): CPColor

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.

Source:
CPColor.scala
inline def getName: String

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.

Source:
CPColor.scala
inline def lighter(factor: Float): CPColor

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.

Source:
CPColor.scala
def setBlue(newBlue: Int): CPColor

Creates new color with given blue channel value.

Creates new color with given blue channel value.

Value parameters:
newBlue

Value for blue channel.

Source:
CPColor.scala
def setGreen(newGreen: Int): CPColor

Creates new color with given green channel value.

Creates new color with given green channel value.

Value parameters:
newGreen

Value for green channel.

Source:
CPColor.scala
def setRed(newRed: Int): CPColor

Creates new color with given red channel value.

Creates new color with given red channel value.

Value parameters:
newRed

Value for red channel.

Source:
CPColor.scala
override def toString: String
Definition Classes
CPIntTuple -> Any
Source:
CPColor.scala
def transformHSB(factorH: Float, factorS: Float, factorB: Float): CPColor

Creates a new color by multiplying HSB values by given channel-specific factors. Note that result value must be valid HSB value.

Creates a new color by multiplying HSB values by given channel-specific factors. 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.

Source:
CPColor.scala
def transformRGB(factor: Float): CPColor

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.

Source:
CPColor.scala
def transformRGB(factorR: Float, factorG: Float, factorB: Float): CPColor

Creates a new color by multiplying RGB values by given channel-specific factors. Note that result value must be valid RGB value.

Creates a new color by multiplying RGB values by given channel-specific factors. 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.

Source:
CPColor.scala

Inherited methods

@targetName("multiInt")
inline def *(x: Int): CPColor

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.

Returns:

New tuple as a result of multiplication.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("multiIntTuple")
inline def *(x: CPIntTuple[CPColor]): CPColor

Multiple two tuples by multiplying their corresponding values.

Multiple two tuples by multiplying their corresponding values.

Value parameters:
x

Other tuple to multiply with.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("plusInt")
inline def +(x: Int): CPColor

Adds given value to each member of this tuple.

Adds given value to each member of this tuple.

Value parameters:
x

Value to add.

Returns:

New tuple as a result of addition.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("plusIntTuple")
inline def +(x: CPIntTuple[_]): CPColor

Adds two tuples by adding their corresponding values.

Adds two tuples by adding their corresponding values.

Value parameters:
x

Tuple to add.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("minusInt")
inline def -(x: Int): CPColor

Subtracts given value from each member of this tuple.

Subtracts given value from each member of this tuple.

Value parameters:
x

Value to subtract.

Returns:

New tuple as a result of subtraction.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("minusIntTuple")
inline def -(x: CPIntTuple[CPColor]): CPColor

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.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("divideInt")
inline def /(x: Int): CPColor

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.

Returns:

New tuple as a result of division.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("divideIntTuple")
inline def /(x: CPIntTuple[CPColor]): CPColor

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.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def <(that: CPColor): Boolean
Inherited from:
Ordered
@targetName("lessInt")
inline def <(x: Int): Boolean

Less-then '<' operator for int.

Less-then '<' operator for int.

Value parameters:
x

Other tuple to compare.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("lessTuple")
inline def <(x: CPIntTuple[_]): Boolean

Less-then '<' operator for tuples.

Less-then '<' operator for tuples.

Value parameters:
x

Other tuple to compare.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def <=(that: CPColor): Boolean
Inherited from:
Ordered
@targetName("lessThenOrEqualTuple")
inline def <=(x: CPIntTuple[_]): Boolean

Less-then-or-equal '<=' operator for tuples.

Less-then-or-equal '<=' operator for tuples.

Value parameters:
x

Other tuple to compare.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("lessThenOrEqualInt")
inline def <=(x: Int): Boolean

Less-then-or-equal '<=' operator for int.

Less-then-or-equal '<=' operator for int.

Value parameters:
x

Other tuple to compare.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def >(that: CPColor): Boolean
Inherited from:
Ordered
@targetName("greaterTuple")
inline def >(x: CPIntTuple[_]): Boolean

Greater-then '>' operator for tuples.

Greater-then '>' operator for tuples.

Value parameters:
x

Other tuple to compare.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("greaterInt")
inline def >(x: Int): Boolean

Greater-then '>' operator for int.

Greater-then '>' operator for int.

Value parameters:
x

Other tuple to compare.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def >=(that: CPColor): Boolean
Inherited from:
Ordered
@targetName("greaterThenOrEqualTuple")
inline def >=(x: CPIntTuple[_]): Boolean

Greater-then-or-equal '>=' operator for tuples.

Greater-then-or-equal '>=' operator for tuples.

Value parameters:
x

Other tuple to compare.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
@targetName("greaterThenOrEqualInt")
inline def >=(x: Int): Boolean

Greater-then-or-equal '>=' operator for int.

Greater-then-or-equal '>=' operator for int.

Value parameters:
x

Other tuple to compare.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def compareTo(that: CPColor): Int
Inherited from:
Ordered
inline def copy: CPColor

Creates a copy of this tuple.

Creates a copy of this tuple.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
override def equals(obj: Any): Boolean
Definition Classes
CPIntTuple -> Any
Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def isOne: Boolean

Tests whether all values in this tuple are one.

Tests whether all values in this tuple are one.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def isPositive: Boolean

Checks if this tuple contains only positive (> 0) numbers.

Checks if this tuple contains only positive (> 0) numbers.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def isWhole: Boolean

Checks if this tuple contains only whole (>= 0) numbers.

Checks if this tuple contains only whole (>= 0) numbers.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def isZero: Boolean

Tests whether all values in this tuple are zero.

Tests whether all values in this tuple are zero.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def mapInt(f: Int => Int): CPColor

Maps this tuple using given function.

Maps this tuple using given function.

Value parameters:
f

Mapping function.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def productElementNames: Iterator[String]
Inherited from:
Product
def productIterator: Iterator[Any]
Inherited from:
Product

Concrete fields

final val awt: Color

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.

Source:
CPColor.scala
final val bgAnsi: String

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.

Source:
CPColor.scala
final val brightness: Float

Color's brightness.

Color's brightness.

Source:
CPColor.scala
final val color24Bit: Boolean

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.

Source:
CPColor.scala
final val color8Bit: Boolean

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.

Source:
CPColor.scala
final val cssHex: String

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

Source:
CPColor.scala
final val fgAnsi: String

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.

Source:
CPColor.scala
final val hex: String

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

Source:
CPColor.scala
final val hsb: Array[Float]

HSB (Hue, Saturation, Brightness) values as 3-element array for this color.

HSB (Hue, Saturation, Brightness) values as 3-element array for this color.

See also:
Source:
CPColor.scala
final val hue: Float

Color's hue.

Color's hue.

Source:
CPColor.scala
final val rgb: Int

RGB value of this color.

RGB value of this color.

Source:
CPColor.scala
final val saturation: Float

Color's saturation.

Color's saturation.

Source:
CPColor.scala
final val xterm: Int

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.

Source:
CPColor.scala

Inherited fields

val arity: Int

Arity of this tuple.

Arity of this tuple.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
val ints: Int*
Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala