Permalink
Browse files

combining new offsets with old stuff, still needs better jumps

  • Loading branch information...
1 parent 1fa17ee commit 0ae1d2e8a3a7c0de0ea647622ce8b479381fea0d @substack committed Jul 10, 2011
Showing with 37 additions and 11 deletions.
  1. +37 −11 index.js
View
@@ -2,25 +2,51 @@ var convert = require('color-convert');
var mr = module.exports = function () {
var angle = 0;
- var step = 60;
-
- var used = {};
+ var bi = mr.biforcate(0, 60);
+ var offset = bi();
return function next () {
- if (angle + step > 360) {
- step /= 2;
- angle = step;
+ if (angle + 60 >= 360) {
+ offset = bi();
+ angle = offset;
}
var a = Math.floor(angle);
- angle += step;
+ angle += 60;
+
+ return mr.fromAngle(a);
+ };
+};
+
+mr.biforcate = function (m, n) {
+ var ranges = [];
+ var indexes = [];
+
+ function next (min, max) {
+ var dx = (max - min) / 2;
- if (used[a]) {
- return next();
+ var i = min;
+ indexes.push(i);
+
+ var j = Math.floor(dx + min);
+ indexes.push(j);
+
+ ranges.push([ i + dx / 2, j ]);
+ ranges.push([ j + dx / 2, max ]);
+ }
+ next(m, n);
+
+ return function result () {
+ if (indexes.length) {
+ return indexes.shift();
+ }
+ else if (ranges.length) {
+ var r = ranges.shift();
+ next.apply(null, r);
+ return indexes.shift();
}
else {
- used[a] = true;
- return mr.fromAngle(a);
+ throw new Error('wtf');
}
};
};

0 comments on commit 0ae1d2e

Please sign in to comment.