| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
class ColorPrimitives |
|---|
| 15 |
{ |
|---|
| 16 |
|
|---|
| 17 |
* the red part of the color |
|---|
| 18 |
* |
|---|
| 19 |
* @var int |
|---|
| 20 |
*/ |
|---|
| 21 |
private $red; |
|---|
| 22 |
|
|---|
| 23 |
* the green part of the color |
|---|
| 24 |
* |
|---|
| 25 |
* @var int |
|---|
| 26 |
*/ |
|---|
| 27 |
private $green; |
|---|
| 28 |
|
|---|
| 29 |
* the blue part of the color |
|---|
| 30 |
* |
|---|
| 31 |
* @var int |
|---|
| 32 |
*/ |
|---|
| 33 |
private $blue; |
|---|
| 34 |
|
|---|
| 35 |
* the name of the color |
|---|
| 36 |
* |
|---|
| 37 |
* @var int |
|---|
| 38 |
*/ |
|---|
| 39 |
private $name = null; |
|---|
| 40 |
|
|---|
| 41 |
* the title of the color |
|---|
| 42 |
* |
|---|
| 43 |
* @var int |
|---|
| 44 |
*/ |
|---|
| 45 |
private $colorTitle = null; |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
* constructor |
|---|
| 49 |
* |
|---|
| 50 |
* @var string $name name of the color |
|---|
| 51 |
*/ |
|---|
| 52 |
public function __construct($name) |
|---|
| 53 |
{ |
|---|
| 54 |
$this->name = $name; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
* set the red part |
|---|
| 59 |
* |
|---|
| 60 |
* @param int $val |
|---|
| 61 |
*/ |
|---|
| 62 |
public function setRed($val) |
|---|
| 63 |
{ |
|---|
| 64 |
$this->red = $val; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
* set the green part |
|---|
| 69 |
* |
|---|
| 70 |
* @param int $val |
|---|
| 71 |
*/ |
|---|
| 72 |
public function setGreen($val) { |
|---|
| 73 |
$this->green = $val; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
* set the blue part |
|---|
| 78 |
* |
|---|
| 79 |
* @param int $val |
|---|
| 80 |
*/ |
|---|
| 81 |
public function setBlue($val) { |
|---|
| 82 |
$this->blue = $val; |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
* set the title of the color |
|---|
| 87 |
* |
|---|
| 88 |
* @param string $title |
|---|
| 89 |
*/ |
|---|
| 90 |
public function setColorTitle($title) |
|---|
| 91 |
{ |
|---|
| 92 |
$this->colorTitle = $title; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
* get the rgb value as hex |
|---|
| 97 |
* |
|---|
| 98 |
* @return string |
|---|
| 99 |
*/ |
|---|
| 100 |
public function getRGB() |
|---|
| 101 |
{ |
|---|
| 102 |
return "#" . dechex($this->red) . dechex($this->green) . dechex($this->blue); |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
* return the name of the color |
|---|
| 107 |
* |
|---|
| 108 |
* @return string |
|---|
| 109 |
*/ |
|---|
| 110 |
public function getName() |
|---|
| 111 |
{ |
|---|
| 112 |
return $this->name; |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
* return the title of the color |
|---|
| 117 |
* |
|---|
| 118 |
* @return string |
|---|
| 119 |
*/ |
|---|
| 120 |
public function getColorTitle() |
|---|
| 121 |
{ |
|---|
| 122 |
return $this->colorTitle; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
* returns string representation |
|---|
| 127 |
* |
|---|
| 128 |
* @return string |
|---|
| 129 |
*/ |
|---|
| 130 |
public function __toString() |
|---|
| 131 |
{ |
|---|
| 132 |
return $this->name . "(" . $this->getRGB() . ")"; |
|---|
| 133 |
} |
|---|
| 134 |
} |
|---|
| 135 |
?> |
|---|