Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: substack/mrcolor
base: master
...
head fork: rook2pawn/mrcolor
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 38 additions and 0 deletions.
  1. +5 −0 README.markdown
  2. +17 −0 index.js
  3. +16 −0 test/lighten.js
View
5 README.markdown
@@ -63,6 +63,11 @@ mr.take(n)
Generate `n` colors as an array.
+mr.lighten(color,[by])
+----------
+
+Return a lighter version of a color.
+
color objects
=============
View
17 index.js
@@ -77,3 +77,20 @@ mr.take = function (n) {
return res;
};
+
+mr.lighten = function(color,by) {
+ var hsv = color.hsv().map(function(val,idx) {
+ return (idx == 1) ? (by || 0.2) * val : val
+ });
+ return mr.fromHSL.apply(undefined,convert.hsv2hsl(hsv));
+};
+
+mr.rgbhexToColorObj = function(color) {
+ var cutHex = function (h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}
+ var hexToR = function (h) {return parseInt((cutHex(h)).substring(0,2),16)}
+ var hexToG = function (h) {return parseInt((cutHex(h)).substring(2,4),16)}
+ var hexToB = function (h) {return parseInt((cutHex(h)).substring(4,6),16)}
+
+ var rgb = [hexToR(color),hexToG(color),hexToB(color)];
+ return mr.fromHSL.apply(undefined,convert.rgb2hsl(rgb))
+}
View
16 test/lighten.js
@@ -0,0 +1,16 @@
+var assert = require('assert');
+
+var mr = require('../');
+var next = mr();
+var x = next();
+
+//console.log(x.hsl());console.log(y.hsl());console.log(z.hsl());
+
+exports.lighten = function () {
+
+ var y = mr.lighten(x);
+ var z = mr.lighten(x,0.5);
+
+ assert.equal(Math.round(y.hsl()[1]), 20);
+ assert.equal(Math.round(z.hsl()[1]), 50);
+};

No commit comments for this range

Something went wrong with that request. Please try again.