color_contrast
Contrast returns the color with the most contrast (hence either black or white)
color_contrast(
color
) -> Hex color (#000000 or #ffffff)
Contrast returns the color with the most contrast (hence either black or white)
Syntaxe
var col = color_contrast(color="#FFC107")
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
color | string | yes | - | Color |
Full example
canvas(width=200, height=100);
var col1 = "#CFD8DC";
var col2 = "#37474F";
circle(x= 50, y=50, radius=40, fill=col1);
text(col1, 50, 40, ax=MIDDLE, fill=color_contrast(color=col1));
circle(x=150, y=50, radius=40, fill=col2);
text(col2, 150, 40, ax=MIDDLE, fill=color_contrast(color=col2));
save(whoami(png=true));
