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?
Color Palette Selection
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Color Palette Selection
Bomberman in LÖVE:
http://migre.me/7Beiu
http://migre.me/7Beiu
Re: Color Palette Selection
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
The selection processes:
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
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
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Color Palette Selection
It's not that hard, if you make an image like that you can just use ImageData:getPixel.
Re: Color Palette Selection
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...
Forget '-' kkkk i found it thanks, I will try it...
Bomberman in LÖVE:
http://migre.me/7Beiu
http://migre.me/7Beiu
Re: Color Palette Selection
Very simple example:
See: love.image.newImageData, ImageData:getPixel
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
Re: Color Palette Selection
There is the result, thanks for all.
- Attachments
-
- Color Selection.love
- (294.32 KiB) Downloaded 263 times
Bomberman in LÖVE:
http://migre.me/7Beiu
http://migre.me/7Beiu
Who is online
Users browsing this forum: Bing [Bot] and 1 guest