PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/utils/mixers.js

https://github.com/ajanthanm/cssfilterlab
JavaScript | 59 lines | 37 code | 7 blank | 15 comment | 3 complexity | 058ae4c648281320f4ba48736216d602 MD5 | raw file
 1/*
 2 * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
 3 * 
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 * 
 8 *     http://www.apache.org/licenses/LICENSE-2.0
 9 * 
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17(function(){
18
19    var mixers = {
20        mixNumber: function(a, b, t) {
21            return a * (1 - t) + b * t;
22        },
23        
24        mixVector: function(a, b, t) {
25            var r = [];
26            for (var i=0; i<a.length; ++i)
27                r.push(mixers.mixNumber(a[i], b[i], t));
28            return r;
29        },
30        
31        mixVectorOfVectors: function(a, b, t) {
32            var r = [];
33            for (var i=0; i < a.length; ++i) {
34                var row = []; r.push(row);
35                var l2 = a[i].length;
36                for (var j=0; j < l2; ++j)
37                    row.push(Global.mixers.mixVector(a[i][j], b[i][j], t));
38            }
39            return r;
40        },
41        
42        mixHash: function(fn) {
43            var mixFn = Global.mixers[fn];
44            return function(a, b, t) {
45                var r = {};
46                $.each(a, function(key, valueA) {
47                    r[key] = mixFn(valueA, b[key], t);
48                });
49                return r;
50            }
51        },
52        
53        dontMix: function(a, b, t) {
54            return a;
55        }
56    };
57
58    Global.mixers = mixers;
59})();