From 63d4f559e31cdd7f03d24fe0adda562559505af3 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <cwillisf@media.mit.edu> Date: Tue, 3 May 2016 10:01:52 -0700 Subject: [PATCH] Fix inconsistent color scale The HSV-to-RGB function had been returning values in the range [0,1]. Now it uses [0,255] to be consistent with the other values returned by _getColor. --- src/blocks/wedo2.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/blocks/wedo2.js b/src/blocks/wedo2.js index c38b8f62d..f69d557eb 100644 --- a/src/blocks/wedo2.js +++ b/src/blocks/wedo2.js @@ -58,7 +58,7 @@ WeDo2Blocks.prototype._clamp = function(val, min, max) { * @param hueDegrees Hue, in degrees. * @param saturation Saturation in the range [0,1]. * @param value Value in the range [0,1]. - * @returns {number[]} An array of [r,g,b], each in the range [0,1]. + * @returns {number[]} An array of [r,g,b], each in the range [0,255]. * @private */ WeDo2Blocks.prototype._HSVToRGB = function(hueDegrees, saturation, value) { @@ -93,9 +93,9 @@ WeDo2Blocks.prototype._HSVToRGB = function(hueDegrees, saturation, value) { } var m = value - chroma; - rgb[0] += m; - rgb[1] += m; - rgb[2] += m; + rgb[0] = (rgb[0] + m) * 255; + rgb[1] = (rgb[1] + m) * 255; + rgb[2] = (rgb[2] + m) * 255; return rgb; }; @@ -169,8 +169,7 @@ WeDo2Blocks.prototype._getColor = function(colorName) { WeDo2Blocks.prototype.setColor = function(argValues) { if (window.native) { var rgbColor = this._getColor(argValues[0]); - window.native.setLedColor( - 255 * rgbColor[0], 255 * rgbColor[1], 255 * rgbColor[2]); + window.native.setLedColor(rgbColor[0], rgbColor[1], rgbColor[2]); } };