|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace projectcleverweb\color; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class main extends main_peripheral { |
|
8
|
|
|
|
|
9
|
|
|
public $color; |
|
10
|
|
|
|
|
11
|
|
|
public function __construct($color) { |
|
12
|
|
|
$this->set($color); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
protected function set($color, string $type = '') { |
|
16
|
|
|
if ($color instanceof color) { |
|
17
|
|
|
$this->color = $color; |
|
18
|
|
|
} else { |
|
19
|
|
|
$this->color = new color($color, $type); |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function rgb() :array { |
|
24
|
|
|
return (array) $this->color->rgb + ['a' => $this->color->alpha()]; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function hsl(int $accuracy = 0) :array { |
|
28
|
|
|
$color = []; |
|
29
|
|
|
foreach($this->color->hsl() as $key => $value) { |
|
30
|
|
|
$color[$key] = round($value, abs($accuracy)); |
|
31
|
|
|
} |
|
32
|
|
|
return $color + ['a' => $this->color->alpha()]; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function cmyk() :array { |
|
36
|
|
|
$rgb = $this->color->rgb; |
|
37
|
|
|
return generate::rgb_to_cmyk($rgb['r'], $rgb['g'], $rgb['b']) + ['a' => $this->color->alpha()]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function hsb(int $accuracy = 0) :array { |
|
41
|
|
|
$rgb = $this->color->rgb; |
|
42
|
|
|
return generate::rgb_to_hsb($rgb['r'], $rgb['g'], $rgb['b'], $accuracy) + ['a' => $this->color->alpha()]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function hex() :string { |
|
46
|
|
|
return $this->color->hex; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function css() :string { |
|
50
|
|
|
return css::best($this->color); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get (and set) the alpha channel |
|
55
|
|
|
* |
|
56
|
|
|
* @param mixed $new_alpha If numeric, the alpha channel is set to this value |
|
57
|
|
|
* @return float The current alpha value |
|
58
|
|
|
*/ |
|
59
|
|
|
public function alpha($new_alpha) { |
|
60
|
|
|
return $this->color->alpha($new_alpha); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function is_dark(int $check_score = 128) :bool { |
|
64
|
|
|
$rgb = $this->color->rgb; |
|
65
|
|
|
return check::is_dark($rgb['r'], $rgb['g'], $rgb['b'], $check_score); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function red(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
|
69
|
|
|
return modify::rgb($this->color, 'red', $adjustment, $as_percentage, $set_absolute); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function green(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
|
73
|
|
|
return modify::rgb($this->color, 'green', $adjustment, $as_percentage, $set_absolute); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function blue(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
|
77
|
|
|
return modify::rgb($this->color, 'blue', $adjustment, $as_percentage, $set_absolute); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function hue(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
|
81
|
|
|
return modify::hsl($this->color, 'hue', $adjustment, $as_percentage, $set_absolute); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function saturation(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
|
85
|
|
|
return modify::hsl($this->color, 'saturation', $adjustment, $as_percentage, $set_absolute); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function light(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
|
89
|
|
|
return modify::hsl($this->color, 'light', $adjustment, $as_percentage, $set_absolute); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function blend(main $color2, float $amount = 50.0) { |
|
93
|
|
|
$c1 = $this->rgb(); |
|
94
|
|
|
$c2 = $color2->rgb(); |
|
95
|
|
|
return new $this(generate::blend( |
|
96
|
|
|
$c1['r'], $c1['g'], $c1['b'], $c1['a'], |
|
97
|
|
|
$c2['r'], $c2['g'], $c2['b'], $c2['a'], |
|
98
|
|
|
$amount) |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function scheme(string $scheme_name, string $return_type = 'hex') :array { |
|
103
|
|
|
return static::_scheme($scheme_name, strtolower($return_type), $this->hsl(3)); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function rgb_rand(int $min_r = 0, int $max_r = 255, int $min_g = 0, int $max_g = 255, int $min_b = 0, int $max_b = 255) :color { |
|
107
|
|
|
return new color(generate::rgb_rand($min_r, $max_r, $min_g, $max_g, $min_b, $max_b)); |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function hsl_rand(int $min_h = 0, int $max_h = 255, int $min_s = 0, int $max_s = 255, int $min_l = 0, int $max_l = 255) :color { |
|
111
|
|
|
return new color(generate::hsl_rand($min_h, $max_h, $min_s, $max_s, $min_l, $max_l)); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.