Commit 713eb632c832264f8bbfdf63525b3e42446d3998
1 parent
a1b77a92
add brightness function which calculate the brightness of the given color. This …
…is helpful for determine which color can readable with this color.
Showing
1 changed file
with
32 additions
and
0 deletions
Show diff stats
| 1 | +/* | |
| 2 | + * Created by PyramIDE. | |
| 3 | + * User: フランスのトトロ aka (David RENÉ) | |
| 4 | + * Date: 07/01/2018 | |
| 5 | + * Time: 11:59 | |
| 6 | + * © Calexium | |
| 7 | + */ | |
| 8 | + | |
| 9 | +transmit system/string.anubis | |
| 10 | +transmit system/convert.anubis | |
| 11 | +transmit tools/maybefloat.anubis | |
| 12 | + | |
| 13 | + | |
| 14 | +public define Int | |
| 15 | +/** | |
| 16 | + */ | |
| 17 | + brightness | |
| 18 | + ( | |
| 19 | + String color //color value in hexadecimal form without any prefixed '0x' or '#' | |
| 20 | + )= | |
| 21 | + with red = hexa_to_mb_Float(color, 0, 2), | |
| 22 | + with green = hexa_to_mb_Float(color, 2, 2), | |
| 23 | + with blue = hexa_to_mb_Float(color, 4, 2), | |
| 24 | + if sqrt(red * red * success(0.241) + green * green * success(0.691) + blue * blue * success(0.068)) is | |
| 25 | + { | |
| 26 | + failure then /*println("brightness failure");*/255, | |
| 27 | + success(value) then | |
| 28 | + with result = integral_part(value), | |
| 29 | + //println("brightness value"+result); | |
| 30 | + result | |
| 31 | + } | |
| 32 | +. | ... | ... |