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
111 changes: 111 additions & 0 deletions tinycolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,117 @@ tinycolor.prototype = {
isLight: function() {
return !this.isDark();
},
/**
* The color with less brightness value is considered as Darker.
* @param {tinycolor} secondColor
*/
isDarker: function (secondColor) {
return this.getBrightness() < secondColor.getBrightness();
},
/**
* Return the opposite value of isDarker().
* @param {tinycolor} secondColor
*/
isLighter: function (secondColor) {
return !this.isDarker(secondColor);
},
isWarm: function () {
return this._r > this._b;
},
isCool: function () {
return !this.isWarm();
},
/**
* Returns true if the color is warmer i.e. have more red value.
* If both colors have the same red value the one with less green and blue values is considered warmer.
* @param {tinycolor} secondColor
*/
isWarmer: function (secondColor) {
if (this._r > secondColor._r)
return true;
if (this._r == secondColor._r) {
return (this._b + this._g) < (secondColor._b + secondColor._g);
}
return false;
},
/**
* Return the opposite value of isWarmer().
* @param {tinycolor} secondColor
*/
isCooler: function (secondColor) {
return !this.isWarmer(secondColor);
},
/**
* Returns true if colors are harmonious with the selected harmony.
*
* @param {String} harmony
* Should be a value from ['complement', 'analogous', 'monochromatic', 'splitcomplement', 'triad', 'tetrad'].
* @param {tinycolor[]} otherColors
* List of the colors to be checked.
* you have to pass
* 1 color for 'complement', 'monochromatic',
* 2 colors for 'analogous', 'splitcomplement', 'triad', and
* 3 colors for 'tetrad'.
* @src https://www.sessions.edu/color-calculator/
*/
isHarmonious: function (harmony, otherColors) {
var len = otherColors.length;
var result = false;
switch (harmony) {
case 'complement': {
var compColor = this.complement();
restult = compColor.toRgbString() == otherColors[0].toRgbString();
}
break;
case 'analogous': {
var anaList = this.analogous();
for (var aIndex = 0; aIndex < anaList.length; aIndex++) {
if (!(otherColors.includes(anaList[aIndex]))) {
result = false;
}
}
result = true;
}
break;
case 'monochromatic': {
var monoList = this.monochromatic();
for (var mIndex = 0; mIndex < monoList.length; mIndex++) {
if (!(otherColors.includes(monoList[mIndex])))
result = false;
}
result = true;
}
break;
case 'splitcomplement': {
var splitList = this.splitcomplement();
for (var sIndex = 0; sIndex < splitList.length; sIndex++) {
if (!(otherColors.includes(splitList[sIndex])))
result = false;
}
result = true;
}
break;
case 'triad': {
var triList = this.triad();
for (var tIndex = 0; tIndex < triList.length; tIndex++) {
if (!(otherColors.includes(triList[tIndex])))
result = false;
}
result = true;

}
break;
case 'tetrad': {
var tetList = this.tetrad();
for (var tetIndex = 0; tetIndex < tetList.length; tetIndex++) {
if (!(otherColors.includes(tetList[tetIndex])))
result = false;
}
result = true;
}
}
return result;
},
isValid: function() {
return this._ok;
},
Expand Down