]> gitweb.factorcode.org Git - factor.git/blob - basis/colors/colors.factor
9e5fef11344f9861618ec0c3a04924cc6c0a2c6b
[factor.git] / basis / colors / colors.factor
1 ! Copyright (C) 2003, 2009 Slava Pestov.
2 ! Copyright (C) 2008 Eduardo Cavazos.
3 ! See http://factorcode.org/license.txt for BSD license.
4 USING: accessors combinators kernel math ;
5 IN: colors
6
7 TUPLE: color ;
8
9 TUPLE: rgba < color
10 { red read-only }
11 { green read-only }
12 { blue read-only }
13 { alpha read-only } ;
14
15 C: <rgba> rgba
16
17 GENERIC: >rgba ( color -- rgba )
18
19 M: rgba >rgba ; inline
20
21 M: color red>> >rgba red>> ;
22 M: color green>> >rgba green>> ;
23 M: color blue>> >rgba blue>> ;
24
25 : >rgba-components ( object -- r g b a )
26     >rgba { [ red>> ] [ green>> ] [ blue>> ] [ alpha>> ] } cleave ; inline
27
28 : opaque? ( color -- ? ) alpha>> 1 number= ;
29
30 CONSTANT: transparent T{ rgba f 0.0 0.0 0.0 0.0 }
31
32 : inverse-color ( color -- color' )
33     >rgba-components [ [ 1.0 swap - ] tri@ ] dip <rgba> ;