Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tinycolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var trimLeft = /^\s+/,
mathRound = Math.round,
mathMin = Math.min,
mathMax = Math.max,
mathRandom = Math.random;
mathRandom = Math.random,
mathAbsolute = Math.abs;

function tinycolor (color, opts) {

Expand Down Expand Up @@ -85,6 +86,14 @@ tinycolor.prototype = {
if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}
return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
},
getSaturation: function () {
var rgb = this.toRgb();
var maxRGB = mathMax(rgb.r, rgb.g, rgb.b) / 255;
var minRGB = mathMin(rgb.r, rgb.g, rgb.b) / 255;
var luminance = this.getLuminance();

return luminance === 1 ? 0 : (maxRGB - minRGB) / (1 - mathAbsolute(2 * luminance - 1));
},
setAlpha: function(value) {
this._a = boundAlpha(value);
this._roundA = mathRound(100*this._a) / 100;
Expand Down