Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/color/creating_reading.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,25 @@ function creatingReading(p5, fn){
* </div>
*/
fn.hue = function(c) {
// p5._validateParameters('hue', arguments);
return this.color(c)._getHue();
let colorMode = HSL;
let i = 0;

if(
this._renderer.states.colorMode === HSB ||
this._renderer.states.colorMode === HSL
){
colorMode = this._renderer.states.colorMode;
}else if(
this._renderer.states.colorMode === LCH ||
this._renderer.states.colorMode === OKLCH
){
colorMode = this._renderer.states.colorMode;
i = 2;
}

return this.color(c)._getHue(
this._renderer.states.colorMaxes[colorMode][i]
);
};

/**
Expand Down Expand Up @@ -1220,8 +1237,10 @@ function creatingReading(p5, fn){
* </div>
*/
fn.saturation = function(c) {
// p5._validateParameters('saturation', arguments);
return this.color(c)._getSaturation();
const colorMode = (this._renderer.states.colorMode === HSB) ? HSB : HSL;
return this.color(c)._getSaturation(
this._renderer.states.colorMaxes[colorMode][1]
);
};

/**
Expand Down Expand Up @@ -1365,8 +1384,9 @@ function creatingReading(p5, fn){
* </div>
*/
fn.brightness = function(c) {
// p5._validateParameters('brightness', arguments);
return this.color(c)._getBrightness();
return this.color(c)._getBrightness(
this._renderer.states.colorMaxes.hsb[2]
);
};

/**
Expand Down Expand Up @@ -1510,8 +1530,9 @@ function creatingReading(p5, fn){
* </div>
*/
fn.lightness = function(c) {
// p5._validateParameters('lightness', arguments);
return this.color(c)._getLightness();
return this.color(c)._getLightness(
this._renderer.states.colorMaxes.hsl[2]
);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/color/p5.Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,14 @@ class Color {
return map(to(this._color, 'hsl').coords[1], colorjsMax[0], colorjsMax[1], max[0], max[1]);
}
}

/**
* Brightness obtains the HSB brightness value from either a p5.Color object,
* an array of color components, or a CSS color string.Depending on value,
* when `colorMode()` is set to HSB, this function will return the
* brightness value in the range. By default, this function will return
* the HSB brightness within the range 0 - 100.
*/

_getBrightness(max=[0, 100]) {
if(!Array.isArray(max)){
max = [0, max];
Expand Down
Loading