CPColor

org.cosplay.CPColor
See theCPColor companion object
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:

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
trait Product
trait Equals
trait Ordered[CPColor]
trait Comparable[CPColor]
trait Serializable
class Object
trait Matchable
class Any

Members list

Concise view

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.

Attributes

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.

Attributes

Source:
CPColor.scala
override def compare(that: CPColor): Int

Attributes

Definition Classes
Ordered
Source:
CPColor.scala
inline def darker(factor: Float): CPColor

Creates a new darker color.

Creates a new darker color.

Attributes

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.

Attributes

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

Creates a new lighter color.

Creates a new lighter color.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

newRed

Value for red channel.

Source:
CPColor.scala
override def toString: String

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
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.

Attributes

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.

Attributes

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.

Attributes

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

inline def *(x: Int): T

Multiplies given value with each member of this tuple.

Multiplies given value with each member of this tuple.

Attributes

x

Value to multiple by.

Returns:

New tuple as a result of multiplication.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def *(x: CPIntTuple[CPColor]): T

Multiple two tuples by multiplying their corresponding values.

Multiple two tuples by multiplying their corresponding values.

Attributes

x

Other tuple to multiply with.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def +(x: Int): T

Adds given value to each member of this tuple.

Adds given value to each member of this tuple.

Attributes

x

Value to add.

Returns:

New tuple as a result of addition.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def +(x: CPIntTuple[_]): T

Adds two tuples by adding their corresponding values.

Adds two tuples by adding their corresponding values.

Attributes

x

Tuple to add.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def -(x: Int): T

Subtracts given value from each member of this tuple.

Subtracts given value from each member of this tuple.

Attributes

x

Value to subtract.

Returns:

New tuple as a result of subtraction.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def -(x: CPIntTuple[CPColor]): T

Subtracts given tuple from this one by subtracting their corresponding values.

Subtracts given tuple from this one by subtracting their corresponding values.

Attributes

x

Tuple to subtract.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def /(x: Int): T

Divides each member of this tuple by the given value.

Divides each member of this tuple by the given value.

Attributes

x

Value to divide by.

Returns:

New tuple as a result of division.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
inline def /(x: CPIntTuple[CPColor]): T

Device this tuple by the given tuple by dividing their corresponding values.

Device this tuple by the given tuple by dividing their corresponding values.

Attributes

x

Other tuple to divide by.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def <(that: CPColor): Boolean

Attributes

Inherited from:
Ordered
inline def <(x: Int): Boolean

Less-then '<' operator for int.

Less-then '<' operator for int.

Attributes

x

Other tuple to compare.

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

Less-then '<' operator for tuples.

Less-then '<' operator for tuples.

Attributes

x

Other tuple to compare.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def <=(that: CPColor): Boolean

Attributes

Inherited from:
Ordered
inline def <=(x: CPIntTuple[_]): Boolean

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

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

Attributes

x

Other tuple to compare.

Note:

Tuples must have the same arity.

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

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

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

Attributes

x

Other tuple to compare.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def >(that: CPColor): Boolean

Attributes

Inherited from:
Ordered
inline def >(x: CPIntTuple[_]): Boolean

Greater-then '>' operator for tuples.

Greater-then '>' operator for tuples.

Attributes

x

Other tuple to compare.

Note:

Tuples must have the same arity.

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

Greater-then '>' operator for int.

Greater-then '>' operator for int.

Attributes

x

Other tuple to compare.

Note:

Tuples must have the same arity.

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
def >=(that: CPColor): Boolean

Attributes

Inherited from:
Ordered
inline def >=(x: CPIntTuple[_]): Boolean

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

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

Attributes

x

Other tuple to compare.

Note:

Tuples must have the same arity.

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

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

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

Attributes

x

Other tuple to compare.

Note:

Tuples must have the same arity.

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

Attributes

Inherited from:
Ordered
inline def copy: T

Creates a copy of this tuple.

Creates a copy of this tuple.

Attributes

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala
override def equals(obj: Any): Boolean

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 type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

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)).

Attributes

that

the object to compare against this object for equality.

Returns:

true if the receiver object is equivalent to the argument; false otherwise.

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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

Maps this tuple using given function.

Maps this tuple using given function.

Attributes

f

Mapping function.

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

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product

Concrete fields

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.

Attributes

Source:
CPColor.scala
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.

Attributes

Source:
CPColor.scala
val brightness: Float

Color's brightness.

Color's brightness.

Attributes

Source:
CPColor.scala
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.

Attributes

Source:
CPColor.scala
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.

Attributes

Source:
CPColor.scala
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

Attributes

Source:
CPColor.scala
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.

Attributes

Source:
CPColor.scala
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

Attributes

Source:
CPColor.scala
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.

Attributes

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

Color's hue.

Color's hue.

Attributes

Source:
CPColor.scala
val rgb: Int

RGB value of this color.

RGB value of this color.

Attributes

Source:
CPColor.scala
val saturation: Float

Color's saturation.

Color's saturation.

Attributes

Source:
CPColor.scala
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.

Attributes

Source:
CPColor.scala

Inherited fields

val arity: Int

Arity of this tuple.

Arity of this tuple.

Attributes

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

Attributes

Inherited from:
CPIntTuple (hidden)
Source:
CPIntTuple.scala