Das RGB-Farbmodell ist vorhanden.

This commit is contained in:
2021-03-01 16:20:14 +01:00
parent 78d070d754
commit d5fea09dfc
3 changed files with 216 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace TorstenHettstedt\Colors\ColorModels;
use InvalidArgumentException;
abstract class AbstractColorModel
{
protected function checkValue(float $value)
{
if ($value > 1.0) {
throw new InvalidArgumentException('Ein Wert größer als 1 ist nicht definierbar.');
}
if ($value < 0.0) {
throw new InvalidArgumentException('Ein Wert kleiner als 0 ist nicht definierbar.');
}
}
}
+75
View File
@@ -0,0 +1,75 @@
<?php
namespace TorstenHettstedt\Colors\ColorModels;
/**
* Definition des allgemeinen RGB-Farbraumes. Die Werte für die eigenschaften sind reelle Zahlen von 0 bis einschließlich 1.
* Ohne Änderung der Eigenschaften wird die Farbe *weiß* dargestellt.
*/
class RedGreenBlue extends AbstractColorModel
{
/** @var float : Definition des Rotanteil */
protected float $red = 1.0;
/** @var float : Definition des Grünanteil */
protected float $green = 1.0;
/** @var float : Definition des Grünanteil */
protected float $blue = 1.0;
/**
* @return float
*/
public function getRed(): float
{
return $this->red;
}
/**
* @param float $red
* @return RedGreenBlue
*/
public function setRed(float $red): RedGreenBlue
{
$this->checkValue($red);
$this->red = $red;
return $this;
}
/**
* @return float
*/
public function getGreen(): float
{
return $this->green;
}
/**
* @param float $green
* @return RedGreenBlue
*/
public function setGreen(float $green): RedGreenBlue
{
$this->checkValue($green);
$this->green = $green;
return $this;
}
/**
* @return float
*/
public function getBlue(): float
{
return $this->blue;
}
/**
* @param float $blue
* @return RedGreenBlue
*/
public function setBlue(float $blue): RedGreenBlue
{
$this->checkValue($blue);
$this->blue = $blue;
return $this;
}
}