Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Illusion
- {
- protected $color = [];
- protected $changedColor = [];
- protected $name;
- public function color($color)
- {
- if (strlen($color) == 6 && ctype_xdigit($color)) {
- $this->color ['red'] = substr($color, 0, 2);
- $this->color ['green'] = substr($color, 2, 2);
- $this->color ['blue'] = substr($color, 4, 2);
- return $this;
- }
- return false;
- }
- public function nahid()
- {
- $change = ['red'=>100];
- $this->name = 'Nahid';
- return $this->brainProcess($change);
- }
- public function obi()
- {
- $change = ['green'=>100];
- $this->name = 'Obi';
- return $this->brainProcess($change);
- }
- public function naim()
- {
- $change = ['blue'=>100];
- $this->name = 'Naim';
- return $this->brainProcess($change);
- }
- public function see()
- {
- $originalColor = implode('', $this->color);
- $seenColor = implode('', $this->changedColor);
- $output = '<h3>' . $this->name. '</h3>';
- $output .= '<div style="width:100px; height:100px; background-color: #'. $originalColor .'; text-shadow: 1px 2px white;">Original</div>
- <div style="width:100px; height:100px; background-color: #' .$seenColor .'; text-shadow: 1px 2px white;">Seen</div>';
- return $output;
- }
- protected function brainProcess($change)
- {
- $color = [];
- foreach($this->color as $key=>$val) {
- if (isset($change[$key])) {
- $processColor = hexdec($this->color[$key])+$change[$key];
- if ($processColor<=255) {
- $this->changedColor[$key] = dechex($processColor);
- }else {
- $this->changedColor[$key] = dechex(hexdec($this->color[$key])-$change[$key]);
- }
- }else {
- $this->changedColor[$key] = $this->color[$key];
- }
- }
- return $this;
- }
- }
- $illu = new Illusion;
- $color = $illu->color('00ffff');
- echo $color->nahid()->see();
- echo $color->obi()->see();
- echo $color->naim()->see();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement