Permalink
Browse files

fixes issue #3

  • Loading branch information...
1 parent f8bd3fc commit 654d553f54856602a5994bf02b285de85cdd02bf @brehaut committed Mar 4, 2013
Showing with 32 additions and 14 deletions.
  1. +21 −4 color.js
  2. +11 −10 test/color-test.js
View
@@ -37,6 +37,7 @@ if (!net.brehaut) { net.brehaut = {}; }
// this module function is called with net.brehaut as 'this'
(function ( ) {
+ "use strict";
// Constants
// css_colors maps color names onto their hex values
@@ -443,19 +444,19 @@ if (!net.brehaut) { net.brehaut = {}; }
this.hue = hue;
}),
- darkenByAmount: cloneOnApply(function ( val ) {
+ devalueByAmount: cloneOnApply(function ( val ) {
this.value = Math.min(1, Math.max(this.value - val, 0));
}),
- darkenByRatio: cloneOnApply(function ( val ) {
+ devalueByRatio: cloneOnApply(function ( val ) {
this.value = Math.min(1, Math.max(this.value * (1 - val), 0));
}),
- lightenByAmount: cloneOnApply(function ( val ) {
+ valueByAmount: cloneOnApply(function ( val ) {
this.value = Math.min(1, Math.max(this.value + val, 0));
}),
- lightenByRatio: cloneOnApply(function ( val ) {
+ valueByRatio: cloneOnApply(function ( val ) {
this.value = Math.min(1, Math.max(this.value * (1 + val), 0));
}),
@@ -664,6 +665,22 @@ if (!net.brehaut) { net.brehaut = {}; }
saturation: 0,
lightness: 0,
+ darkenByAmount: cloneOnApply(function ( val ) {
+ this.lightness = Math.min(1, Math.max(this.lightness - val, 0));
+ }),
+
+ darkenByRatio: cloneOnApply(function ( val ) {
+ this.lightness = Math.min(1, Math.max(this.lightness * (1 - val), 0));
+ }),
+
+ lightenByAmount: cloneOnApply(function ( val ) {
+ this.lightness = Math.min(1, Math.max(this.lightness + val, 0));
+ }),
+
+ lightenByRatio: cloneOnApply(function ( val ) {
+ this.lightness = Math.min(1, Math.max(this.lightness * (1 + val), 0));
+ }),
+
fromObject: function ( o ) {
if ("string" == typeof o) {
return this._fromCSS( o );
View
@@ -205,25 +205,26 @@ vows.describe('Color').addBatch({
topic: Color({ hue: 90,
saturation: .5,
value: .5 }),
- 'lightened by 1000% should be equal to HSV(H=90; S=0.5; V=1)': function(color) {
- assert.colorEqual(color.lightenByRatio(10), Color({ hue: 90,
- saturation: .5,
- value: 1 }));
+ 'increase value by 1000% should be equal to HSV(H=90; S=0.5; V=1)': function(color) {
+ assert.colorEqual( color.valueByRatio(10),
+ Color({ hue: 90,
+ saturation: .5,
+ value: 1 }));
},
- 'lightened by 0.1 should be equal to HSV(H=90; S=0.5; V=0.6)': function(color) {
- assert.colorEqual( color.lightenByAmount(.1),
+ 'increase value by 0.1 should be equal to HSV(H=90; S=0.5; V=0.6)': function(color) {
+ assert.colorEqual( color.valueByAmount(.1),
Color({ hue: 90,
saturation: .5,
value: .6 }) );
},
- 'darkened by 50% should be equal to HSV(H=90; S=0.5; V=0.25)': function(color) {
- assert.colorEqual( color.darkenByRatio(.5),
+ 'devalue by 50% should be equal to HSV(H=90; S=0.5; V=0.25)': function(color) {
+ assert.colorEqual( color.devalueByRatio(.5),
Color({ hue: 90,
saturation: .5,
value: .25 }) );
},
- 'darkened by 2.3 should be equal to HSV(H=90; S=0.5; V=0)': function(color) {
- assert.colorEqual( color.darkenByAmount(2.3),
+ 'devalue by 2.3 should be equal to HSV(H=90; S=0.5; V=0)': function(color) {
+ assert.colorEqual( color.devalueByAmount(2.3),
Color({ hue: 90,
saturation: .5,
value: 0 }) );

0 comments on commit 654d553

Please sign in to comment.