Page 1 of 1
Color Palette Selection
Posted: Fri Jan 06, 2012 7:02 pm
by Mkalo
I'm needing a lib for color palette to select colors to make a paint in LÖVE but i can't make one by myself and didn't found it on google.
Something like that:
Someone could help me?
Re: Color Palette Selection
Posted: Fri Jan 06, 2012 7:20 pm
by MarekkPie
If you're actually trying to implement a selectable color palette like the right side of the top picture, or the color wheel within your .love game, then that's a big project. If you are just needing to have a few preset selections, then you could probably make a few simply rectangles that trigger a base color change upon selection. Implement a simple class that has a rectangle and a setColor() function that would be called if you love.mousepressed() on it:
Simple color swatch
Code: Select all
colorSwatches = {} -- Load in your color swatches
function newColorSwatch(x,y,w,h,rgba)
local a = {}
a.x = x
a.y = y
a.w = w
a.h = h
a.color = rgba
a.trigger = function()
love.graphics.setColor(a.color)
end
return a
end
The selection processes:
Code: Select all
local function contains2D(x, y, rect)
if rect.x < x and x < rect.x + rect.w then
if rect.y < y and y < rect.y + rect.h then
return true
end
end
return false
end
function love.mousepressed(x, y, b)
if b == "l" then
for _,v in pairs(colorSwatches) do
if contains2D(x, y, v) then
v.trigger()
end
end
end
end
Re: Color Palette Selection
Posted: Fri Jan 06, 2012 7:23 pm
by bartbes
It's not that hard, if you make an image like that you can just use ImageData:getPixel.
Re: Color Palette Selection
Posted: Fri Jan 06, 2012 7:33 pm
by Mkalo
Bartbes can you tell me more about this ImageData:getPixel? I didn't found this function on wiki Oo '-'
Forget '-' kkkk i found it thanks, I will try it...
Re: Color Palette Selection
Posted: Fri Jan 06, 2012 7:38 pm
by thelinx
Very simple example:
Code: Select all
palette = love.image.newImageData("palette.png")
paletteImg = love.graphics.newImage(palette)
function love.mousepressed(x, y)
r, g, b, a = palette:getPixel(x, y)
end
See:
love.image.newImageData,
ImageData:getPixel
Re: Color Palette Selection
Posted: Sat Jan 07, 2012 9:46 pm
by Mkalo
There is the result, thanks for all.