Mixing

Mixing colors together is very common when producing color palettes. The most notable examples of this are creating tints (mixing with white), shades (mixing with black), and tones (mixing with gray), although any two colors can be mixed together. These functions are declared as extension methods in the static class Mixing.

Color red = Color.red;
Color yellow = Color.yellow;

Color orange = red.Mix(yellow); // 50% red, 50% yellow
Color redOrange = red.Mix(yellow, 0.25f); // 75% red, 25% yellow
Color amber = red.Mix(yellow, 0.75f); // 25% red, 75% yellow

By default, colors are mixed using RGB components, but any color model can be used to mix colors if specified. For example, the following mixes colors using the HSV color model.

Color red = Color.red;
Color yellow = Color.yellow;

Color orange = red.Mix<HSV>(yellow);
Color redOrange = red.Mix<HSV>(yellow, 0.25f);
Color amber = red.Mix<HSV>(yellow, 0.75f);

See all available color models in the Conversion manual.


⬜ Tints

Tints are produced by mixing a color with white (increases lightness).

Color tint = color.Tint(0.1f); // 10% white
Color same = color.Tint(0f); // no change
Color white = color.Tint(1f); // pure white

Color[] tints = color.Tints(10); // 10 tints
color.TintsNonAlloc(array); // prevent heap allocations

⬛ Shades

Tints are produced by mixing a color with black (decreases lightness).

Color shade = color.Shade(0.1f); // 10% black
Color same = color.Shade(0f); // no change
Color black = color.Shade(1f); // pure black

Color[] shades = color.Shades(10); // 10 shades
color.ShadesNonAlloc(array); // prevent heap allocations

🔳 Tones

Tints are produced by mixing a color with gray (decreases saturation).

Color tone = color.Tone(0.1f); // 10% gray
Color same = color.Tone(0f); // no change
Color gray = color.Tone(1f); // pure gray (50% black / 50% white)

Color[] tones = color.Tones(10); // 10 tones
color.TonesNonAlloc(array); // prevent heap allocations