From 93afebdb303b46215d8bf67c1f9e8d75f79be988 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 1 Feb 2009 20:32:00 -0600 Subject: [PATCH] colors: add an opaque? word and a transparent color --- basis/colors/colors.factor | 5 ++++- basis/colors/hsv/hsv-tests.factor | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/basis/colors/colors.factor b/basis/colors/colors.factor index 89f2dd1cd4..5a4e2134d5 100644 --- a/basis/colors/colors.factor +++ b/basis/colors/colors.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2003, 2009 Slava Pestov. ! Copyright (C) 2008 Eduardo Cavazos. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel accessors combinators ; +USING: kernel accessors combinators math ; IN: colors TUPLE: color ; @@ -21,6 +21,9 @@ M: color blue>> ( 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 } CONSTANT: black T{ rgba f 0.0 0.0 0.0 1.0 } CONSTANT: blue T{ rgba f 0.0 0.0 1.0 1.0 } CONSTANT: cyan T{ rgba f 0 0.941 0.941 1 } diff --git a/basis/colors/hsv/hsv-tests.factor b/basis/colors/hsv/hsv-tests.factor index 8a736553bb..a825cacda8 100644 --- a/basis/colors/hsv/hsv-tests.factor +++ b/basis/colors/hsv/hsv-tests.factor @@ -24,3 +24,5 @@ USING: accessors kernel colors colors.hsv tools.test math ; [ 5/6 5/36 5/6 ] [ 5/6 5/6 5/6 hsv>rgb ] unit-test [ 1/6 0 1/6 ] [ 5/6 1 1/6 hsv>rgb ] unit-test + +[ 0.5 ] [ 180 0.1 0.2 0.5 alpha>> ] unit-test \ No newline at end of file