color-forge
Advanced tools
Comparing version 1.0.4 to 1.0.5
12
doc.md
@@ -44,2 +44,3 @@ ## Classes | ||
* [.burn(other)](#Color#burn) | ||
* [.exponent(power)](#Color#exponent) | ||
* _static_ | ||
@@ -249,2 +250,13 @@ * [.spaces](#Color.spaces) | ||
<a name="Color#exponent"></a> | ||
### color.exponent(power) | ||
Returns a new color that is the result of raising each power to an exponent. | ||
The resulting color has channels clipped at a maximum of 255. | ||
**Kind**: instance method of <code>[Color](#Color)</code> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| power | <code>number</code> | The power to raise each channel by | | ||
<a name="Color.spaces"></a> | ||
@@ -251,0 +263,0 @@ ### Color.spaces |
18
index.js
@@ -386,5 +386,21 @@ 'use strict'; | ||
}); | ||
/** | ||
Returns a new color that is the result of raising each power to an exponent. | ||
The resulting color has channels clipped at a maximum of 255. | ||
@function | ||
@param {number} power - The power to raise each channel by | ||
*/ | ||
Color.prototype.exponent = function exponent(power) { | ||
var values = this.convert('rgb').values.map(function(value) { | ||
return Math.min(Math.pow(value / 255, power), 255) * 255; | ||
}); | ||
var alpha = Math.pow(this.alpha, power); | ||
return new Color(values, alpha, 'rgb'); | ||
}; | ||
/** | ||
@@ -570,3 +586,3 @@ Available spaces for colors. Check`color-space` to ensure up-to-dateness. Note | ||
return new Color(values, alpha); | ||
return new Color(values, alpha, 'rgb'); | ||
}; | ||
@@ -573,0 +589,0 @@ } |
{ | ||
"name": "color-forge", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A simple color system based on the work of https://github.com/dfcreative/color-space", | ||
@@ -5,0 +5,0 @@ "url": "https://github.com/jacobp100/color-forge", |
@@ -110,2 +110,7 @@ /* eslint-env node, mocha */ | ||
}); | ||
it('Should raise to exponents', function() { | ||
assert.about(Color.hex('#111').exponent(2), Color.hex('#010101')); | ||
assert.about(Color.hex('#888').exponent(2), Color.hex('#494949')); | ||
assert.about(Color.hex('#fff').exponent(2), Color.hex('#ffffff')); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50370
882