Color

value class Color(val rgba: UInt)(source)

An RGBA color with 8 bits per channel, packed as 0xRRGGBBAA.

Samples

val orange = Color(red = 1f, green = 0.5f, blue = 0f)
assertPrints(orange, "Color(#ff8000ff)")
assertPrints(orange.red, "1.0")
assertPrints(orange.alpha, "1.0")
assertPrints(Color.WHITE, "Color(#ffffffff)")
assertFailsWith<IllegalArgumentException> { Color(red = 2f, green = 0f, blue = 0f) }

Constructors

Link copied to clipboard
constructor(rgba: UInt)

Types

Link copied to clipboard
object Companion

Holds shared color constants. Every one but TRANSPARENT is opaque, with each channel either full or zero, except GRAY, whose channels are all 0x80.

Properties

Link copied to clipboard

Alpha channel in 0.0..1.0, where 1.0 is opaque.

Link copied to clipboard
val blue: Float

Blue channel in 0.0..1.0.

Link copied to clipboard

Green channel in 0.0..1.0.

Link copied to clipboard
val red: Float

Red channel in 0.0..1.0.

Link copied to clipboard
val rgba: UInt

The packed value, 0xRRGGBBAA.

Functions

Link copied to clipboard
fun Color.lerp(to: Color, t: Float): Color

Returns the color t of the way from this color to to, blending each channel, alpha included, on its own: this color at 0, to at 1. t is clamped to 0.0..1.0, because a blend past either end could leave a channel's range.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun Color.withAlpha(alpha: Float): Color

Returns this color with its alpha channel replaced by alpha, in 0.0..1.0, and red, green and blue unchanged. color.withAlpha(0f) is the color fully transparent, which is what a fade out ends on.