MCPcopy Index your code
hub / github.com/davidmerfield/randomColor / HexToHSB

Function HexToHSB

randomColor.js:542–562  ·  view source on GitHub ↗
(hex)

Source from the content-addressed store, hash-verified

540 }
541
542 function HexToHSB(hex) {
543 hex = hex.replace(/^#/, "");
544 hex = hex.length === 3 ? hex.replace(/(.)/g, "$1$1") : hex;
545
546 var red = parseInt(hex.substr(0, 2), 16) / 255,
547 green = parseInt(hex.substr(2, 2), 16) / 255,
548 blue = parseInt(hex.substr(4, 2), 16) / 255;
549
550 var cMax = Math.max(red, green, blue),
551 delta = cMax - Math.min(red, green, blue),
552 saturation = cMax ? delta / cMax : 0;
553
554 switch (cMax) {
555 case red:
556 return [60 * (((green - blue) / delta) % 6) || 0, saturation, cMax];
557 case green:
558 return [60 * ((blue - red) / delta + 2) || 0, saturation, cMax];
559 case blue:
560 return [60 * ((red - green) / delta + 4) || 0, saturation, cMax];
561 }
562 }
563
564 function HSVtoHSL(hsv) {
565 var h = hsv[0],

Callers 2

getHueRangeFunction · 0.85
getRealHueRangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…