Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
AbstractEffect | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
getBlend | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
4 | |||
calculateSteps | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Image\Effect; |
15 | |
16 | use Pop\Image\AbstractEditObject; |
17 | use Pop\Color\Color; |
18 | |
19 | /** |
20 | * Abstract effect class |
21 | * |
22 | * @category Pop |
23 | * @package Pop\Image |
24 | * @author Nick Sagona, III <dev@nolainteractive.com> |
25 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
26 | * @license http://www.popphp.org/license New BSD License |
27 | * @version 4.0.0 |
28 | */ |
29 | abstract class AbstractEffect extends AbstractEditObject implements EffectInterface |
30 | { |
31 | |
32 | /** |
33 | * Get the blend between 2 colors |
34 | * |
35 | * @param Color\ColorInterface $color1 |
36 | * @param Color\ColorInterface $color2 |
37 | * @param int $tween |
38 | * @return array |
39 | */ |
40 | public function getBlend(Color\ColorInterface $color1, Color\ColorInterface $color2, int $tween): array |
41 | { |
42 | if (!($color1 instanceof Color\Rgb)) { |
43 | $color1 = $color1->toRgb(); |
44 | } |
45 | if (!($color2 instanceof Color\Rgb)) { |
46 | $color2 = $color2->toRgb(); |
47 | } |
48 | |
49 | $blend = ['r' => [], 'g' => [], 'b' => []]; |
50 | |
51 | $r1 = $color1->getR(); |
52 | $g1 = $color1->getG(); |
53 | $b1 = $color1->getB(); |
54 | |
55 | $r2 = $color2->getR(); |
56 | $g2 = $color2->getG(); |
57 | $b2 = $color2->getB(); |
58 | |
59 | $rTotal = $r2 - $r1; |
60 | $gTotal = $g2 - $g1; |
61 | $bTotal = $b2 - $b1; |
62 | |
63 | for ($i = 0; $i <= $tween; $i++) { |
64 | $blend['r'][] = round($this->calculateSteps($i, $r1, $rTotal, $tween)); |
65 | $blend['g'][] = round($this->calculateSteps($i, $g1, $gTotal, $tween)); |
66 | $blend['b'][] = round($this->calculateSteps($i, $b1, $bTotal, $tween)); |
67 | } |
68 | |
69 | return $blend; |
70 | } |
71 | |
72 | /** |
73 | * Calculate the steps between two points |
74 | * |
75 | * @param int $curStep |
76 | * @param int $start |
77 | * @param int $end |
78 | * @param int $totalSteps |
79 | * @return int|float |
80 | */ |
81 | public function calculateSteps(int $curStep, int $start, int $end, int $totalSteps): int|float |
82 | { |
83 | return ($end * ($curStep / $totalSteps)) + $start; |
84 | } |
85 | |
86 | } |