Color Palette Selection

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Mkalo
Prole
Posts: 11
Joined: Thu Dec 29, 2011 11:54 pm

Color Palette Selection

Post 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:
Image

Someone could help me?
Bomberman in LÖVE:
http://migre.me/7Beiu
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Color Palette Selection

Post 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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Color Palette Selection

Post by bartbes »

It's not that hard, if you make an image like that you can just use ImageData:getPixel.
Mkalo
Prole
Posts: 11
Joined: Thu Dec 29, 2011 11:54 pm

Re: Color Palette Selection

Post 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...
Bomberman in LÖVE:
http://migre.me/7Beiu
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Color Palette Selection

Post 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
Mkalo
Prole
Posts: 11
Joined: Thu Dec 29, 2011 11:54 pm

Re: Color Palette Selection

Post by Mkalo »

There is the result, thanks for all.
Attachments
Color Selection.love
(294.32 KiB) Downloaded 253 times
Bomberman in LÖVE:
http://migre.me/7Beiu
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests