Skip to content
Reference > AmiScript API > Methods

contrast(color,background)

Definition

String contrast(String color, String background)

Description

Returns #000000 or #FFFFFF, whichever is more legible on top of the supplied color. Colors are in #RRGGBB format. Returns null if the color argument is null or unparseable. Supply the background color when the first color is translucent, so the two are blended before the choice is made.

Parameter Definition

Name Type Description
color String Color that the text or shape will be drawn on top of, in rrggbb format
background String Color behind the first one, used only when the first color has alpha. Leave as empty string when the fill is opaque or the backdrop is unknown

Examples

1
2
3
4
5
String r1 = contrast("#FFFFFF",""); // r1 == #000000
String r2 = contrast("#000000",""); // r2 == #FFFFFF
String r3 = contrast("#FFCC00",""); // r3 == #000000
String r4 = contrast("#1B3A6B",""); // r4 == #FFFFFF
String r5 = contrast("#FFFFFF33","#111111"); // r5 == #FFFFFF