From f7afcdd5a924b5a38efa4857210ca295f3fc2b1b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 25 Apr 2021 16:27:20 +0200 Subject: [PATCH] feat: add a way to set color from hsv --- sonic-radiance.love/core/utils/graphics.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sonic-radiance.love/core/utils/graphics.lua b/sonic-radiance.love/core/utils/graphics.lua index 516edea..826b5e3 100644 --- a/sonic-radiance.love/core/utils/graphics.lua +++ b/sonic-radiance.love/core/utils/graphics.lua @@ -27,6 +27,22 @@ local Graphics = {} -- COLOR FUNCTIONS -- Handle colors and scene colors +function Graphics.setColorHSV(h, s, v) + if s <= 0 then return v,v,v end + h, s, v = h*6, s, v + local c = v*s + local x = (1-math.abs((h%2)-1))*c + local m,r,g,b = (v-c), 0,0,0 + if h < 1 then r,g,b = c,x,0 + elseif h < 2 then r,g,b = x,c,0 + elseif h < 3 then r,g,b = 0,c,x + elseif h < 4 then r,g,b = 0,x,c + elseif h < 5 then r,g,b = x,0,c + else r,g,b = c,0,x + end + love.graphics.setColor((r+m),(g+m),(b+m),1) +end + function Graphics.resetColor() love.graphics.setColor(1,1,1,1) end