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

Function getRgbBySection

Conversions/RgbHsvConversion.js:92–133  ·  view source on GitHub ↗
(
  hueSection,
  chroma,
  matchValue,
  secondLargestComponent
)

Source from the content-addressed store, hash-verified

90}
91
92function getRgbBySection(
93 hueSection,
94 chroma,
95 matchValue,
96 secondLargestComponent
97) {
98 function convertToInt(input) {
99 return Math.round(255 * input)
100 }
101
102 let red
103 let green
104 let blue
105
106 if (hueSection >= 0 && hueSection <= 1) {
107 red = convertToInt(chroma + matchValue)
108 green = convertToInt(secondLargestComponent + matchValue)
109 blue = convertToInt(matchValue)
110 } else if (hueSection > 1 && hueSection <= 2) {
111 red = convertToInt(secondLargestComponent + matchValue)
112 green = convertToInt(chroma + matchValue)
113 blue = convertToInt(matchValue)
114 } else if (hueSection > 2 && hueSection <= 3) {
115 red = convertToInt(matchValue)
116 green = convertToInt(chroma + matchValue)
117 blue = convertToInt(secondLargestComponent + matchValue)
118 } else if (hueSection > 3 && hueSection <= 4) {
119 red = convertToInt(matchValue)
120 green = convertToInt(secondLargestComponent + matchValue)
121 blue = convertToInt(chroma + matchValue)
122 } else if (hueSection > 4 && hueSection <= 5) {
123 red = convertToInt(secondLargestComponent + matchValue)
124 green = convertToInt(matchValue)
125 blue = convertToInt(chroma + matchValue)
126 } else {
127 red = convertToInt(chroma + matchValue)
128 green = convertToInt(matchValue)
129 blue = convertToInt(secondLargestComponent + matchValue)
130 }
131
132 return [red, green, blue]
133}

Callers 1

hsvToRgbFunction · 0.85

Calls 1

convertToIntFunction · 0.85

Tested by

no test coverage detected