Skip to content

Commit 10a2d43

Browse files
authored
Merge pull request #8062 from limzykenneth/fix-hsbl-maxes
Include use of relevant maxes in `hue()`, `saturation()`, `brightness()` and `lightness()`
2 parents fc8ca8a + 6d115df commit 10a2d43

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/color/creating_reading.js

Lines changed: 29 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,10 @@ 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 = (this._renderer.states.colorMode === HSB) ? HSB : HSL;
1241+
return this.color(c)._getSaturation(
1242+
this._renderer.states.colorMaxes[colorMode][1]
1243+
);
12251244
};
12261245

12271246
/**
@@ -1365,8 +1384,9 @@ function creatingReading(p5, fn){
13651384
* </div>
13661385
*/
13671386
fn.brightness = function(c) {
1368-
// p5._validateParameters('brightness', arguments);
1369-
return this.color(c)._getBrightness();
1387+
return this.color(c)._getBrightness(
1388+
this._renderer.states.colorMaxes.hsb[2]
1389+
);
13701390
};
13711391

13721392
/**
@@ -1510,8 +1530,9 @@ function creatingReading(p5, fn){
15101530
* </div>
15111531
*/
15121532
fn.lightness = function(c) {
1513-
// p5._validateParameters('lightness', arguments);
1514-
return this.color(c)._getLightness();
1533+
return this.color(c)._getLightness(
1534+
this._renderer.states.colorMaxes.hsl[2]
1535+
);
15151536
};
15161537

15171538
/**

src/color/p5.Color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,14 +689,14 @@ class Color {
689689
return map(to(this._color, 'hsl').coords[1], colorjsMax[0], colorjsMax[1], max[0], max[1]);
690690
}
691691
}
692+
692693
/**
693694
* Brightness obtains the HSB brightness value from either a p5.Color object,
694695
* an array of color components, or a CSS color string.Depending on value,
695696
* when `colorMode()` is set to HSB, this function will return the
696697
* brightness value in the range. By default, this function will return
697698
* the HSB brightness within the range 0 - 100.
698699
*/
699-
700700
_getBrightness(max=[0, 100]) {
701701
if(!Array.isArray(max)){
702702
max = [0, max];

0 commit comments

Comments
 (0)