|
1
|
|
|
<?php |
|
2
|
|
|
namespace rtens\domin\parameters; |
|
3
|
|
|
|
|
4
|
|
|
class Color { |
|
5
|
|
|
|
|
6
|
|
|
/** @var int */ |
|
7
|
|
|
private $red; |
|
8
|
|
|
|
|
9
|
|
|
/** @var int */ |
|
10
|
|
|
private $green; |
|
11
|
|
|
|
|
12
|
|
|
/** @var int */ |
|
13
|
|
|
private $blue; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param int $red |
|
17
|
|
|
* @param int $green |
|
18
|
|
|
* @param int $blue |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct($red, $green, $blue) { |
|
21
|
|
|
$this->red = $red; |
|
22
|
|
|
$this->green = $green; |
|
23
|
|
|
$this->blue = $blue; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public static function fromHex($hexString) { |
|
27
|
|
|
list($r, $g, $b) = str_split(trim($hexString, '#'), 2); |
|
28
|
|
|
return new Color(hexdec($r), hexdec($g), hexdec($b)); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function asHex() { |
|
32
|
|
|
return '#' |
|
33
|
|
|
. str_pad(dechex($this->red), 2, '0', STR_PAD_LEFT) |
|
34
|
|
|
. str_pad(dechex($this->green), 2, '0', STR_PAD_LEFT) |
|
35
|
|
|
. str_pad(dechex($this->blue), 2, '0', STR_PAD_LEFT); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return int |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getRed() { |
|
42
|
|
|
return $this->red; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return int |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getGreen() { |
|
49
|
|
|
return $this->green; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return int |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getBlue() { |
|
56
|
|
|
return $this->blue; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return array |
|
61
|
|
|
*/ |
|
62
|
|
|
public function asArray() { |
|
63
|
|
|
return [$this->red, $this->green, $this->blue]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
public static function RANDOM() { |
|
68
|
|
|
return new Color(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public static function BLUE() { |
|
72
|
|
|
return new Color(93, 165, 218); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public static function GREEN() { |
|
76
|
|
|
return new Color(96, 189, 104); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public static function RED() { |
|
80
|
|
|
return new Color(241, 88, 84); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public static function PURPLE() { |
|
84
|
|
|
return new Color(178, 118, 178); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public static function ORANGE() { |
|
88
|
|
|
return new Color(250, 164, 58); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public static function BROWN() { |
|
92
|
|
|
return new Color(178, 145, 47); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public static function PINK() { |
|
96
|
|
|
return new Color(241, 124, 176); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public static function YELLOW() { |
|
100
|
|
|
return new Color(222, 207, 63); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public static function GRAY() { |
|
104
|
|
|
return new Color(77, 77, 77); |
|
105
|
|
|
} |
|
106
|
|
|
} |