Posted 13 July 2017 - 03:42 PM
Hello. I am making a program where I want the background to smoothly fade beetwen two diffrent colours.
My code so far:
Please tell me where did I make a mistake. Any help will be appreciated.
My code so far:
local blue = {0x33,0x66,0xF2}
local lblue = {0x99,0xB2,0xFF}
local steps = 256
local s1 = (lblue[1] - blue[1])/128
local s2 = (lblue[2] - blue[2])/128
local s3 = (lblue[3] - blue[3])/128
print(s1)
print(s2)
print(s3)
local current = lblue
term.setBackgroundColor(colors.blue)
term.clear()
while true do
for i=1,steps do
current[1] = current[1] - s1
current[2] = current[2] - s2
current[3] = current[3] - s3
sleep(0.05)
term.setPaletteColor(colors.blue,colors.rgb8(current[1]/255,current[2]/255,current[3]/255))
end
print("y")
for i=1,steps do
current[1] = current[1] + s1
current[2] = current[2] + s2
current[3] = current[3] + s3
sleep(0.05)
term.setPaletteColor(colors.blue,colors.rgb8(current[1]/255,current[2]/255,current[3]/255))
end
print("h")
os.queueEvent("_") os.pullEvent()
end
but it fails when decreasing the amount of steps. Also it randomly changes to magenta.Please tell me where did I make a mistake. Any help will be appreciated.