SPHPlayground API
SPHPlayground
sphplayground sphplayground

Color manipulation

HTML colors are specified with predefined color names, or with RGB, HEX, HSL, RGBA, or HSLA values [1].

RGBA colors

RGB(A) Colors: An RGB color value represents a color in the sRGB color space according to its RED, GREEN, and BLUE components. An optional alpha component represents the color's transparency [2][3][4].

Hex triplet: A hex triplet is a six-digit (or eight-digit) hexadecimal number used in HTML, CSS, SVG, and other computing applications to represent colors [5]. A hexadecimal color is specified with: #RRGGBB(AA) [6].

The RGBA class implements these colors.

Synopsis
class RGBA implements Color
public readonly int $red
public readonly int $green
public readonly int $blue
public readonly float $alpha
public __construct(int $red, int $green, int $blue, float $alpha = 1.0)
Returns the value of the red channel
public getRed():int
Returns the value of the green channel
public getGreen():int
Returns the value of the blue channel
public getBlue():int
Returns the alpha channel value
public getAlpha():float
public __toString():string
Returns the HEX color value
public toHex():string
public jsonSerialize():string
Creates a color instance with altered values
public alter(?int $red = null, ?int $green = null, ?int $blue = null, ?float $alpha = null):RGBA
Returns the inverted color
public invert():RGBA
public mixWith(Color|string $color, int|float $weight = 50):Color

HSLA colors

HSLA(A) Colors: HSLA stands for Hue, Saturation, Lightness, and Alpha. This color model extends the HSL format by incorporating transparency control through the alpha channel.[7]

Synopsis
class HSLA implements Color
public readonly int $hue
public readonly int $saturation
public readonly int $lightness
public readonly float $alpha
public __construct(int $hue, int $saturation, int $lightness, float $alpha = 1.0)
Returns the value of the hue
public getHue():int
Returns the value of the saturation
public getSaturation():int
Returns the value of the lightness
public getLightness():int
Returns the value of the alpha channel (opacity)
public getAlpha():float
public __toString():string
public jsonSerialize():string
Creates a color instance with altered values
public alter(?int $hue = null, ?int $saturation = null, ?int $lightness = null, ?float $alpha = null):HSLA
Returns the inverted color
public invert():Color
public mixWith(Color|string $color, float $weight = 0.5):HSLA

rgba(255, 0, 0, 0.6)
rgba(0, 255, 255, 0.6)
rgba(140, 0, 213, 0.39)

Named colors

HTML comes with 140 named colors. These are special keyword values like black, white, and cyan.These keywords all represent plain, solid colors without transparency [8] [9]. 139 of these colors (and two aliases NamedColor::CYAN and NamedColor::MAGENTA) are implemented in NamedColor Enum.

GOLD
rgba(255, 215, 0, 0.2)

Color palette

The Palette is just an iterable container for color instances. It has an ability to create simple gradients using Palette::gradientBetween() method.

rgb(255, 0, 0)
rgba(245, 0, 21, 0.96)
rgba(236, 0, 43, 0.92)
rgba(226, 0, 64, 0.88)
rgba(217, 0, 85, 0.83)
rgba(207, 0, 106, 0.79)
rgba(198, 0, 128, 0.75)
rgba(188, 0, 149, 0.71)
rgba(178, 0, 170, 0.67)
rgba(169, 0, 191, 0.63)
rgba(159, 0, 213, 0.58)
rgba(140, 0, 255, 0.5)