Darkens color by a percentage a given Color object

@param object $color Color object
@param integer
@return object Color
512251
public function darken(Color $color, $amount = null)
    {
        $current = $color->lightness;

        $amount = ($amount === null) ? self::DEFAULT_ADJUST : $amount ;

        $amount = intval($amount) / 100;

        $new = $current - $amount;

        $new = ($new < 0) ? 0 : $new;

        $new = ($new > 1) ? 1 : $new;

        $color->lightness = floatval($new);

        return $color;
    }
1074880
public function setBackgroundColor($backgroundColor)
    {
        if (null === $backgroundColor) {
            return $this;
        }

        $this->backgroundColor = $this->convertColor($backgroundColor);

        return $this;
    }
372196
public function addColor($color)
    {
        if ( ! $color instanceof Color ) {
            $color = new Color($color);
        }

        $this->colors []= $color;
    }
559726
protected function _prepColor($color) {
		if (strpos($color, '#') !== false) {
			return str_replace('#', '0x', $color);
		}
		if (is_numeric($color)) {
			return '0x' . $color;
		}
		return $color;
	}
823915
public function setColor($color)
    {
        if (null === $color) {
            return $this;
        }

        $this->color = $this->convertColor($color);

        return $this;
    }
1053933
static public function color($color) {
		if (!is_array($color)) {
			$color = compact('color');
		}

		$color += array('color' => null, 'style' => null, 'background' => null);

		if ($color['color'] == 'reset') {
			return "\033[0m";
		}

		$colors = array();
		foreach (array('color', 'style', 'background') as $type) {
			$code = $color[$type];
			if (isset(self::$_colors[$type][$code])) {
				$colors[] = self::$_colors[$type][$code];
			}
		}

		if (empty($colors)) {
			$colors[] = 0;
		}

		return "\033[" . join(';', $colors) . "m";
	}
678258
public function blend(RGBColor $color, $amount)
    {
        return $this->setFromArray(array(
                    min(255, min($this->getRed(), $color->getRed()) + round(abs($color->getRed() - $this->getRed()) * $amount))
                    , min(255, min($this->getGreen(), $color->getGreen()) + round(abs($color->getGreen() - $this->getGreen()) * $amount))
                    , min(255, min($this->getBlue(), $color->getBlue()) + round(abs($color->getBlue() - $this->getBlue()) * $amount))
                    , min(100, min($this->getAlpha(), $color->getAlpha()) + round(abs($color->getAlpha() - $this->getAlpha()) * $amount))
        ));
    }
1148731
public function bg($color)
    {
        Assert::nullOrOneOf($color, self::$colors, 'The color must be null or one of the Style::* color constants. Got: "%s"');

        $this->bgColor = $color;

        return $this;
    }
232570
public function color($color){
        $style = array(
            'font' => array(
                'color' => array('rgb'=>$color)
            )
        );
        $this->engine->getActiveSheet()->getStyle("$this->x$this->y")->applyFromArray($style);
        return $this;
    }
678600
public function spin($percent)
    {
        $color = $this->toHsl();
        $hue = ($color->hue() + $percent) % 360;
        return $color->hue($hue < 0 ? 360 + $hue : $hue)->back($this);
    }
207970
public function lighten($percent)
    {
        $color = $this->toHsl();
        $lightness = $this->clamp(($color->lightness() + $percent) / 100);
        return $color->lightness($lightness * 100)->back($this);
    }
66999
public function mix(BaseColor $color, $percent = 50)
    {
        $first = $this->toRgb();
        $second = $color->toRgb();
        $weight = $percent / 100;
        $red = $first->red() * (1 - $weight) + $second->red() * $weight;
        $green = $first->green() * (1 - $weight) + $second->green() * $weight;
        $blue = $first->blue() * (1 - $weight) + $second->blue() * $weight;
        return $first->red($red)->green($green)->blue($blue)->back($this);
    }
1350941
private function convertColor($color)
    {
        if (is_array($color)) {
            return $color;
        }

        if (preg_match('/^#?([a-z\d])([a-z\d])([a-z\d])$/i', $color, $matches)) {
            $color = $matches[1].$matches[1];
            $color .= $matches[2].$matches[2];
            $color .= $matches[3].$matches[3];
        }

        preg_match('/#?([a-z\d]{2})([a-z\d]{2})([a-z\d]{2})$/i', $color, $matches);

        return array_map(function ($value) {
            return hexdec($value);
        }, array_slice($matches, 1, 3));
    }
712048
public function setColor($color)
	{
		if (is_array($color))
		{
			$this->color[0] = $color[0];
			$this->color[1] = $color[1];
			$this->color[2] = $color[2];
		}
		else
		{
			$color = ltrim($color, '#');

			$this->color[0] = hexdec(substr($color, 0, 2));
			$this->color[1] = hexdec(substr($color, 2, 2));
			$this->color[2] = hexdec(substr($color, 4, 2));
		}

		return $this;
	}
1291136
public function merge(Color $color1, Color $color2, $percentage = 50)
    {
        return new Color(array(
            'red' => $this->getMergedColorPart('red', $color1, $color2, $percentage),
            'green' => $this->getMergedColorPart('green', $color1, $color2, $percentage),
            'blue' => $this->getMergedColorPart('blue', $color1, $color2, $percentage)
        ));
    }
831387
public function setColor($color)
	{
		if ( ! $this->isValidColor($color))
		{
			throw new \InvalidArgumentException('Invalid color format.');
		}
		
		$this->color = (string) $color;
		
		return $this;
	}
567904
public function colorDifference(Color $color): int
    {
        $color2 = $color->getRgb();

        return (int)abs($this->colors['r'] - $color2['r'])
            + (int)abs($this->colors['g'] - $color2['g'])
            + (int)abs($this->colors['b'] - $color2['b']);
    }