LOVE2D - Simple ColorPicker

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
darkmetalic
Prole
Posts: 17
Joined: Tue Feb 07, 2017 4:09 pm
Contact:

LOVE2D - Simple ColorPicker

Post by darkmetalic »

Hello guys, I make a demo available to anyone who needs something like this simple color picker. It simulates touching (with a mouse or no).

Code: Select all

selectedcolor,bordercolor={0,0,0},{50,50,50}
x,y,c_x,c_y=0,0,0,0
radius=25

set=love.graphics.setColor
prints=love.graphics.print
rec=love.graphics.rectangle
cir=love.graphics.circle

function love.load()
palletd=love.image.newImageData("pallet.png") --pallet 300px
palletw,palleth=palletd:getDimensions()
pallet=love.graphics.newImage(palletd)
prevx=palletw+50
end

function love.update(dt)
	if love.mouse.isDown(1) then
	istouch=true
	else
	istouch=nil
	end
end

function love.keyreleased(key)
   if key == "escape" then
      love.event.quit()
   end
end

function love.touchpressed( id, x, y, dx, dy, pressure )
istouch=true
end

function love.touchmoved( id, x, y, dx, dy, pressure )
istouch=true
end

function love.touchreleased( id, x, y, dx, dy, pressure )
istouch=nil
end

function rgbtohex(selected)
local hex={}
for i, color in ipairs(selected) do
color=string.format("%X", color*256) --hexadecimal format or "x = lowercase"
hex[i]=string.format("%02s",string.sub(color,1,2)) --min 00 strings
end
return table.concat(hex)
end

function love.draw()
x, y = love.mouse.getPosition()

--[[touches = love.touch.getTouches()
for i, id in ipairs(touches) do
x, y = love.touch.getPosition(id)
end]]

if (x>0 and x<palletw) and (y>0 and y<palleth) and istouch then
c_x,c_y=x,y
r,g,b=palletd:getPixel(x,y)
selectedcolor={r,g,b}
end

set(selectedcolor) rec("fill", prevx, 10, 100, 100)
set(bordercolor) rec("line", prevx, 10, 100, 100)

set(255,255,255,255) love.graphics.draw(pallet)
set(bordercolor) rec("line", 0, 0, palletw, palleth)
cir("line", c_x, c_y, radius, 100)

set(255,0,0,200) prints("Red "..selectedcolor[1], prevx,120)
set(0,255,0,200) prints("Green "..selectedcolor[2], prevx,150)
set(0,0,255,200) prints("Blue "..selectedcolor[3], prevx,180)

set(200,200,200)
prints("HEX #"..rgbtohex(selectedcolor), prevx,250)
prints("RGB ("..table.concat(selectedcolor,",")..")", prevx,280)
end
Attachments
AdvancedColorPicker.love
new
(44.81 KiB) Downloaded 407 times
SimpleColorPicker.zip
(43.26 KiB) Downloaded 234 times
SimpleColorPicker.love
(43.26 KiB) Downloaded 317 times
Last edited by darkmetalic on Fri Apr 07, 2017 12:30 pm, edited 1 time in total.
User avatar
D0NM
Party member
Posts: 250
Joined: Mon Feb 08, 2016 10:35 am
Location: Zabuyaki
Contact:

Re: LOVE2D - Simple ColorPicker

Post by D0NM »

Cool.
It would be cooler if the tool uses LOVE2D's clipboard functions
and export the picked colours right in the LOVE2D format ^_-
Our LÖVE Gamedev blog Zabuyaki (an open source retro beat 'em up game). Twitter: @Zabuyaki.
:joker: LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua :joker:
User avatar
darkmetalic
Prole
Posts: 17
Joined: Tue Feb 07, 2017 4:09 pm
Contact:

Re: LOVE2D - Simple ColorPicker

Post by darkmetalic »

D0NM wrote: Tue Feb 21, 2017 10:46 am Cool.
It would be cooler if the tool uses LOVE2D's clipboard functions
and export the picked colours right in the LOVE2D format ^_-
great idea^^
User avatar
darkmetalic
Prole
Posts: 17
Joined: Tue Feb 07, 2017 4:09 pm
Contact:

Re: LOVE2D - Simple ColorPicker

Post by darkmetalic »

I added an new advanced ColorPicker with your idea
User avatar
D0NM
Party member
Posts: 250
Joined: Mon Feb 08, 2016 10:35 am
Location: Zabuyaki
Contact:

Re: LOVE2D - Simple ColorPicker

Post by D0NM »

darkmetalic wrote: Fri Apr 07, 2017 12:34 pm I added an new advanced ColorPicker with your idea
Way to go!!! :awesome:
Our LÖVE Gamedev blog Zabuyaki (an open source retro beat 'em up game). Twitter: @Zabuyaki.
:joker: LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua :joker:
asommer
Prole
Posts: 2
Joined: Sun Jul 29, 2018 3:56 pm

Re: LOVE2D - Simple ColorPicker

Post by asommer »

Great utility, thanks for creating that.
Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests