Posted 02 September 2017 - 07:37 PM
Is there anyway to make something fade into another program instead of just clear?
Not easily… it could be done in the latest beta (1.80)* but there are some special cases you would have to consider. Clearing is definitely the way to go.
You obviously couldn't start fading until the program's drawn stuff, but how do you know that? The program would have to signal the fade effect somehow. Also, what do you do in the case of the program drawing on the same pixel multiple times? What if the program has on-screen movement? How does that fading work? What about controls? Is the program going to recieve events during the fade? etc.
*Similar to this effect.
local fadeTime = 1 --# Time to spend fading, in seconds.
--# Record current palette:
local pal = {}
for i = 0, 15 do pal[2^i] = {term.getPaletteColour(2^i)} end
fadeTime = fadeTime * 20 - 0.05
--# Fade to black:
for i = 0, fadeTime do
local thisCol = 1
for j = 0, 15 do
local r, g, b = pal[thisCol][1], pal[thisCol][2], pal[thisCol][3]
term.setPaletteColour(thisCol, r - (r / fadeTime * i), g - (g / fadeTime * i), b - (b / fadeTime * i))
thisCol = thisCol * 2
end
sleep(0.05)
end
term.clear()
--# Draw something new here, if you like.
--# Restore original palette here. Either fade back the other way (repeat the above
--# with "for i = fadeTime, 0, -1 do"), or just snap straight to it with:
for i = 0, 15 do term.setPaletteColour(2^i, table.unpack(pal[2^i])) end
To be honest I'm still doing "If Statements" and using them for most of the OS Im making. I did end up learning to code buttons. Which was somewhat complicated for me. But thanks for showing me this, I'll for sure use this :3A direct fade into another script is a bit tricky, but fading the old screen-content to black / white is trivial. You could then additionally draw your script's new content before fading back to a regular palette.Spoiler
local fadeTime = 1 --# Time to spend fading, in seconds. --# Record current palette: local pal = {} for i = 0, 15 do pal[2^i] = {term.getPaletteColour(2^i)} end fadeTime = fadeTime * 20 - 0.05 --# Fade to black: for i = 0, fadeTime do local thisCol = 1 for j = 0, 15 do local r, g, b = pal[thisCol][1], pal[thisCol][2], pal[thisCol][3] term.setPaletteColour(thisCol, r - (r / fadeTime * i), g - (g / fadeTime * i), b - (b / fadeTime * i)) thisCol = thisCol * 2 end sleep(0.05) end term.clear() --# Draw something new here, if you like. --# Restore original palette here. Either fade back the other way (repeat the above --# with "for i = fadeTime, 0, -1 do"), or just snap straight to it with: for i = 0, 15 do term.setPaletteColour(2^i, table.unpack(pal[2^i])) end
local originalPal = {}
for i = 0, 15 do originalPal[2^i] = {term.getPaletteColour(2^i)} end
local function fadeToBlack()
local fadeTime = 1 --# Time to spend fading, in seconds.
--# Record current palette:
local pal = {}
for i = 0, 15 do pal[2^i] = {term.getPaletteColour(2^i)} end
fadeTime = fadeTime * 20 - 0.05
--# Fade to black:
for i = 0, fadeTime do
local thisCol = 1
for j = 0, 15 do
local r, g, b = pal[thisCol][1], pal[thisCol][2], pal[thisCol][3]
term.setPaletteColour(thisCol, r - (r / fadeTime * i), g - (g / fadeTime * i), b - (b / fadeTime * i))
thisCol = thisCol * 2
end
sleep(0.05)
end
term.setBackgroundColor( colors.black )
term.clear()
end
local function resetPalette()
--reset palette
for i = 0, 15 do term.setPaletteColour(2^i, table.unpack(originalPal[2^i])) end
end
local function fadeInCursor()
local fadeTime = 20 - 0.05
term.setPaletteColour( colors.yellow, 0, 0, 0 )
local r, g, b = table.unpack( originalPal[ colors.yellow ] )
for i = 0, fadeTime do
term.setPaletteColour( colors.yellow, r / fadeTime * i, g / fadeTime * i, g / fadeTime * i )
sleep( 0.05 )
end
end
term.clear()
term.setCursorPos( 1, 1 )
term.setTextColor( colors.yellow )
term.write( "> " )
term.setTextColor( colors.white )
term.setCursorBlink( true )
while true do
local s_input = read()
local time = os.clock()
shell.run( s_input )
local do_fade = os.clock() - time > 1
if do_fade then
fadeToBlack()
term.setCursorPos( 1, 1 )
end
term.setTextColor( colors.yellow )
term.write( "> " )
term.setTextColor( colors.white )
if do_fade then
fadeInCursor()
resetPalette()
end
term.setCursorBlink( true )
end