Created
January 8, 2016 03:07
-
-
Save Skrylar/a7a46ea69073aea68ef7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ralette-grammar: [ | |
collect any [ | |
['decompose [ | |
'rgb keep ([ | |
r: (color/1) / 255.0 | |
g: (color/2) / 255.0 | |
b: (color/3) / 255.0 | |
]) | | |
'hsl keep ([ | |
h: (color/1) / 255.0 | |
s: (color/2) / 255.0 | |
l: (color/3) / 255.0 | |
]) | | |
'hsv keep ([ | |
h: (color/1) / 255.0 | |
s: (color/2) / 255.0 | |
v: (color/3) / 255.0 | |
])] | |
] | | |
['compose [ | |
'rgb keep ([ | |
pack3 r g b | |
]) | | |
'hsl keep ([ | |
pack3 h s l | |
]) | | |
'hsv keep ([ | |
pack3 h s v | |
]) | |
] | |
] | | |
['m 'from | |
'rgb keep ([ | |
minc: min min r g b | |
maxc: max max r g b | |
]) | |
] | | |
['chroma 'from | |
'rgb keep ([ | |
chroma: to float! (maxc - minc) | |
]) | |
] | | |
['hue 'from | |
'rgb keep ([ | |
h: 0 | |
if chroma <> 0 [ | |
if maxc = r [h: modulo ((g - b) / chroma) 6] | |
if maxc = g [h: ((b - r) / chroma) + 2] | |
if maxc = b [h: ((r - g) / chroma) + 4] | |
] | |
h: (h * 60.0)]) | |
] | | |
['lightness 'from 'rgb keep ([ | |
l: (maxc + minc) * 0.5 | |
]) | |
] | | |
['saturation 'from 'rgb 'for 'hsl keep ([ | |
s-hsl: either chroma <> 0 [ | |
chroma / (1 - absolute (2 * lightness - 1)) | |
][ | |
0 | |
]]) | |
] | | |
['return [ | |
['hue keep ([h])] | | |
['lightness keep ([l])] | | |
['saturation 'for 'hsl keep ([s-hsl])] | |
] | |
] | |
] | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment