Toolbox-XToolbox-X

Color Manipulation Methods

Learn how to darken, lighten, desaturate, and blend colors with the Color class.

Color Manipulation Methods

applyOpacity()

Applies the specified opacity percentage to the color, returning a new Color instance.

This is an absolute setter: passing 50 means "set opacity to exactly 50%", regardless of the current opacity.

Signature

applyOpacity(opacity: Percent): Color

Parameters

ParameterTypeDescription
opacityPercentThe opacity percentage (0–100) to apply.

Returns

  • Color: A new Color instance with the modified opacity. If the original color has no alpha channel, it is added. If it already has one, it is replaced.

Example

playground.ts

applyDarkness()

Darkens the color by subtracting the given percentage points from the current lightness in HSL space.

This is a relative adjustment: passing 20 means "reduce lightness by 20 percentage points" from its current value.

Signature

applyDarkness(percent: Percent): Color

Parameters

ParameterTypeDescription
percentPercentPercentage points to subtract from lightness (0–100).

Returns

  • Color: A new darkened Color instance. Reduces lightness in HSL space, clamping to 0% if the result would be negative. The original alpha (opacity) is preserved.

Example

playground.ts

applyBrightness()

Lightens the color by adding the given percentage points to the current lightness in HSL space.

This is a relative adjustment: passing 30 means "increase lightness by 30 percentage points" from its current value.

Signature

applyBrightness(percent: Percent): Color

Parameters

ParameterTypeDescription
percentPercentPercentage points to add to lightness (0–100).

Returns

  • Color: A new lightened Color instance. Increases lightness in HSL space, clamping to 100% if the result exceeds it. The original alpha (opacity) is preserved.

Example

playground.ts

applyDullness()

Desaturates the color by subtracting the given percentage points from the current saturation in HSL space.

This is a relative adjustment: passing 50 means "reduce saturation by 50 percentage points" from its current value.

Signature

applyDullness(percent: Percent): Color

Parameters

ParameterTypeDescription
percentPercentPercentage points to subtract from saturation (0–100).

Returns

  • Color: A new desaturated Color instance. Reduces saturation in HSL space, clamping to 0% if the result would be negative. The original alpha (opacity) is preserved.

Example

playground.ts

applyWhiteShade()

Softens the color toward white by proportionally reducing saturation and increasing lightness.

This is a proportional blend: passing 40 means "move 40% of the remaining distance toward pure white". Unlike applyBrightness or applyDullness, the effect scales relative to the current distance from white, producing a natural pastel/tint effect.

Signature

applyWhiteShade(percent: Percent): Color

Parameters

ParameterTypeDescription
percentPercentSoften percentage (0–100).

Returns

  • Color: A new softened Color instance. Internally reduces saturation and increases lightness proportionally. The original alpha (opacity) is preserved.

Example

playground.ts

blendWith()

Blends the current color with another color by a given weight.

Signature

blendWith(other: ColorType | CSSColor, weight?: number): Color

Parameters

ParameterTypeDescription
otherColorType | CSSColorThe color to blend with.
weightnumber (optional)The influence of the other color (0–1, default 0.5).

Returns

  • Color: A new blended Color instance. A weight of 0 returns the original color, 1 returns the other color, and 0.5 is an equal mix.

Example

playground.ts

Last updated: Mon, Jun 15, 2026 09:49:35PM (UTC)

On this page