|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace projectcleverweb\color\convert; |
|
4
|
|
|
|
|
5
|
|
|
class hsl implements \projectcleverweb\color\interfaces\converter { |
|
6
|
|
|
use \projectcleverweb\color\traits\converter; |
|
7
|
|
|
|
|
8
|
|
|
protected static $valid_keys = array( |
|
9
|
|
|
'h', |
|
10
|
|
|
's', |
|
11
|
|
|
'l' |
|
12
|
|
|
); |
|
13
|
|
|
|
|
14
|
|
|
protected static $default_value = array( |
|
15
|
|
|
'h' => 0, |
|
16
|
|
|
's' => 0, |
|
17
|
|
|
'l' => 0 |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
public static function to_rgb($input) :array { |
|
21
|
|
|
$hsl = static::_validate_array_input($input); |
|
|
|
|
|
|
22
|
|
|
$hsl['s'] /= 100; |
|
23
|
|
|
$hsl['l'] /= 100; |
|
24
|
|
|
$c = (1 - abs((2 * $hsl['l']) - 1)) * $hsl['s']; |
|
|
|
|
|
|
25
|
|
|
$x = $c * (1 - abs(fmod(($hsl['h'] / 60), 2) - 1)); |
|
|
|
|
|
|
26
|
|
|
$m = $hsl['l'] - ($c / 2); |
|
|
|
|
|
|
27
|
|
|
$r = $c; |
|
|
|
|
|
|
28
|
|
|
$g = 0; |
|
|
|
|
|
|
29
|
|
|
$b = $x; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
if ($hsl['h'] < 180) { |
|
32
|
|
|
static::_hslrgb_low($r, $g, $b, $c, $x, $hsl['h']); |
|
33
|
|
|
} elseif ($hsl['h'] < 300) { |
|
34
|
|
|
static::_hslrgb_high($r, $g, $b, $c, $x, $hsl['h']); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return [ |
|
38
|
|
|
'r' => (int) round(($r + $m) * 255), |
|
39
|
|
|
'g' => (int) round(($g + $m) * 255), |
|
40
|
|
|
'b' => (int) round(($b + $m) * 255) |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public static function to_hex($input) :string { |
|
45
|
|
|
return rgb::to_hex(static::to_rgb($input)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public static function to_cmyk($input) :array { |
|
49
|
|
|
return rgb::to_cmyk(static::to_rgb($input)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public static function to_hsl($input) :array { |
|
53
|
|
|
return static::_validate_array_input($input); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public static function to_hsb($input) :array { |
|
57
|
|
|
return rgb::to_hsb(static::to_rgb($input)); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.