Permalink
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (23 sloc) 783 Bytes
! Copyright (C) 2003, 2009 Slava Pestov.
! Copyright (C) 2008 Eduardo Cavazos.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors combinators kernel math ;
IN: colors
TUPLE: color ;
TUPLE: rgba < color
{ red read-only }
{ green read-only }
{ blue read-only }
{ alpha read-only } ;
C: <rgba> rgba
GENERIC: >rgba ( color -- rgba )
M: rgba >rgba ; inline
M: color red>> >rgba red>> ;
M: color green>> >rgba green>> ;
M: color blue>> >rgba blue>> ;
: >rgba-components ( object -- r g b a )
>rgba { [ red>> ] [ green>> ] [ blue>> ] [ alpha>> ] } cleave ; inline
: opaque? ( color -- ? ) alpha>> 1 number= ;
CONSTANT: transparent T{ rgba f 0.0 0.0 0.0 0.0 }
: inverse-color ( color -- color' )
>rgba-components [ [ 1.0 swap - ] tri@ ] dip <rgba> ;