1 ! Copyright (C) 2013 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: colors kernel math sequences ;
6 : linear-gradient ( color1 color2 percent -- color )
7 [ 1.0 swap - * ] [ * ] bi-curry swapd
8 [ [ >rgba-components drop ] [ tri@ ] bi* ] 2bi@
9 [ + ] tri-curry@ tri* 1.0 <rgba> ;
11 :: sample-linear-gradient ( colors percent -- color )
12 colors length :> num-colors
13 num-colors 1 - percent * >integer :> left-index
14 1.0 num-colors 1 - / :> cell-range
15 percent left-index cell-range * - cell-range / :> alpha
16 left-index colors nth :> left-color
17 left-index 1 + num-colors mod colors nth :> right-color
18 left-color right-color alpha linear-gradient ;