A representation of a RGB, fully opaque color

Static factories

Methods

Properties

Static factories

Methods

  • Returns an array containing red, green, and blue components of this color.

    Returns [r: number, g: number, b: number]

Properties

b: number

A blue component, an integer between 0 and 255.

cssHex: string

A hex representation of this color. Can be used e.g. for CSS. Or just for simple way to store a color as a single value.

g: number

A green component, an integer between 0 and 255.

r: number

A red component, an integer between 0 and 255.

type: "rgb" = "rgb"

A property helpful for TypeScript type inference, when distinguishing from other types of colors.

const c:
| null
| BpxRgbColor
| BpxPatternColors
| BpxSpriteColorMapping
| BpxCanvasSnapshotColorMapping
= getColor();
if (c == null) {
// c is transparent here
} else if (c.type === "rgb") {
// c is BpxRgbColor here
} else if (c.type === "pattern") {
// c is BpxPatternColors here
} else if (c.type === "sprite_mapping") {
// c is BpxSpriteColorMapping here
} else if (c.type === "canvas_snapshot_mapping") {
// c is BpxCanvasSnapshotColorMapping here
} else {
$u.assertUnreachable(c);
}