mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +00:00
Added Color::mix()
This commit is contained in:
parent
92a1f45175
commit
d9f0546cb3
@ -101,6 +101,30 @@ class Color{
|
||||
$this->b = $b & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixes the supplied list of colours together to produce a result colour.
|
||||
*
|
||||
* @param Color[] ...$colors
|
||||
* @return Color
|
||||
*/
|
||||
public static function mix(Color ...$colors) : Color{
|
||||
$count = count($colors);
|
||||
if($count < 1){
|
||||
throw new \ArgumentCountError("No colors given");
|
||||
}
|
||||
|
||||
$a = $r = $g = $b = 0;
|
||||
|
||||
foreach($colors as $color){
|
||||
$a += $color->a;
|
||||
$r += $color->r;
|
||||
$g += $color->g;
|
||||
$b += $color->b;
|
||||
}
|
||||
|
||||
return new Color((int) ($r / $count), (int) ($g / $count), (int) ($b / $count), (int) ($a / $count));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Color from the supplied RGB colour code (24-bit)
|
||||
* @param int $code
|
||||
|
Loading…
x
Reference in New Issue
Block a user