{ $subsections >rgba }
"Extracting RGBA components of colors:"
{ $subsections >rgba-components }
-"Mixing colors:"
-{ $subsections
- linear-gradient
- sample-linear-gradient
-}
"Further topics:"
{ $subsections
"colors.protocol"
+++ /dev/null
-USING: colors.constants kernel tools.test ;
-IN: colors
-
-{ COLOR: blue } [ COLOR: blue COLOR: red 0.0 linear-gradient ] unit-test
-{ COLOR: red } [ COLOR: blue COLOR: red 1.0 linear-gradient ] unit-test
-
-{ COLOR: blue } [ { COLOR: blue COLOR: red COLOR: green } 0.0 sample-linear-gradient ] unit-test
-{ COLOR: red } [ { COLOR: blue COLOR: red COLOR: green } 0.5 sample-linear-gradient ] unit-test
-{ COLOR: green } [ { COLOR: blue COLOR: red COLOR: green } 1.0 sample-linear-gradient ] unit-test
-
-{ t } [
- { COLOR: blue COLOR: red } 0.5 sample-linear-gradient
- COLOR: blue COLOR: red 0.5 linear-gradient =
-] unit-test
! Copyright (C) 2003, 2009 Slava Pestov.
! Copyright (C) 2008 Eduardo Cavazos.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators kernel locals math sequences ;
+USING: accessors combinators kernel math ;
IN: colors
TUPLE: color ;
CONSTANT: transparent T{ rgba f 0.0 0.0 0.0 0.0 }
-: linear-gradient ( color1 color2 percent -- color )
- [ 1.0 swap - * ] [ * ] bi-curry swapd
- [ [ >rgba-components drop ] [ tri@ ] bi* ] 2bi@
- [ + ] tri-curry@ tri* 1.0 <rgba> ;
-
-:: sample-linear-gradient ( colors percent -- color )
- colors length :> num-colors
- num-colors 1 - percent * >integer :> left-index
- 1.0 num-colors 1 - / :> cell-range
- percent left-index cell-range * - cell-range / :> alpha
- left-index colors nth :> left-color
- left-index 1 + num-colors mod colors nth :> right-color
- left-color right-color alpha linear-gradient ;
-
: inverse-color ( color -- color' )
>rgba-components [ [ 1.0 swap - ] tri@ ] dip <rgba> ;
--- /dev/null
+USING: colors.constants kernel tools.test ;
+IN: colors.mix
+
+{ COLOR: blue } [ COLOR: blue COLOR: red 0.0 linear-gradient ] unit-test
+{ COLOR: red } [ COLOR: blue COLOR: red 1.0 linear-gradient ] unit-test
+
+{ COLOR: blue } [ { COLOR: blue COLOR: red COLOR: green } 0.0 sample-linear-gradient ] unit-test
+{ COLOR: red } [ { COLOR: blue COLOR: red COLOR: green } 0.5 sample-linear-gradient ] unit-test
+{ COLOR: green } [ { COLOR: blue COLOR: red COLOR: green } 1.0 sample-linear-gradient ] unit-test
+
+{ t } [
+ { COLOR: blue COLOR: red } 0.5 sample-linear-gradient
+ COLOR: blue COLOR: red 0.5 linear-gradient =
+] unit-test
--- /dev/null
+! Copyright (C) 2013 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+USING: colors kernel locals math sequences ;
+IN: colors.mix
+
+: linear-gradient ( color1 color2 percent -- color )
+ [ 1.0 swap - * ] [ * ] bi-curry swapd
+ [ [ >rgba-components drop ] [ tri@ ] bi* ] 2bi@
+ [ + ] tri-curry@ tri* 1.0 <rgba> ;
+
+:: sample-linear-gradient ( colors percent -- color )
+ colors length :> num-colors
+ num-colors 1 - percent * >integer :> left-index
+ 1.0 num-colors 1 - / :> cell-range
+ percent left-index cell-range * - cell-range / :> alpha
+ left-index colors nth :> left-color
+ left-index 1 + num-colors mod colors nth :> right-color
+ left-color right-color alpha linear-gradient ;