Darken the current color by a fraction

@param float $fraction (default=0.1) a number between 0 and 1

@returns Color The darker color object
189118
public function darken($fraction=0.1)
    {
        $hsl = $this->toHSL();
        $l = $hsl[2];
        // so that 100% darker = black
        $dl = -$l * $fraction;

        return $this->changeHSL(0, 0, $dl);
    }
577843
public function lightness($lightness = null)
    {
        if (is_numeric($lightness)) {
            $this->lightness = $lightness >= 0 && $lightness <= 100 ? $lightness : $this->lightness;
            return $this;
        }
        return (int) $this->lightness;
    }
1001408
private int lighten(int color){
        float[] hsv = new float[3];
        Color.colorToHSV(color, hsv);
        hsv[2] = 1.0f - 0.8f * (1.0f - hsv[2]);
        color = Color.HSVToColor(hsv);
        return color;
    }
27782
function getDisplayHexColor() {
        $colorRole = $this->getColorRole();
        if($colorRole !== null && $colorRole->color > 0) {
            return $colorRole->hexColor;
        }
        
        return null;
    }
153088
protected function shortenColors($content)
    {
        $content = preg_replace('/(?<=[: ])#([0-9a-z])\\1([0-9a-z])\\2([0-9a-z])\\3(?:([0-9a-z])\\4)?(?=[; }])/i', '#$1$2$3$4', $content);

        // remove alpha channel if it's pointless...
        $content = preg_replace('/(?<=[: ])#([0-9a-z]{6})ff?(?=[; }])/i', '#$1', $content);
        $content = preg_replace('/(?<=[: ])#([0-9a-z]{3})f?(?=[; }])/i', '#$1', $content);

        $colors = array(
            // we can shorten some even more by replacing them with their color name
            '#F0FFFF' => 'azure',
            '#F5F5DC' => 'beige',
            '#A52A2A' => 'brown',
            '#FF7F50' => 'coral',
            '#FFD700' => 'gold',
            '#808080' => 'gray',
            '#008000' => 'green',
            '#4B0082' => 'indigo',
            '#FFFFF0' => 'ivory',
            '#F0E68C' => 'khaki',
            '#FAF0E6' => 'linen',
            '#800000' => 'maroon',
            '#000080' => 'navy',
            '#808000' => 'olive',
            '#CD853F' => 'peru',
            '#FFC0CB' => 'pink',
            '#DDA0DD' => 'plum',
            '#800080' => 'purple',
            '#F00' => 'red',
            '#FA8072' => 'salmon',
            '#A0522D' => 'sienna',
            '#C0C0C0' => 'silver',
            '#FFFAFA' => 'snow',
            '#D2B48C' => 'tan',
            '#FF6347' => 'tomato',
            '#EE82EE' => 'violet',
            '#F5DEB3' => 'wheat',
            // or the other way around
            'WHITE' => '#fff',
            'BLACK' => '#000',
        );

        return preg_replace_callback(
            '/(?<=[: ])('.implode(array_keys($colors), '|').')(?=[; }])/i',
            function ($match) use ($colors) {
                return $colors[strtoupper($match[0])];
            },
            $content
        );
    }
834608
@ScalarFunction
    @SqlType(ColorType.NAME)
    public static long color(@SqlType(StandardTypes.DOUBLE) double fraction, @SqlType(ColorType.NAME) long lowColor, @SqlType(ColorType.NAME) long highColor)
    {
        checkCondition(lowColor >= 0, INVALID_FUNCTION_ARGUMENT, "lowColor not a valid RGB color");
        checkCondition(highColor >= 0, INVALID_FUNCTION_ARGUMENT, "highColor not a valid RGB color");

        fraction = Math.min(1, fraction);
        fraction = Math.max(0, fraction);

        return interpolate((float) fraction, lowColor, highColor);
    }
1100535
protected function _convertSubColor($c)
    {
        if (substr($c, -1)=='%') {
            $c = floatVal(substr($c, 0, -1))/100.;
        } else {
            $c = floatVal($c);
            if ($c>1) $c = $c/255.;
        }

        return $c;
    }
950808
public function getBrightnessDifference($color1, $color2): float
    {
        return Plugin::$plugin->color->getBrightnessDifference($color1, $color2);
    }
739314
public function getColorFromRatio( $ratio ){
		if( $this->getOption( 'invertColor' ) )
			$ratio	= 1 - $ratio;
		$colorR	= ( 1 - $ratio ) > 0.5 ? 255 : round( ( 1 - $ratio ) * 2 * 255 );
		$colorG	= $ratio > 0.5 ? 255 : round( $ratio * 2 * 255 );
		$colorB	= "0";
		return array( $colorR, $colorG, $colorB );
	}
1038406
public function getBrightnessDifference($color1, $color2): float
    {
        $c1 = color($color1);
        $c2 = color($color2);
        return brightness_difference($c1, $c2);
    }
1352466
public static function colorize($text, $fgcolor = null, $bgcolor = null)
    {
        $colors = '';
        if ($bgcolor) {
            $colors .= self::getBgColorString(self::getColorCode($bgcolor));
        }
        if ($fgcolor) {
            $colors .= self::getFgColorString(self::getColorCode($fgcolor));
        }
        if ($colors) {
            $text = $colors . $text . self::RESET;
        }
        return $text;
    }
766366
public function darken($amount)
    {
        if ($amount < 0 || $amount > 100) {
            throw new InvalidArgumentException('The given amount must be between 0 and 100');
        }
        $amount /= 100;
        $this->lightness -= $this->lightness * $amount;

        return $this;
    }
437246
public function brightnessDifference(Color $color): float
    {
        $difference = $this->getBrightness() - $color->getBrightness();

        if ($difference < 0) {
            $difference *= -1.0;
        }

        return $difference;
    }
659555
public function darken($percent)
    {
        $color = $this->toHsl();
        $lightness = $this->clamp(($color->lightness() - $percent) / 100);
        return $color->lightness($lightness * 100)->back($this);
    }
1095656
protected function convertSubColor($c)
    {
        if (substr($c, -1) === '%') {
            $c = floatVal(substr($c, 0, -1)) / 100.;
        } else {
            $c = floatVal($c);
            if ($c > 1) {
                $c = $c / 255.;
            }
        }

        return $c;
    }
1168315
public function colorize($r, $g, $b, $alpha) {
		
		$this -> add(__FUNCTION__, func_get_args());
		return $this;
	}
658628
public static Color rotateHue (Color color, float fraction) {

		float[] af = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);

		float hue = af[0];
		float saturation = af[1];
		float brightness = af[2];

		float hueNew = hue  + fraction;

		Color hsb = Color.getHSBColor(hueNew, saturation, brightness);
		return new Color(hsb.getRed(), hsb.getGreen(), hsb.getBlue(), color.getAlpha());
	}