color_contrast
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 | Required | Default | Description |
|---|---|---|---|
color | 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, 55, ax=MIDDLE, stroke=color_contrast(color=col1));
circle(x=150, y=50, radius=40, fill=col2);
text(col2, 150, 55, ax=MIDDLE, stroke=color_contrast(color=col2));
save("color_contrast.png");
