Skip to content

Commit 4e08d08

Browse files
committed
Include current HSB/HSL maxes in functions retrieving values
1 parent e9eaf99 commit 4e08d08

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/color/creating_reading.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,25 @@ function creatingReading(p5, fn){
10431043
* </div>
10441044
*/
10451045
fn.hue = function(c) {
1046-
// p5._validateParameters('hue', arguments);
1047-
return this.color(c)._getHue();
1046+
let colorMode = HSL;
1047+
let i = 0;
1048+
1049+
if(
1050+
this._renderer.states.colorMode === HSB ||
1051+
this._renderer.states.colorMode === HSL
1052+
){
1053+
colorMode = this._renderer.states.colorMode;
1054+
}else if(
1055+
this._renderer.states.colorMode === LCH ||
1056+
this._renderer.states.colorMode === OKLCH
1057+
){
1058+
colorMode = this._renderer.states.colorMode;
1059+
i = 2;
1060+
}
1061+
1062+
return this.color(c)._getHue(
1063+
this._renderer.states.colorMaxes[colorMode][i]
1064+
);
10481065
};
10491066

10501067
/**
@@ -1220,8 +1237,16 @@ function creatingReading(p5, fn){
12201237
* </div>
12211238
*/
12221239
fn.saturation = function(c) {
1223-
// p5._validateParameters('saturation', arguments);
1224-
return this.color(c)._getSaturation();
1240+
const colorMode = (
1241+
this._renderer.states.colorMode === HSB ||
1242+
this._renderer.states.colorMode === HSL
1243+
) ?
1244+
this._renderer.states.colorMode :
1245+
HSL;
1246+
1247+
return this.color(c)._getSaturation(
1248+
this._renderer.states.colorMaxes[colorMode][1]
1249+
);
12251250
};
12261251

12271252
/**
@@ -1365,8 +1390,9 @@ function creatingReading(p5, fn){
13651390
* </div>
13661391
*/
13671392
fn.brightness = function(c) {
1368-
// p5._validateParameters('brightness', arguments);
1369-
return this.color(c)._getBrightness();
1393+
return this.color(c)._getBrightness(
1394+
this._renderer.states.colorMaxes.hsb[2]
1395+
);
13701396
};
13711397

13721398
/**
@@ -1510,8 +1536,9 @@ function creatingReading(p5, fn){
15101536
* </div>
15111537
*/
15121538
fn.lightness = function(c) {
1513-
// p5._validateParameters('lightness', arguments);
1514-
return this.color(c)._getLightness();
1539+
return this.color(c)._getLightness(
1540+
this._renderer.states.colorMaxes.hsl[2]
1541+
);
15151542
};
15161543

15171544
/**

src/color/p5.Color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,14 +630,14 @@ class Color {
630630
return map(to(this._color, 'hsl').coords[1], colorjsMax[0], colorjsMax[1], max[0], max[1]);
631631
}
632632
}
633+
633634
/**
634635
* Brightness obtains the HSB brightness value from either a p5.Color object,
635636
* an array of color components, or a CSS color string.Depending on value,
636637
* when `colorMode()` is set to HSB, this function will return the
637638
* brightness value in the range. By default, this function will return
638639
* the HSB brightness within the range 0 - 100.
639640
*/
640-
641641
_getBrightness(max=[0, 100]) {
642642
if(!Array.isArray(max)){
643643
max = [0, max];

0 commit comments

Comments
 (0)