Saturate or desaturate a color by a given amount

@param {Color} color
@param {Number} amount
@returns {Color} color
425849
function(color, amount) {
    var hsl = this.toHSL(color);

    hsl.s += amount / 100;
    hsl.s = clamp(hsl.s);
    return hsla(hsl);
  }
1101539
function convertColorToString(color) {
  const {type, values} = color

  // Only convert the first 3 values to int (i.e. not alpha)
  if (type.indexOf('rgb') > -1)
    for (let i = 0; i < 3; i++) values[i] = parseInt(values[i])

  let colorString

  if (type.indexOf('hsl') > -1)
    colorString = `${color.type}(${values[0]}, ${values[1]}%, ${values[2]}%`
  else colorString = `${color.type}(${values[0]}, ${values[1]}, ${values[2]}`

  if (values.length === 4) colorString += `, ${color.values[3].toFixed(2)})`
  else colorString += ')'

  return colorString
}
758395
function(color1, color2) {
		var result = color1.slice();
		for (var i=0;i<3;i++) {
			for (var j=1;j<arguments.length;j++) {
				result[i] += arguments[j][i];
			}
		}
		return result;
	}
1183919
def saturate_color(color, amount):
    """"""
    r, g, b = hex_to_rgb(color)
    r, g, b = [x/255.0 for x in (r, g, b)]
    h, l, s = colorsys.rgb_to_hls(r, g, b)
    s = amount
    r, g, b = colorsys.hls_to_rgb(h, l, s)
    r, g, b = [x*255.0 for x in (r, g, b)]

    return rgb_to_hex((int(r), int(g), int(b)))
813171
def lighten_color(color, amount):
    """"""
    color = [int(col + (255 - col) * amount) for col in hex_to_rgb(color)]
    return rgb_to_hex(color)
309297
function hueshiftColor(col, amount) {
  let colRgba = parseColor(col);
  let colHsla = rgbaToHsla(colRgba.r, colRgba.g, colRgba.b, colRgba.a);
  colRgba = hslaToRgba((hsl[0] + amount) % 1, colHsla[1], colHsla[2],colHsla[3]);
  return RGBobj2string({
    r: colRgba[0],
    g: colRgba[1],
    b: colRgba[2],
    a: colRgba[3]
  });
}
290504
function (color) {
            this.glArray[0] = me.Math.clamp(this.glArray[0] + color.glArray[0], 0, 1);
            this.glArray[1] = me.Math.clamp(this.glArray[1] + color.glArray[1], 0, 1);
            this.glArray[2] = me.Math.clamp(this.glArray[2] + color.glArray[2], 0, 1);
            this.glArray[3] = (this.glArray[3] + color.glArray[3]) / 2;

            return this;
        }
224577
function Lighten($amount)
    {
        $floatAmount = (float)$amount;
        if ($floatAmount < 0 || $floatAmount > 1) {
            throw new \InvalidArgumentException('Colors can be only lightened with amounts between 0 and 1');
        }
        $this->r = $this->LightenColor($this->r, $floatAmount);
        $this->g = $this->LightenColor($this->g, $floatAmount);
        $this->b = $this->LightenColor($this->b, $floatAmount);
    }
1320987
function (a, bInt, c) {
            if (isFinite(a * bInt)) {
                return saturated.saturate(a * bInt + c);
            } else {
                var result = c;

                for (var i = 0; i < bInt; i++) {
                    result += a;
                }

                return saturated.saturate(result);
            }
        }
120021
def prettify(amount, separator=','):
    """"""
    orig = str(amount)
    new = re.sub("^(-?\d+)(\d{3})", "\g<1>{0}\g<2>".format(separator), str(amount))
    if orig == new:
        return new
    else:
        return prettify(new)
203573
public function desaturate($amount)
    {
        if ($amount < 0 || $amount > 100) {
            throw new InvalidArgumentException('The given amount must be between 0 and 100');
        }
        $amount /= 100;
        $this->saturation -= $this->saturation * $amount;

        return $this;
    }
1321416
function adjust(color, prop, amount){
  utils.assertColor(color, 'color');
  utils.assertString(prop, 'prop');
  utils.assertType(amount, 'unit', 'amount');
  var hsl = color.hsla.clone();
  prop = { hue: 'h', saturation: 's', lightness: 'l' }[prop.string];
  if (!prop) throw new Error('invalid adjustment property');
  var val = amount.val;
  if ('%' == amount.type){
    val = 'l' == prop && val > 0
      ? (100 - hsl[prop]) * val / 100
      : hsl[prop] * (val / 100);
  }
  hsl[prop] += val;
  return hsl.rgba;
}
152355
public function getCssGradient(Color $color, $amount = null)
    {
        // Get gradient colors
        if (self::isLight($color)) {
            $lightColor = $color->hex;
            $darkColor = self::darken($color->copy(), $amount)->hex;
        } else {
            $lightColor = self::lighten($color->copy(), $amount)->hex;
            $darkColor = $color->hex;
        }

        /* fallback/image non-cover color */
        $css = "background-color: #" . $color->hex . ";";

        /* IE Browsers */
        $css .= "filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#" . $lightColor . "', endColorstr='#" . $darkColor . "');";

        /* Safari 4+, Chrome 1-9 */
        $css .= "background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#" . $lightColor . "), to(#" . $darkColor . "));";

        /* Safari 5.1+, Mobile Safari, Chrome 10+ */
        $css .= "background-image: -webkit-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";

        /* Firefox 3.6+ */
        $css .= "background-image: -moz-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";

        /* IE 10+ */
        $css .= "background-image: -ms-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";

        /* Opera 11.10+ */
        $css .= "background-image: -o-linear-gradient(top, #" . $lightColor . ", #" . $darkColor . ");";

        // Return our CSS
        return $css;
    }
374910
function changeDecColorsToHex(color) {
  return color.replace(decimalColorRx, (colorValue, r, g, b) => {
    const hr = changeDecColorToHex(r);
    const hg = changeDecColorToHex(g);
    const hb = changeDecColorToHex(b);

    return `#${hr}${hg}${hb}`;
  });
}
810352
function Amount(value, unit) {
  if (!(this instanceof Amount))
    return new Amount(value, unit);

  this.value = 0;
  this.unit = null;

  if (value != null)
    this.fromOptions(value, unit);
}
310896
function setColor(color) {
         var alpha = this.currentColor.glArray[3];
         this.currentColor.copy(color);
         this.currentColor.glArray[3] *= alpha;
       }
1311471
function Darken($amount)
    {
        $floatAmount = (float)$amount;
        if ($floatAmount < 0 || $floatAmount > 1) {
            throw new \InvalidArgumentException('Colors can be only lightened with amounts between 0 and 1');
        }
        $this->r = $this->DarkenColor($this->r, $floatAmount);
        $this->g = $this->DarkenColor($this->g, $floatAmount);
        $this->b = $this->DarkenColor($this->b, $floatAmount);
    }