1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: accessors colors combinators kernel math math.order ;
10 { saturation read-only }
11 { lightness read-only }
20 : value ( p q t -- value )
21 dup 0 < [ 1.0 + ] when
22 dup 1 > [ 1.0 - ] when
24 { [ dup 1/6 < ] [ [ over - ] dip * 6 * + ] }
25 { [ dup 1/2 < ] [ drop nip ] }
26 { [ dup 2/3 < ] [ [ over - ] dip 2/3 swap - * 6 * + ] }
34 [ hue>> ] [ saturation>> ] [ lightness>> ] [ alpha>> ]
39 l 0.5 < [ l s 1 + * ] [ l s + l s * - ] if :> q
47 GENERIC: >hsla ( color -- hsla )
49 M: object >hsla >rgba >hsla ;
51 M: hsla >hsla ; inline
54 >rgba-components [| r g b |
55 r g b min min :> min-c
56 r g b max max :> max-c
57 min-c max-c + 2 / :> l
61 { r [ g b - d / g b < 6.0 0.0 ? + ] }
62 { g [ b r - d / 2.0 + ] }
63 { b [ r g - d / 4.0 + ] }