From 43b86049eac4e8b3a60768c4164e75f95eb19875 Mon Sep 17 00:00:00 2001 From: Lee Bradley Date: Thu, 10 Aug 2017 14:36:02 +0100 Subject: [PATCH] Adds Colour class for modelling Gives ability to request Red, Green, Blue integer values --- code/models/Colour.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 code/models/Colour.php diff --git a/code/models/Colour.php b/code/models/Colour.php new file mode 100644 index 0000000..7b41127 --- /dev/null +++ b/code/models/Colour.php @@ -0,0 +1,39 @@ +value, 1); + } + + public function getRGB() + { + $hash = $this->getHash(); + return array( + 'R' => hexdec(substr($hash, 0, 2)), + 'G' => hexdec(substr($hash, 2, 2)), + 'B' => hexdec(substr($hash, 4, 2)), + ); + } + + public function getRed() + { + return $this->getRGB()['R']; + } + + public function getBlue() + { + return $this->getRGB()['B']; + } + + public function getGreen() + { + return $this->getRGB()['G']; + } +}