Finished color library

This commit is contained in:
Ryan Ward 2022-02-11 14:51:31 -05:00
parent bbc5d3e586
commit 0da8204d28
2 changed files with 52 additions and 36 deletions

View File

@ -12,6 +12,7 @@ local function HSL(h, s, l, a)
else r,b,g = c,0,x else r,b,g = c,0,x
end return (r+m)*255,(g+m)*255,(b+m)*255,a end return (r+m)*255,(g+m)*255,(b+m)*255,a
end end
local color={}
local mt = { local mt = {
__add = function (c1,c2) __add = function (c1,c2)
return color.new(c1[1]+c2[1],c1[2]+c2[2],c1[2]+c2[2]) return color.new(c1[1]+c2[1],c1[2]+c2[2],c1[2]+c2[2])
@ -37,49 +38,54 @@ local mt = {
__tostring = function(c) __tostring = function(c)
return "("..c[1]..","..c[2]..","..c[3]..")" return "("..c[1]..","..c[2]..","..c[3]..")"
end, end,
__eq = color.EQ, __eq = function (c1,c2)
__lt = color.LT,
__le = color.LE,
}
local color={
new=function(r,b,g)
local temp = {r/255,b/255,g/255,1}
setmetatable(temp, mt)
return temp
end,
Random=function()
return color.new(math.random(0,255),math.random(0,255),math.random(0,255))
end,
EQ = function (c1,c2)
return (c1[1]==c2[1] and c1[2]==c2[2] and c1[2]==c2[2]) return (c1[1]==c2[1] and c1[2]==c2[2] and c1[2]==c2[2])
end, end,
LT = function (c1,c2) __lt = function (c1,c2)
return (c1[1]<c2[1] and c1[2]<c2[2] and c1[2]<c2[2]) return (c1[1]<c2[1] and c1[2]<c2[2] and c1[2]<c2[2])
end, end,
LE = function (c1,c2) __le = function (c1,c2)
return (c1[1]<=c2[1] and c1[2]<=c2[2] and c1[2]<=c2[2]) return (c1[1]<=c2[1] and c1[2]<=c2[2] and c1[2]<=c2[2])
end, end
indexColor=function(name,r,b,g) }
function color.new(r, b, g, fmt)
local temp
if fmt then
temp = {r,b,g}
else
temp = {love.math.colorFromBytes(r, b, g)}
end
setmetatable(temp, mt)
return temp
end
function color.random()
return color.new(math.random(0,10000)/10000, math.random(0,10000)/10000, math.random(0,10000)/10000, true)
end
function color.indexColor(name,r,b,g)
if type(r)=="string" then if type(r)=="string" then
r,b,g=tonumber(string.sub(r,1,2),16),tonumber(string.sub(r,3,4),16),tonumber(string.sub(r,5,6),16) r,b,g=tonumber(string.sub(r,1,2),16),tonumber(string.sub(r,3,4),16),tonumber(string.sub(r,5,6),16)
end end
-- Other ways to index a color
color[string.lower(name)]=color.new(r,b,g) color[string.lower(name)]=color.new(r,b,g)
color[string.upper(name)]=color.new(r,b,g) color[string.upper(name)]=color[string.lower(name)] -- These should link to the original and not be cloned
color[string.upper(string.sub(name,1,1))..string.lower(string.sub(name,2))]=color.new(r,b,g) color[string.upper(string.sub(name,1,1))..string.lower(string.sub(name,2))]=color[string.lower(name)]
end, end
Darken=function(color,v)
currentR=color[1] function color.darken(c, v)
currentG=color[2] local currentR,currentG,currentB=c[1],c[2],c[3]
currentB=color[3]
return color.new((currentR*255) * (1 - v),(currentG*255) * (1 - v),(currentB*255) * (1 - v)) return color.new((currentR*255) * (1 - v),(currentG*255) * (1 - v),(currentB*255) * (1 - v))
end, end
Lighten=function(color,v)
currentR=color[1] function color.lighten(c, v)
currentG=color[2] local currentR,currentG,currentB=c[1],c[2],c[3]
currentB=color[3]
return color.new(currentR*255 + (255 - (currentR*255)) * v,currentG*255 + (255 - (currentG*255)) * v,currentB*255 + (255 - (currentB*255)) * v) return color.new(currentR*255 + (255 - (currentR*255)) * v,currentG*255 + (255 - (currentG*255)) * v,currentB*255 + (255 - (currentB*255)) * v)
end end
}
-- Add a ton of colors sourced from online
color.indexColor("WHITE",255,255,255) color.indexColor("WHITE",255,255,255)
color.indexColor("MAROON",128,20,20) color.indexColor("MAROON",128,20,20)
color.indexColor("DARK_RED",139,20,20) color.indexColor("DARK_RED",139,20,20)
@ -181,7 +187,7 @@ color.indexColor("LEMON_CHIFFON",255,250,205)
color.indexColor("LIGHT_GOLDEN_ROD_YELLOW",250,250,210) color.indexColor("LIGHT_GOLDEN_ROD_YELLOW",250,250,210)
color.indexColor("LIGHT_YELLOW",255,255,224) color.indexColor("LIGHT_YELLOW",255,255,224)
color.indexColor("SADDLE_BROWN",139,69,19) color.indexColor("SADDLE_BROWN",139,69,19)
color.indexColor("SEXY_PURPLE",85,85,127) color.indexColor("CALM_PURPLE",85,85,127)
color.indexColor("SIENNA",160,82,45) color.indexColor("SIENNA",160,82,45)
color.indexColor("CHOCOLATE",210,105,30) color.indexColor("CHOCOLATE",210,105,30)
color.indexColor("PERU",205,133,63) color.indexColor("PERU",205,133,63)
@ -1674,7 +1680,7 @@ color.indexColor("dust","b2996e")
color.indexColor("dark_pastel_green","56ae57") color.indexColor("dark_pastel_green","56ae57")
color.indexColor("cloudy_blue","acc2d9") color.indexColor("cloudy_blue","acc2d9")
for i=0,255 do for i=0,255 do
color.indexColor("Gray"..i,i,i,i) color.indexColor("gray"..i,i,i,i)
end end
return color return color

View File

@ -11,9 +11,11 @@ gui.MOUSE_SECONDARY = 2
gui.MOUSE_MIDDLE = 3 gui.MOUSE_MIDDLE = 3
local frame, label, image, text, button, box, video = 0, 1, 2, 4, 8, 16, 32 local frame, label, image, text, button, box, video = 0, 1, 2, 4, 8, 16, 32
function gui:getChildren() function gui:getChildren()
return self.Children return self.Children
end end
function gui:getAllChildren() function gui:getAllChildren()
local Stuff = {} local Stuff = {}
function Seek(Items) function Seek(Items)
@ -57,6 +59,7 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
table.insert(self.Children,c) table.insert(self.Children,c)
return c return c
end end
function gui:newDualDim(x, y, w, h, sx, sy, sw, sh) function gui:newDualDim(x, y, w, h, sx, sy, sw, sh)
local dd = {} local dd = {}
dd.offset={} dd.offset={}
@ -79,13 +82,14 @@ function gui:newDualDim(x, y, w, h, sx, sy, sw, sh)
} }
return dd return dd
end end
-- Objects
-- Frames -- Frames
function gui:newFrame(x, y, w, h, sx, sy, sw, sh) function gui:newFrame(x, y, w, h, sx, sy, sw, sh)
local c = self:newBase(frame, x, y, w, h, sx, sy, sw, sh) local c = self:newBase(frame, x, y, w, h, sx, sy, sw, sh)
return c return c
end end
-- Texts -- Texts
function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh) function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
local c = self:newBase(text + typ,x, y, w, h, sx, sy, sw, sh) local c = self:newBase(text + typ,x, y, w, h, sx, sy, sw, sh)
@ -93,32 +97,38 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
return c return c
end end
function gui:newTextButton(txt, x, y, w, h, sx, sy, sw, sh) function gui:newTextButton(txt, x, y, w, h, sx, sy, sw, sh)
local c = self:newTextBase(button, txt, x, y, w, h, sx, sy, sw, sh) local c = self:newTextBase(button, txt, x, y, w, h, sx, sy, sw, sh)
return c return c
end end
function gui:newTextLabel(txt, x, y, w, h, sx, sy, sw, sh) function gui:newTextLabel(txt, x, y, w, h, sx, sy, sw, sh)
local c = self:newTextBase(label, txt, x, y, w, h, sx, sy, sw, sh) local c = self:newTextBase(label, txt, x, y, w, h, sx, sy, sw, sh)
return c return c
end end
function gui:newTextBox(txt, x, y, w, h, sx, sy, sw, sh) function gui:newTextBox(txt, x, y, w, h, sx, sy, sw, sh)
local c = self:newTextBase(box, txt, x, y, w, h, sx, sy, sw, sh) local c = self:newTextBase(box, txt, x, y, w, h, sx, sy, sw, sh)
return c return c
end end
-- Images -- Images
function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh) function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh)
local c = self:newBase(image + typ,x, y, w, h, sx, sy, sw, sh) local c = self:newBase(image + typ,x, y, w, h, sx, sy, sw, sh)
return c return c
end end
function gui:newImageLabel(x, y, w, h, sx, sy, sw, sh) function gui:newImageLabel(x, y, w, h, sx, sy, sw, sh)
local c = self:newImageBase(label, x, y, w, h, sx, sy, sw, sh) local c = self:newImageBase(label, x, y, w, h, sx, sy, sw, sh)
return c return c
end end
function gui:newImageButton(x, y, w, h, sx, sy, sw, sh) function gui:newImageButton(x, y, w, h, sx, sy, sw, sh)
local c = self:newImageBase(button, x, y, w, h, sx, sy, sw, sh) local c = self:newImageBase(button, x, y, w, h, sx, sy, sw, sh)