From ca1a395dbdb7c5e09e8198db5c22baf356e2dc18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 8 Apr 2013 20:20:47 -0700 Subject: [PATCH] Invert Color#gray component. --- src/color/Color.js | 11 +++++------ test/tests/Color.js | 31 ++++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/color/Color.js b/src/color/Color.js index 39c3db01..599a6500 100644 --- a/src/color/Color.js +++ b/src/color/Color.js @@ -178,21 +178,20 @@ var Color = this.Color = Base.extend(new function() { // Using the standard NTSC conversion formula that is used for // calculating the effective luminance of an RGB color: // http://www.mathworks.com/support/solutions/en/data/1-1ASCU/index.html?solution=1-1ASCU - return [1 - (r * 0.2989 + g * 0.587 + b * 0.114)]; + return [r * 0.2989 + g * 0.587 + b * 0.114]; }, 'gray-rgb': function(g) { - var comp = 1 - g; - return [comp, comp, comp]; + return [g, g, g]; }, 'gray-hsb': function(g) { - return [0, 0, 1 - g]; + return [0, 0, g]; }, 'gray-hsl': function(g) { // TODO: Is lightness really the same as brightness for gray? - return [0, 0, 1 - g]; + return [0, 0, g]; } }; @@ -310,7 +309,7 @@ var Color = this.Color = Base.extend(new function() { } // Default fallbacks: rgb, black this._type = type || 'rgb'; - this._components = components || (type === 'gray' ? [1] : [0, 0, 0]); + this._components = components || (type === 'gray' ? [0] : [0, 0, 0]); this._alpha = alpha; if (this._read) this._read = read; diff --git a/test/tests/Color.js b/test/tests/Color.js index 1e80fed8..3a641391 100644 --- a/test/tests/Color.js +++ b/test/tests/Color.js @@ -40,7 +40,7 @@ test('Set color to object', function() { var path = new Path(); path.fillColor = { gray: 0.2 }; compareColors(path.fillColor, new Color(0.2)); - equals(path.fillColor.toCss(), 'rgb(204, 204, 204)'); + equals(path.fillColor.toCss(), 'rgb(51, 51, 51)'); }); test('Set color to array', function() { @@ -73,15 +73,15 @@ test('Creating colors', function() { test('Get gray from RGB Color', function() { var color = new Color(1, 0.5, 0.2); - compareNumbers(color.gray, 0.3848); + compareNumbers(color.gray, 0.6152); var color = new Color(0.5, 0.2, 0.1); - compareNumbers(color.gray, 0.72175); + compareNumbers(color.gray, 0.27825); }); test('Get gray from HSB Color', function() { var color = new HsbColor(0, 0, 0.2); - compareNumbers(color.gray, 0.80002); + compareNumbers(color.gray, 0.19998); }); test('Get red from HSB Color', function() { @@ -97,28 +97,29 @@ test('Get hue from RGB Color', function() { test('Gray Color', function() { var color = new Color(1); - compareNumbers(color.gray, 1); - compareNumbers(color.red, 0); - compareNumbers(color.blue, 0); + compareNumbers(color.gray, 1, 'color.gray'); + compareNumbers(color.red, 1, 'color.red'); + compareNumbers(color.blue, 1, 'color.blue'); color.red = 0.5; - compareNumbers(color.gray, 0.85055); + console.log(color + ''); + compareNumbers(color.gray, 0.85045, 'color.gray'); color.green = 0.2; - compareNumbers(color.red, 0.5); - compareNumbers(color.green, 0.2); - compareNumbers(color.blue, 0); + compareNumbers(color.red, 0.5, 'color.red'); + compareNumbers(color.green, 0.2, 'color.green'); + compareNumbers(color.blue, 1, 'color.blue'); - compareNumbers(color.gray, 0.73315); + compareNumbers(color.gray, 0.38085, 'color.gray'); }); test('Converting Colors', function() { var rgbColor = new Color(1, 0.5, 0.2); - compareNumbers(rgbColor.gray, 0.3848); + compareNumbers(rgbColor.gray, 0.6152); var grayColor = new Color(0.2); - compareColors(grayColor.convert('rgb'), new Color(0.8, 0.8, 0.8)); - compareColors(grayColor.convert('hsb'), { hue: 0, saturation: 0, brightness: 0.8 }); + compareColors(grayColor.convert('rgb'), new Color(0.2, 0.2, 0.2)); + compareColors(grayColor.convert('hsb'), { hue: 0, saturation: 0, brightness: 0.2 }); compareColors(new Color(1, 0, 0).convert('hsb'), { hue: 0, saturation: 1, brightness: 1 }); });