Hi folks,
This is my first post and i need some help for a simulator i'm trying to do. The problem is that i'm trying to simulate a hue potentiometer
(like on old TV's). The closest thing i have found is a random color background that changes randomly in the Pop game by VeeThree.
I don't want the colors at random, just something simple as like if i press "1", the hue goes from 0 to 360 (potentiometer clockwise)
and press "2", hue goes from 360 to 0 (potentiometer counterclockwise).
Can someone help me before i go bald and insane ?!
changing hue
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
changing hue
--- Sly DC ---
Re: changing hue
You could try tinting the screen with a transparent color...
Won't work well, however.
For images, you can use love.graphics.setColor to set a tint for them, or RGB 255,255,255 to reset it back to normal.
Won't work well, however.
For images, you can use love.graphics.setColor to set a tint for them, or RGB 255,255,255 to reset it back to normal.
- SimonLarsen
- Party member
- Posts: 100
- Joined: Thu Mar 31, 2011 4:47 pm
- Location: Denmark
- Contact:
Re: changing hue
I'm not sure what you want to do, but you can use the HSL function on the wiki.
Here's quick demo for you:
Here's quick demo for you:
Code: Select all
function HSL(h, s, l, a)
if s<=0 then return l,l,l,a end
h, s, l = h/256*6, s/255, l/255
local c = (1-math.abs(2*l-1))*s
local x = (1-math.abs(h%2-1))*c
local m,r,g,b = (l-.5*c), 0,0,0
if h < 1 then r,g,b = c,x,0
elseif h < 2 then r,g,b = x,c,0
elseif h < 3 then r,g,b = 0,c,x
elseif h < 4 then r,g,b = 0,x,c
elseif h < 5 then r,g,b = x,0,c
else r,g,b = c,0,x
end return (r+m)*255,(g+m)*255,(b+m)*255,a
end
function love.load()
hue = 0
direction = 1 -- increasing hue
end
function love.update(dt)
hue = hue + 32*dt*direction
if hue > 255 then hue = 0
elseif hue < 0 then hue = 255 end
end
function love.draw()
love.graphics.setColor(HSL(hue,255,128))
love.graphics.rectangle("fill",0,0,800,600)
love.graphics.setColor(255,255,255,255)
love.graphics.print("Hue: "..hue, 16,16)
love.graphics.print(direction == 1 and "increasing" or "decreasing",16,32)
end
function love.keypressed(k,uni)
if k == "1" then
direction = 1
elseif k == "2" then
direction = -1
end
end
Re: changing hue
Thank you so much SimonLarsen! This is what i was looking for!
But your code increases or decreases the hue automatically, so i sightly modified it to change the hue manually like this:
So thanks to you, i won't go bald & insane...LOL!!!
But your code increases or decreases the hue automatically, so i sightly modified it to change the hue manually like this:
Code: Select all
function HSL(h, s, l, a)
if s<=0 then return l,l,l,a end
h, s, l = h/256*6, s/255, l/255
local c = (1-math.abs(2*l-1))*s
local x = (1-math.abs(h%2-1))*c
local m,r,g,b = (l-.5*c), 0,0,0
if h < 1 then r,g,b = c,x,0
elseif h < 2 then r,g,b = x,c,0
elseif h < 3 then r,g,b = 0,c,x
elseif h < 4 then r,g,b = 0,x,c
elseif h < 5 then r,g,b = x,0,c
else r,g,b = c,0,x
end return (r+m)*255,(g+m)*255,(b+m)*255,a
end
function love.load()
hue = 0
end
function love.update(dt)
if hue > 255 then hue = 0
elseif hue < 0 then hue = 255 end
if love.keyboard.isDown('1') then hue = hue +10*dt end
if love.keyboard.isDown('2') then hue = hue -10*dt end
end
function love.draw()
love.graphics.setColor(HSL(hue,255,128))
love.graphics.rectangle("fill",0,0,800,600)
love.graphics.setColor(255,255,255,255)
love.graphics.print("Hue: "..hue, 16,16)
end
--- Sly DC ---
Who is online
Users browsing this forum: Google [Bot] and 6 guests