diff options
| author | jules <jules@okfoc.us> | 2014-01-05 18:56:32 -0500 |
|---|---|---|
| committer | jules <jules@okfoc.us> | 2014-01-05 18:56:32 -0500 |
| commit | 5592d810fc5080f37fee26f7ad7422f3630bce4c (patch) | |
| tree | 0403dd7abfd503ea34cb39e1e4f57dc5b5c310a7 /js | |
| parent | 235eb11d772fde9589c425ae13656874e76ed351 (diff) | |
frame weaving
Diffstat (limited to 'js')
| -rw-r--r-- | js/util.js | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -64,3 +64,34 @@ function smoothstep(n,a,b){ return t * t * (3.0 - 2.0 * t) } +function shuffle(a){ + for (var i = a.length; i > 0; i--){ + var r = randint(i) + var swap = a[i-1] + a[i-1] = a[r] + a[r] = swap + } + return a +} +function reverse(a){ + var reversed = [] + for (var i = 0, _len = a.length-1; i <= _len; i++){ + reversed[i] = a[_len-i] + } + return reversed +} +function deinterlace(a){ + var odd = [], even = [] + for (var i = 0, _len = a.length; i < _len; i++) { + if (i % 2) even.push(a[i]) + else odd.push(a[i]) + } + return [even, odd] +} +function weave(a){ + var aa = deinterlace(a) + var b = [] + aa[0].forEach(function(el){ b.push(el) }) + reverse(aa[1]).forEach(function(el){ b.push(el) }) + return b +} |
