Skip to content
Browse files

seems to work now with range and colors stacks

  • Loading branch information...
1 parent 104dcfa commit 088177ef747233d4460acdca26812d5e9bea495d @substack committed
Showing with 27 additions and 22 deletions.
  1. +27 −22 index.js
View
49 index.js
@@ -1,33 +1,38 @@
var convert = require('color-convert');
var mr = module.exports = function () {
- return (function next (min, max) {
+ var ranges = [];
+ var colors = [];
+
+ function nextTwo (min, max) {
+ var dx = (max - min) / 2;
+
var i = min;
- var x = mr.fromIndex(i);
+ var j = Math.floor(dx + min);
- x.next = function () {
- var j = Math.floor((max - min) / 2 + min);
- var y = mr.fromIndex(j);
- y.next = function () {
- return next(Math.floor(i + (max - i) / 2 + i), max);
- };
- return y;
- };
+ colors.push(mr.fromIndex(i));
+ colors.push(mr.fromIndex(j));
- return x;
- })(0, 360);
-};
-
-mr.take = function (n) {
- var xs = [];
- var c = { next : mr };
-
- for (var i = 0; i < n; i++) {
- c = c.next();
- xs.push(c);
+ ranges.push([ i + dx / 2, j ]);
+ ranges.push([ j + dx / 2, max ]);
}
- return xs;
+ return (function next () {
+ if (colors.length) {
+ var c = colors.shift();
+ c.next = next;
+ return c;
+ }
+ else if (ranges.length) {
+ var r = ranges.shift();
+ nextTwo.apply(null, r);
+ return next();
+ }
+ else {
+ nextTwo(0, 360);
+ return next();
+ }
+ })();
};
mr.fromIndex = function (i) {

0 comments on commit 088177e

Please sign in to comment.
Something went wrong with that request. Please try again.