| 235 | |
| 236 | //https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB |
| 237 | const getHSL = (red, green, blue) => { |
| 238 | red /= 255; |
| 239 | green /= 255; |
| 240 | blue /= 255; |
| 241 | |
| 242 | const max = Math.max(red, green, blue); |
| 243 | const min = Math.min(red, green, blue); |
| 244 | const chroma = max - min; |
| 245 | |
| 246 | let lightness = (max + min) / 2; |
| 247 | let saturation = 0; |
| 248 | if (lightness !== 0 && lightness !== 1) { |
| 249 | saturation = (max - lightness) / Math.min(lightness, 1 - lightness); |
| 250 | } |
| 251 | |
| 252 | let hue = 0; |
| 253 | if (max === red) hue = (green - blue) / chroma; |
| 254 | if (max === green) hue = 2 + (blue - red) / chroma; |
| 255 | if (max === blue) hue = 4 + (red - green) / chroma; |
| 256 | if (chroma === 0) hue = 0; |
| 257 | |
| 258 | lightness *= 100; |
| 259 | saturation *= 100; |
| 260 | hue *= 60; |
| 261 | while (hue < 0) hue += 360; |
| 262 | |
| 263 | return [hue, saturation, lightness]; |
| 264 | }; |
| 265 | |
| 266 | Habitat.Colour.add = ( |
| 267 | colour, |