Permalink
Browse files

works much better around 0 to 360 discontinuity

  • Loading branch information...
1 parent 0ae1d2e commit c4ffb73ed823d6e3084ec75463e8566d12f1a19f @substack substack committed Jul 10, 2011
Showing with 45 additions and 55 deletions.
  1. +0 −12 example/browser/index.html
  2. +11 −1 example/browser/server.js
  3. +9 −0 example/browser/views/index.jade
  4. +25 −42 index.js
@@ -1,12 +0,0 @@
-<html>
- <head>
- <title>Mr. Color, requisition me some colors post haste!</title>
- <script type="text/javascript" src="/browserify.js"></script>
- </head>
- <body>
- <div>
- <input id="clicky" type="button" value="more colors!">
- </div>
- <div id="colors"></div>
- </body>
-</html>
@@ -3,8 +3,18 @@ var app = express.createServer();
app.use(express.static(__dirname));
var browserify = require('browserify');
-var bundle = browserify({ entry : __dirname + '/main.js' });
+var bundle = browserify({
+ entry : __dirname + '/main.js',
+ watch : true
+});
app.use(bundle);
+app.get('/', function (req, res) {
+ res.render('index.jade', {
+ modified : bundle.modified,
+ layout : false
+ });
+});
+
app.listen(8080);
console.log('Listening on :8080');
@@ -0,0 +1,9 @@
+!!!
+html
+ head
+ title Mr. Color, requisition me some colors post haste!
+ script(type='text/javascript', src='/browserify.js?' + modified)
+ body
+ div
+ input#clicky(type='button', value='more colors!')
+ div#colors
View
@@ -1,53 +1,36 @@
var convert = require('color-convert');
var mr = module.exports = function () {
- var angle = 0;
- var bi = mr.biforcate(0, 60);
- var offset = bi();
+ var used = [];
+ var num = 0;
+ var last = [];
return function next () {
- if (angle + 60 >= 360) {
- offset = bi();
- angle = offset;
- }
-
- var a = Math.floor(angle);
- angle += 60;
-
- return mr.fromAngle(a);
- };
-};
-
-mr.biforcate = function (m, n) {
- var ranges = [];
- var indexes = [];
-
- function next (min, max) {
- var dx = (max - min) / 2;
-
- 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();
+ var angle;
+ if (num < 6) {
+ angle = 60 * num;
+ used.push(angle);
+ if (num === 5) used.push(360);
}
else {
- throw new Error('wtf');
+ var dxs = used.slice(1).map(function (u, i) {
+ return (u - used[i]) * last.every(function (x) {
+ return Math.abs(u - x) > 60
+ && Math.abs((u - 360) - x) > 60
+ ;
+ });
+ });
+ var ix = dxs.indexOf(Math.max.apply(null, dxs));
+
+ var x = used[ix];
+ var y = used[ix+1];
+ angle = Math.floor(x + (y - x) / 2);
+ used.splice(ix + 1, 0, angle);
}
+
+ num ++;
+ last = [angle].concat(last).slice(0,4);
+ return mr.fromAngle(angle);
};
};

0 comments on commit c4ffb73

Please sign in to comment.