diff --git a/tinycolor.js b/tinycolor.js index 9ce79d8..2594fdd 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -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; },