From 713eb632c832264f8bbfdf63525b3e42446d3998 Mon Sep 17 00:00:00 2001 From: totoro Date: Sat, 24 Feb 2018 14:59:31 +0100 Subject: [PATCH] add brightness function which calculate the brightness of the given color. This is helpful for determine which color can readable with this color. --- web/color/color.anubis | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+), 0 deletions(-) create mode 100644 web/color/color.anubis diff --git a/web/color/color.anubis b/web/color/color.anubis new file mode 100644 index 0000000..f4e5948 --- /dev/null +++ b/web/color/color.anubis @@ -0,0 +1,32 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 07/01/2018 + * Time: 11:59 + * © Calexium + */ + +transmit system/string.anubis +transmit system/convert.anubis +transmit tools/maybefloat.anubis + + +public define Int +/** + */ + brightness + ( + String color //color value in hexadecimal form without any prefixed '0x' or '#' + )= + with red = hexa_to_mb_Float(color, 0, 2), + with green = hexa_to_mb_Float(color, 2, 2), + with blue = hexa_to_mb_Float(color, 4, 2), + if sqrt(red * red * success(0.241) + green * green * success(0.691) + blue * blue * success(0.068)) is + { + failure then /*println("brightness failure");*/255, + success(value) then + with result = integral_part(value), + //println("brightness value"+result); + result + } +. -- libgit2 0.21.4