Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

some gray all up in this

  • Loading branch information...
commit 1ac158871af4de23d266445a92b4939d92a466df 1 parent c4ffb73
@substack authored
Showing with 22 additions and 12 deletions.
  1. +6 −4 example/browser/main.js
  2. +16 −8 index.js
View
10 example/browser/main.js
@@ -6,16 +6,18 @@ $(window).ready(function () {
$('#clicky').click(function () {
var color = next();
- var rgb = 'rgb(' + color.rgb().join(',') + ')';
+ var rgb = color.rgb();
+ var rgbStr = 'rgb(' + rgb.join(',') + ')';
$('<div>')
.css({
- 'background-color' : rgb,
- color : 'white',
+ 'background-color' : rgbStr,
+ color : (rgb[0] + rgb[1] + rgb[2]) / 3 > 128
+ ? 'black' : 'white',
width : 500,
height : 30
})
- .text(rgb)
+ .text(rgbStr)
.appendTo($('#colors'))
;
});
View
24 index.js
@@ -30,27 +30,35 @@ var mr = module.exports = function () {
num ++;
last = [angle].concat(last).slice(0,4);
- return mr.fromAngle(angle);
+
+ return mr.fromHSL(
+ angle,
+ 75 + Math.random() * 25 * (1 - 1 / Math.sqrt(num)),
+ 25 + Math.random() * 50
+ );
};
};
-mr.fromAngle = function (i) {
+mr.fromHSL = function (h, s, l) {
+ if (!s) s = 100;
+ if (!l) l = 50;
+ var hsl = [ h, s, l ];
+
return {
- index : i,
rgb : function () {
- return convert.hsl2rgb([ i, 100, 50 ])
+ return convert.hsl2rgb(hsl);
},
hsl : function () {
- return [ i, 100, 50 ];
+ return hsl;
},
hsv : function () {
- return convert.hsl2hsv([ i, 100, 50 ])
+ return convert.hsl2hsv(hsl)
},
cmyk : function () {
- return convert.hsl2cmyk([ i, 100, 50 ])
+ return convert.hsl2cmyk(hsl)
},
xyz : function () {
- return convert.hsl2xyz([ i, 100, 50 ])
+ return convert.hsl2xyz(hsl)
}
};
};
Please sign in to comment.
Something went wrong with that request. Please try again.