MCPcopy Create free account
hub / github.com/davidmerfield/randomColor / HSVtoRGB

Function HSVtoRGB

randomColor.js:476–540  ·  view source on GitHub ↗
(hsv)

Source from the content-addressed store, hash-verified

474 }
475
476 function HSVtoRGB(hsv) {
477 // this doesn't work for the values of 0 and 360
478 // here's the hacky fix
479 var h = hsv[0];
480 if (h === 0) {
481 h = 1;
482 }
483 if (h === 360) {
484 h = 359;
485 }
486
487 // Rebase the h,s,v values
488 h = h / 360;
489 var s = hsv[1] / 100,
490 v = hsv[2] / 100;
491
492 var h_i = Math.floor(h * 6),
493 f = h * 6 - h_i,
494 p = v * (1 - s),
495 q = v * (1 - f * s),
496 t = v * (1 - (1 - f) * s),
497 r = 256,
498 g = 256,
499 b = 256;
500
501 switch (h_i) {
502 case 0:
503 r = v;
504 g = t;
505 b = p;
506 break;
507 case 1:
508 r = q;
509 g = v;
510 b = p;
511 break;
512 case 2:
513 r = p;
514 g = v;
515 b = t;
516 break;
517 case 3:
518 r = p;
519 g = q;
520 b = v;
521 break;
522 case 4:
523 r = t;
524 g = p;
525 b = v;
526 break;
527 case 5:
528 r = v;
529 g = p;
530 b = q;
531 break;
532 }
533

Callers 2

setFormatFunction · 0.85
HSVtoHexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected