MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / hsvToRgb

Function hsvToRgb

Conversions/RgbHsvConversion.js:19–38  ·  view source on GitHub ↗
(hue, saturation, value)

Source from the content-addressed store, hash-verified

17 * @return The tuple of RGB-components.
18 */
19export function hsvToRgb(hue, saturation, value) {
20 if (hue < 0 || hue > 360) {
21 throw new Error('hue should be between 0 and 360')
22 }
23
24 if (saturation < 0 || saturation > 1) {
25 throw new Error('saturation should be between 0 and 1')
26 }
27
28 if (value < 0 || value > 1) {
29 throw new Error('value should be between 0 and 1')
30 }
31
32 const chroma = value * saturation
33 const hueSection = hue / 60
34 const secondLargestComponent = chroma * (1 - Math.abs((hueSection % 2) - 1))
35 const matchValue = value - chroma
36
37 return getRgbBySection(hueSection, chroma, matchValue, secondLargestComponent)
38}
39
40/**
41 * Conversion from the RGB-representation to the HSV-representation.

Callers 1

Calls 1

getRgbBySectionFunction · 0.85

Tested by

no test coverage detected