diff options
| author | Julie Lala <jules@okfoc.us> | 2013-12-10 00:47:36 -0500 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2013-12-10 00:47:36 -0500 |
| commit | 037a0ae8072217f7821549bbdfe030e73289330d (patch) | |
| tree | b2e20cff097a44e08cd8e6609e7d5a00b732d88c /gif-encode/util.js | |
dither stuff
Diffstat (limited to 'gif-encode/util.js')
| -rw-r--r-- | gif-encode/util.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gif-encode/util.js b/gif-encode/util.js new file mode 100644 index 0000000..92d8129 --- /dev/null +++ b/gif-encode/util.js @@ -0,0 +1,15 @@ +function shuffle(a){ + var aa = new Array(a.length); + aa[0] = a[0]; + + for (var i = 1; i < a.length; i++) { + var j = Math.floor( Math.random() * i ); + aa[i] = aa[j]; + aa[j] = a[i]; + } + return aa; +} +function sample(a, n) { + var aa = shuffle(a); + return aa.slice(0,n); +} |
