What i'm trying to achieve is something fading from one color to another, And i actually have achieved this. But the problem is that the speed at which it fades between the two colors depends on how far apart the RGB values are, But i want it to fade at the same speed. So any idea how that can be done? Thanks in advance.
function love.load()
math.randomseed(os.time())
cur = {r = math.random(0, 255), g = math.random(0, 255), b = math.random(0, 255)}
des = {r = cur.r, g = cur.g, b = cur.b}
fades = 150
showhud = true
end
function love.update(dt)
if cur.r < des.r then
cur.r = cur.r + fades * dt
end
if cur.g < des.g then
cur.g = cur.g + fades * dt
end
if cur.b < des.b then
cur.b = cur.b + fades * dt
end
if cur.r > des.r then
cur.r = cur.r - fades * dt
end
if cur.g > des.g then
cur.g = cur.g - fades * dt
end
if cur.b > des.b then
cur.b = cur.b - fades * dt
end
end
function love.draw()
love.graphics.setBackgroundColor(cur.r, cur.g, cur.b)
if showhud then
love.graphics.print("Des: R: "..des.r.." G: "..des.g.." B: "..des.b, 10, 10)
love.graphics.print("Cur: R: "..math.floor(cur.r).." G: "..math.floor(cur.g).." B: "..math.floor(cur.b), 10, 25)
end
end
function love.keypressed(key)
if key == "n" then
des.r = math.random(0, 255)
des.g = math.random(0, 255)
des.b = math.random(0, 255)
elseif key == "f3" then
showhud = not showhud
end
end
You can also download the .love below if that's what you prefer.
Think about "steps" in the process of fading. You're already multiplying by "fades" (a speed variable?), so now you need to make that also account for a variable which basically describes how much change you do.
To use a real world analogy, imagine two men walking to two different point. One is point is further than the other. If we could alter the stride length of one of the men, we could make them arrive at their disparate destinations in the same number of steps.
Hence my word choice above. We need a "step" size that varies to accommodate for different distances between colors.
kikito wrote:You can also use tween.lua to do this in 3 lines. It will handle the transitions, multiple color components, and the like.
Disclaimer: I'm the programmer of tween.lua.
I don't like using libraries too much..i prefer doing things myself. (with some help from the forums in some cases..lol) I don't really know why..feels like cheating. lol
veethree wrote:I don't like using libraries too much..i prefer doing things myself. (with some help from the forums in some cases..lol) I don't really know why..feels like cheating. lol
Don't let that feeling hold you back. Using libraries means less bugs, which makes your games more stable, and means a higher degree of code reuse.
veethree wrote:I don't like using libraries too much..i prefer doing things myself. (with some help from the forums in some cases..lol) I don't really know why..feels like cheating. lol
Don't let that feeling hold you back. Using libraries means less bugs, which makes your games more stable, and means a higher degree of code reuse.
And they can allow you to do stuff you might otherwise need a science degree for, without first getting the degree.
If, like me, you're a very bad person who already knows they're going to a special hell where all the beer is warm and flat, and everybody knows your name but they all mispronounce it intentionally, you might even occasionally rewrite libs to do things your way .. but would you walk across the country because using a car is like cheating?
kikito wrote:You can also use tween.lua to do this in 3 lines. It will handle the transitions, multiple color components, and the like.
Disclaimer: I'm the programmer of tween.lua.
I don't like using libraries too much..i prefer doing things myself. (with some help from the forums in some cases..lol) I don't really know why..feels like cheating. lol
Apple say "There's an app for that!", Lovers usually answer "There's a lib for that!". And there's people like Kikito that have so many libs that can also say "and it's mine!".
There isn't nothing wrong about using libraries of course. However if you trying to do things for yourself I agree with you because it feels like cheating. Less effort is nice and is a lot less time wasted but also means less learning, less brain-development, more dependence. It's a question of want be more or less user than coder. So I cheer you up and say that you aren't alone in that pursuit of do things.
veethree wrote:I don't like using libraries too much..i prefer doing things myself. (with some help from the forums in some cases..lol) I don't really know why..feels like cheating. lol
Don't let that feeling hold you back. Using libraries means less bugs, which makes your games more stable, and means a higher degree of code reuse.
And they can allow you to do stuff you might otherwise need a science degree for, without first getting the degree.
If, like me, you're a very bad person who already knows they're going to a special hell where all the beer is warm and flat, and everybody knows your name but they all mispronounce it intentionally, you might even occasionally rewrite libs to do things your way .. but would you walk across the country because using a car is like cheating?
If i ever make a game that requires something that would require a science degree to write, Of course i'd use a lib. But for simple shit like this i'd just rather do it myself.
As for your car metaphor, The way i see it, If you walk, You get across the country all by yourself and you have all the bragging rights. But if your friend gives you a piggy back ride half the way, you still get there, but your friend did a lot of the work.
But i have nothing against libs and people who use them, I just like doing things myself.
People seem to set a lot of store by this "bragging rights".
My take is that - beyond gaining experience with the language - the only real benefit in writing your own lib is that you can optimize it for your own specific requirements.