This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local function rgb2hsl(r, g, b) | |
| local max, min = math.max(r, g, b), math.min(r, g, b) | |
| local h, s, l = (max + min) / 2, (max + min) / 2, (max + min) / 2 | |
| if max == min then | |
| h, s = 0, 0 -- achromatic | |
| else | |
| local d = max - min | |
| local s = nil | |
| if l > 0.5 then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local function hsl2rgb(h, s, l) | |
| local r, g, b = nil, nil, nil | |
| if s == 0 then | |
| r, g, b = l, l ,l -- achromatic | |
| else | |
| local hue2rgb = function(p, q, t) | |
| if t < 0 then | |
| t = t + 1 | |
| end |