CPColor

org.cosplay.CPColor
See theCPColor companion object
final case class CPColor(red: Int, green: Int, blue: Int, name: String) extends Ordered[CPColor], 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.

Attributes

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
Show all

Members list

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.

Value parameters

factor

Mixing factor in [0,1] range. 0.9 means 90% darker, 0.1 means 10% darker.

Attributes

Source
CPColor.scala
def delta(c: CPColor): Array[Float]

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

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
def mult(delta: Array[Float]): CPColor

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

Attributes

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.

Attributes

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.

Attributes

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.

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

Attributes

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.

Attributes

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.

Value parameters

x

Value to multiple by.

Attributes

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.

Value parameters

x

Other tuple to multiply with.

Attributes

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.

Value parameters

x

Value to add.

Attributes

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.

Value parameters

x

Tuple to add.

Attributes

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.

Value parameters

x

Value to subtract.

Attributes

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.

Value parameters

x

Tuple to subtract.

Attributes

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.

Value parameters

x

Value to divide by.

Attributes

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.

Value parameters

x

Other tuple to divide by.

Attributes

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.

Value parameters

x

Other tuple to compare.

Attributes

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

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

Value parameters

x

Other tuple to compare.

Attributes

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.

Value parameters

x

Other tuple to compare.

Attributes

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.

Value parameters

x

Other tuple to compare.

Attributes

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.

Value parameters

x

Other tuple to compare.

Attributes

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.

Value parameters

x

Other tuple to compare.

Attributes

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.

Value parameters

x

Other tuple to compare.

Attributes

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

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

Value parameters

f

Mapping function.

Attributes

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 luma: Float

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