Skip to content

Commit ac92956

Browse files
authored
Merge pull request mdn#134 from hanche/fix-hwb
Fixed incorrect conversion to HWB
2 parents fbd0cd8 + cf69340 commit ac92956

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

modules/colors.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@
189189

190190
function createHWB(h, s, l, opacity) {
191191
const cell = document.querySelector("#HWB td");
192-
const hsv = (s * ((l < 50) ? l : 100 - l)) / 100;
193-
let W = (hsv === 0) ? 0 : ((2 * hsv) / (l + hsv)) * 100;
194-
let B = l + hsv;
192+
const chroma = s * (1 - Math.abs(l/50 - 1));
193+
let W = l - chroma / 2;
194+
let B = 100 - l - chroma / 2;
195195
W = W.toFixed(1);
196196
B = B.toFixed(1);
197197
if (opacity === 1) {

0 commit comments

Comments
 (0)