From c9624a84ba6e2025a6aa7bc647797d5fb9890df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Thu, 4 Mar 2021 13:55:16 +0100 Subject: [PATCH] =?UTF-8?q?Die=20Werte=20werden=20ann=C3=A4hernd=20ermitte?= =?UTF-8?q?lt.=20Es=20gibt=20noch=20Rundungsfehler.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HueSaturationValueToRedGreenBlue.php | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) 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