diff --git a/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php b/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php index 83544cb..b68fe2d 100644 --- a/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php +++ b/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php @@ -9,6 +9,9 @@ use TorstenHettstedt\Colors\ColorModels\RedGreenBlue; class HueSaturationValueToRedGreenBlue { + /** @var int : Größe des Intervals in 1/100 Grad */ + protected const INTERVAL = 60 * 100; + // Daten für HSV /** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */ protected float $hue; @@ -59,7 +62,50 @@ class HueSaturationValueToRedGreenBlue protected function splitColor(): void { - + // Anteil am Vollkreis in 1/100 Grad + $percent_grad = intval($this->hue * 360 * 100); + // ID des zu nutzenden Interval + $interval_id = intdiv($percent_grad , self::INTERVAL); + // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' + $remainder = (($percent_grad % self::INTERVAL) / self::INTERVAL); + $help_values = [ + $this->value, + $this->value * ( 1 - $this->saturation), + $this->value * ( 1 - $this->saturation * $remainder), + $this->value * ( 1 - $this->saturation * (1 - $remainder)), + ]; + switch ($interval_id) { + case 1: + $this->red = $help_values[2]; + $this->green = $help_values[0]; + $this->blu = $help_values[1]; + break; + case 2: + $this->red = $help_values[1]; + $this->green = $help_values[0]; + $this->blu = $help_values[3]; + break; + case 3: + $this->red = $help_values[1]; + $this->green = $help_values[2]; + $this->blu = $help_values[0]; + break; + case 4: + $this->red = $help_values[3]; + $this->green = $help_values[1]; + $this->blu = $help_values[0]; + break; + case 5: + $this->red = $help_values[0]; + $this->green = $help_values[1]; + $this->blu = $help_values[2]; + break; + default: + $this->red = $help_values[0]; + $this->green = $help_values[3]; + $this->blu = $help_values[1]; + break; + } } } \ No newline at end of file