Skip to content

Commit

Permalink
Change HSL to HSB and implement real HSL function
Browse files Browse the repository at this point in the history
  • Loading branch information
jaumard authored and jaumard committed Oct 12, 2015
1 parent 93ca0b3 commit 6f1ceff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,8 @@ up a desired Light State:
| `transitionInstant()` |A transition of 0ms|
| `transitionDefault()` |A transition time of the bridge default (400ms)|
| `white(colorTemp, briPercent)` | where colorTemp is a value between 154 (cool) and 500 (warm) and briPercent is 0 to 100|
| `hsl(hue, sat, briPercent)` | Where hue is a value from 0 to 359, sat is a saturation percent value from 0 to 100, and briPercent is from 0 to 100|
| `hsl(hue, sat, luminosity)` | Where hue is a value from 0 to 359, sat is a saturation percent value from 0 to 100, and luminosity is from 0 to 100|
| `hsb(hue, sat, brightness)` | Where hue is a value from 0 to 359, sat is a saturation percent value from 0 to 100, and brightness is from 0 to 100|
| `rgb(r, g, b)` | Sets an RGB value from integers 0-255|
| `rgb([r, g, b])` | Sets an RGB value from an array of integer values 0-255|
| `colorLoop()` | Starts a color loop effect (rotates through all available hues at the current saturation level)|
Expand Down
21 changes: 21 additions & 0 deletions hue-api/lightstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ State.prototype.white = function (colorTemp, brightPercentage) {
* @return {State}
*/
State.prototype.hsl = function (hue, saturation, luminosity) {
var t = saturation * (luminosity<50 ? luminosity : 100-luminosity) / 100; // Temp value
saturation = Math.round( 200 * t / (luminosity+t) ) |0;
luminosity = Math.round( t + luminosity );

var hueValue = _getBoundedValue(hue, 0, 360) * 182.5487; // degrees upscaled to 0-65535 range

return this
Expand All @@ -341,6 +345,23 @@ State.prototype.hsl = function (hue, saturation, luminosity) {
;
};

/**
* Adds the HSB values
* @param hue The hue value in degrees 0-360
* @param saturation The saturation percentage 0-100
* @param brightness The brightness percentage 0-100
* @return {State}
*/
State.prototype.hsb = function (hue, saturation, brightness) {
var hueValue = _getBoundedValue(hue, 0, 360) * 182.5487; // degrees upscaled to 0-65535 range

return this
.brightness(brightness)
.hue(hueValue)
.sat(_convertSaturationPercentToHueValue(saturation))
;
};

/**
* Adds the rgb color to the state. This requires knowledge of the light type to be able to convert it into
* an actual color that the map can display.
Expand Down

0 comments on commit 6f1ceff

Please sign in to comment.