Total Complexity | 2 |
Total Lines | 22 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class HSVTransition implements TransitionInterface |
||
12 | { |
||
13 | 8 | public function interpolate(Color $startColor, Color $endColor, float $value, float $max): Color |
|
14 | { |
||
15 | /* @var HSV $startColor */ |
||
16 | 8 | Assert::isInstanceOf($startColor, HSV::class, sprintf('startColor needs to be an instance of [%s]', HSV::class)); |
|
17 | |||
18 | /* @var HSV $endColor */ |
||
19 | 8 | Assert::isInstanceOf($endColor, HSV::class, sprintf('endColor needs to be an instance of [%s]', HSV::class)); |
|
20 | |||
21 | 8 | $step = $value / $max; |
|
22 | |||
23 | 8 | $hue = $startColor->getHue() + ($endColor->getHue() - $startColor->getHue()) * $step; |
|
24 | 8 | $saturation = $startColor->getSaturation() + ($endColor->getSaturation() - $startColor->getSaturation()) * $step; |
|
25 | 8 | $value = $startColor->getValue() + ($endColor->getValue() - $startColor->getValue()) * $step; |
|
26 | |||
27 | 8 | return new HSV((int) round($hue), $saturation, $value); |
|
28 | } |
||
29 | |||
30 | 3 | public function supports(string $fqcn): bool |
|
33 | } |
||
34 | } |
||
35 |