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