CPPixel

org.cosplay.CPPixel
See theCPPixel companion object
final case class CPPixel(char: Char, fg: CPColor, bg: Option[CPColor], tag: Int) extends Serializable

Single immutable character pixel.

Character-pixel is a fundamental graphics unit in ASCII-based games. Just like the raster pixel on a graphics screen it represents the smallest area that can be rendered on the screen.

CosPlay pixel is immutable and consists of a character from the ASCII character set, a foreground color, an optional background color and an optional tag. Note that pixel itself does not have a Z-index as it can be rendered at any Z-index.

Pixel creation and manipulation is used extensively throughout a CosPlay game. There are several ways you can create a pixel:

   import org.cosplay.*
   import org.cosplay.CPColor.*
   import org.cosplay.CPPixel.*

   // Canonical black 'x' on white background.
   new CPPixel('x', C_BLACK, Some(C_WHITE), 0)

   // Few companion object shortcuts for often used cases...
   CPPixel('x', C_BLACK, C_WHITE) // Avoiding 'Some'.
   CPPixel('x', C_BLACK) // Skipping background all together.
   CPPixel('x', C_BLACK, 2) // Skipping background & setting a '2' ag.
   CPPixel('x', C_BLACK, C_WHITE, 2) // Setting up a '2' tag.

You can also use a convenient syntactic sugar '&' and '&&'based on given conversion and extension of Char type. The following unit test demonstrates that usage. Note that usage of '&' extension operators is the recommended way and that is what is used internally by CosPlay:

   import org.cosplay.*
   import org.cosplay.CPColor.*
   import org.cosplay.CPPixel.*

   val p1 = 'x'&C_BLACK // Recommended way.
   val p4 = CPPixel('x', C_BLACK)
   val p5 = new CPPixel('x', C_BLACK, None, 0)

   assertTrue(p1 == p4)
   assertTrue(p4 == p5)

   val p6 = 'x'&&(C_BLACK, C_WHITE) // Recommended way.
   val p7 = new CPPixel('x', C_BLACK, C_WHITE.?, 0)

   assertTrue(p6 == p7)

Value parameters

bg

Background color. If not provided, the background color of this pixel will not be set when rendering on the screen.

char

Pixel character.

fg

Pixel foreground color.

tag

Pixel tag. Tag can be used to tag a pixel, for example, during a fill in algorithm to mark the pixel as touched.

Attributes

See also
Companion
object
Source
CPPixel.scala
Graph
Supertypes
trait Product
trait Equals
trait Serializable
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

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
Any
Source
CPPixel.scala
inline def withBg(x: Option[CPColor]): CPPixel

Gets a copy of this pixel with a new background color.

Gets a copy of this pixel with a new background color.

Value parameters

x

New background color.

Attributes

Source
CPPixel.scala
inline def withChar(x: Char): CPPixel

Gets a copy of this pixel with a new character.

Gets a copy of this pixel with a new character.

Value parameters

x

New character.

Attributes

Source
CPPixel.scala
inline def withDarkerBg(factor: Float): CPPixel

Gets a copy of this pixel with darker background.

Gets a copy of this pixel with darker background.

Value parameters

factor

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

Attributes

See also
Source
CPPixel.scala
inline def withDarkerFg(factor: Float): CPPixel

Gets a copy of this pixel with darker foreground.

Gets a copy of this pixel with darker foreground.

Value parameters

factor

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

Attributes

See also
Source
CPPixel.scala
inline def withFg(x: CPColor): CPPixel

Gets a copy of this pixel with a new foreground color.

Gets a copy of this pixel with a new foreground color.

Value parameters

x

New foreground color.

Attributes

Source
CPPixel.scala
inline def withFgBg(a: CPColor, b: Option[CPColor]): CPPixel

Gets a copy of this pixel with a new foreground and background color.

Gets a copy of this pixel with a new foreground and background color.

Value parameters

a

New foreground color.

b

New background color.

Attributes

Source
CPPixel.scala
inline def withLighterBg(factor: Float): CPPixel

Gets a copy of this pixel with lighter background.

Gets a copy of this pixel with lighter background.

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

See also
Source
CPPixel.scala
inline def withLighterFg(factor: Float): CPPixel

Gets a copy of this pixel with lighter foreground.

Gets a copy of this pixel with lighter foreground.

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

See also
Source
CPPixel.scala
inline def withTag(t: Int): CPPixel

Gets a copy of this pixel with a new tag.

Gets a copy of this pixel with a new tag.

Value parameters

t

New tag.

Attributes

Source
CPPixel.scala

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product

Concrete fields

val ansi: String

ANSI sequence to render this pixel on ANSI terminal.

ANSI sequence to render this pixel on ANSI terminal.

Attributes

Source
CPPixel.scala
lazy val inverse: CPPixel

Gets a new pixel with inverse foreground and background color. If background color is not set, returns this instance.

Gets a new pixel with inverse foreground and background color. If background color is not set, returns this instance.

Attributes

Source
CPPixel.scala
lazy val isXray: Boolean

Tests whether this pixel is CPPixel.XRAY.

Tests whether this pixel is CPPixel.XRAY.

Attributes

Source
CPPixel.scala
lazy val toLower: CPPixel

Gets a new pixel with the lower case character.

Gets a new pixel with the lower case character.

Attributes

Source
CPPixel.scala
lazy val toUpper: CPPixel

Gets a new pixel with the upper case character.

Gets a new pixel with the upper case character.

Attributes

Source
CPPixel.scala