colour-mix
Blend two colours.
amount is the fraction of colour2 (0 = pure colour1, 1 = pure colour2). Mixing happens in sRGB so colour-mix(black, white, 0.92) returns grey92.
Usage
colour-mix(
colour1,
colour2,
amount,
)Parameters
| Parameter | Default | Description |
|---|---|---|
colour1 |
Base colour. | |
colour2 |
Colour to blend in. | |
amount |
Fraction of colour2 in the result (0 to 1). |
Returns
Blended colour.
Examples
Inline blending: half-mix two brand colours.
#let purple = colour-mix(rgb("#1f77b4"), rgb("#d62728"), 0.5)Sweeping amount from 0 to 1 produces a custom two-stop ramp, rendered as a swatch via geom-rect.
#let stops = range(0, 9).map(i => colour-mix(
rgb("#1f77b4"), rgb("#d62728"), i / 8,
))
#let d = stops.enumerate().map(((i, _)) => (
xmin: i, xmax: i + 1, ymin: 0, ymax: 1, k: str(i),
))
#plot(
data: d,
mapping: aes(xmin: "xmin", xmax: "xmax", ymin: "ymin", ymax: "ymax", fill: "k"),
layers: (geom-rect(),),
scales: (scale-fill-manual(values: stops),),
guides: guides(fill: none),
theme: theme-void(),
width: 8cm,
height: 1cm,
)