]> gitweb.factorcode.org Git - factor.git/blob - basis/colors/mix/mix.factor
factor: trim using lists
[factor.git] / basis / colors / mix / mix.factor
1 ! Copyright (C) 2013 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: colors kernel math sequences ;
4 IN: colors.mix
5
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> ;
10
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 ;