Color
in package
Simple RGB color container
Tags
Table of Contents
Properties
Methods
- __construct() : mixed
- alphaBlending() : Color
- Blend this color over a source color.
- blue() : int
- Returns the blue color component of this color as an int from 0 to 255
- blueF() : float
- Returns the blue color component of this color as a float from 0 to 1
- green() : int
- Returns the green color component of this color as an int from 0 to 255
- greenF() : float
- Returns the green color component of this color as a float from 0 to 1
- mixPalette() : array<int, Color>
- Generate a progression of colors starting with $color1 and moving toward $color2.
- name() : string
- Returns the hex triplet color value as a string ("#RRGGBB")
- red() : int
- Returns the red color component of this color as an int from 0 to 255
- redF() : float
- Returns the red color component of this color as a float from 0 to 1
- assertChannelInRange() : void
- calculateDeltas() : array{0: float, 1: float, 2: float}
- Calculate the per-channel change (RGB deltas) required to transition between two colors.
Properties
$b
private
int
$b
$g
private
int
$g
$r
private
int
$r
Methods
__construct()
public
__construct(int $r, int $g, int $b) : mixed
Parameters
- $r : int
- $g : int
- $b : int
Tags
alphaBlending()
Blend this color over a source color.
public
alphaBlending(float $opacity, Color $source) : Color
An opacity of 0 returns $source, and 1 returns this color.
Parameters
- $opacity : float
-
Opacity of this color, expected in the range 0.0 to 1.0
- $source : Color
-
The source/background color
Tags
Return values
Color —The blended color
blue()
Returns the blue color component of this color as an int from 0 to 255
public
blue() : int
Tags
Return values
intblueF()
Returns the blue color component of this color as a float from 0 to 1
public
blueF() : float
Tags
Return values
floatgreen()
Returns the green color component of this color as an int from 0 to 255
public
green() : int
Tags
Return values
intgreenF()
Returns the green color component of this color as a float from 0 to 1
public
greenF() : float
Tags
Return values
floatmixPalette()
Generate a progression of colors starting with $color1 and moving toward $color2.
public
static mixPalette(int $steps, Color $color1, Color $color2) : array<int, Color>
Parameters
- $steps : int
-
Total number of colors to return (including $color1, but excluding $color2); should be at least 2
- $color1 : Color
-
The starting color (index 0 of the returned list)
- $color2 : Color
-
The target color used to calculate the transition
Tags
Return values
array<int, Color> —The list of colors starting with $color1 up to but not including $color2
name()
Returns the hex triplet color value as a string ("#RRGGBB")
public
name() : string
Tags
Return values
stringred()
Returns the red color component of this color as an int from 0 to 255
public
red() : int
Tags
Return values
intredF()
Returns the red color component of this color as a float from 0 to 1
public
redF() : float
Tags
Return values
floatassertChannelInRange()
private
static assertChannelInRange(int $value, string $channel) : void
Parameters
- $value : int
- $channel : string
calculateDeltas()
Calculate the per-channel change (RGB deltas) required to transition between two colors.
private
static calculateDeltas(int $count, Color $start, Color $end) : array{0: float, 1: float, 2: float}
Parameters
- $count : int
-
The number of intervals to divide the transition into >0
- $start : Color
-
The starting color
- $end : Color
-
The target color
Tags
Return values
array{0: float, 1: float, 2: float} —The per-channel [r, g, b] increment required for each interval