RGBA.php 910 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace fphammerle\helpers\colors;
  3. class RGBA extends RGB
  4. {
  5. private $_alpha;
  6. public function __construct($red = 0, $green = 0, $blue = 0, $alpha = 1)
  7. {
  8. $this->setRed($red);
  9. $this->setGreen($green);
  10. $this->setBlue($blue);
  11. $this->setAlpha($alpha);
  12. }
  13. public function getAlpha()
  14. {
  15. return $this->_alpha;
  16. }
  17. public function setAlpha($alpha)
  18. {
  19. $alpha = (float)$alpha;
  20. if($alpha < 0 || $alpha > 1) {
  21. throw new \UnexpectedValueException('value must be within [0, 1]');
  22. }
  23. $this->_alpha = $alpha;
  24. }
  25. public function equals(RGB $other)
  26. {
  27. return parent::equals($other)
  28. && abs($this->alpha - $other->alpha) < self::comparison_precision;
  29. }
  30. public function getTuple()
  31. {
  32. return [$this->red, $this->green, $this->blue, $this->alpha];
  33. }
  34. }