-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcolorFade.lua
60 lines (49 loc) · 1.46 KB
/
colorFade.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
local color = {}
local current = {}
current.fg = {}
current.bg = {}
local target = {}
target.fg = {}
target.bg = {}
local speed = {}
speed.fg = {}
speed.bg = {}
color.setColor = function(fg, bg)
current.fg = {unpack(fg)}
current.bg = {unpack(bg)}
target.fg = {unpack(fg)}
target.bg = {unpack(bg)}
speed.fg = {0, 0, 0}
speed.bg = {0, 0, 0}
end
color.setTarget = function(fg, bg)
target.fg = {unpack(fg)}
target.bg = {unpack(bg)}
speed.fg = {target.fg[1] - current.fg[1], target.fg[2] - current.fg[2], target.fg[3] - current.fg[3]}
speed.bg = {target.bg[1] - current.bg[1], target.bg[2] - current.bg[2], target.bg[3] - current.bg[3]}
end
color.update = function(dt)
for i = 1, 3 do
local new_fg = current.fg[i] + speed.fg[i] * dt
if new_fg <= target.fg[i] and current.fg[i] >= target.fg[i] or
new_fg >= target.fg[i] and current.fg[i] <= target.fg[i] then
new_fg = target.fg[i]
end
current.fg[i] = new_fg
local new_bg = current.bg[i] + speed.bg[i] * dt
if new_bg <= target.bg[i] and current.bg[i] >= target.bg[i] or
new_bg >= target.bg[i] and current.bg[i] <= target.bg[i] then
new_bg = target.bg[i]
end
current.bg[i] = new_bg
end
love.graphics.setColor(current.fg)
love.graphics.setBackgroundColor(current.bg)
end
color.bg = function()
return current.bg
end
color.fg = function()
return current.fg
end
return color