hsluv/hsl(a) functions: wrap around hue

This commit is contained in:
miruka
2019-08-21 12:32:14 -04:00
parent 1886303481
commit 7624ce5fcb
2 changed files with 12 additions and 4 deletions

View File

@@ -1,4 +1,10 @@
function numberWrapAround(num, max) {
return num < 0 ? max + (num % max) : (num % max)
}
function hsluv(hue, saturation, lightness, alpha=1.0) {
hue = numberWrapAround(hue, 360)
let rgb = py.callSync("hsluv", [hue, saturation, lightness])
return Qt.rgba(rgb[0], rgb[1], rgb[2], alpha)
}
@@ -11,6 +17,7 @@ function hsl(hue, saturation, lightness) {
function hsla(hue, saturation, lightness, alpha=1.0) {
// Convert standard hsla(0-360, 1-100, 1-100, 0-1) to Qt format
hue = numberWrapAround(hue, 360)
return Qt.hsla(hue / 360, saturation / 100, lightness / 100, alpha)
}