]> gitweb.factorcode.org Git - factor.git/commitdiff
colors: move mixing words to colors.mix.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 3 Apr 2013 23:33:33 +0000 (16:33 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 3 Apr 2013 23:33:33 +0000 (16:33 -0700)
basis/colors/colors-docs.factor
basis/colors/colors-tests.factor [deleted file]
basis/colors/colors.factor
basis/colors/mix/mix-tests.factor [new file with mode: 0644]
basis/colors/mix/mix.factor [new file with mode: 0644]

index bef12c6e377fa8e83605c47ff70fbe8b41762dd5..5d6a2d268a57e7040767801822612141fe681d1d 100644 (file)
@@ -32,11 +32,6 @@ $nl
 { $subsections >rgba }
 "Extracting RGBA components of colors:"
 { $subsections >rgba-components }
-"Mixing colors:"
-{ $subsections
-    linear-gradient
-    sample-linear-gradient
-}
 "Further topics:"
 { $subsections
     "colors.protocol"
diff --git a/basis/colors/colors-tests.factor b/basis/colors/colors-tests.factor
deleted file mode 100644 (file)
index d316c2a..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-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
index ff4fe0539d8c744385cfea33b299b1a57bbc312d..5932d0ff156526c238c63b418ee7ee200f12bc8b 100644 (file)
@@ -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: accessors combinators kernel locals math sequences ;
+USING: accessors combinators kernel math ;
 IN: colors
 
 TUPLE: color ;
@@ -29,19 +29,5 @@ M: color blue>> ( color -- blue ) >rgba blue>> ;
 
 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> ;
diff --git a/basis/colors/mix/mix-tests.factor b/basis/colors/mix/mix-tests.factor
new file mode 100644 (file)
index 0000000..536f8ae
--- /dev/null
@@ -0,0 +1,14 @@
+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
diff --git a/basis/colors/mix/mix.factor b/basis/colors/mix/mix.factor
new file mode 100644 (file)
index 0000000..459c119
--- /dev/null
@@ -0,0 +1,18 @@
+! 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 ;