Posted 11 July 2014 - 08:27 AM
hello all, I was just wondering how to create animations such as the shutdown animation in OneOS and buffers for gui's.
function AnimateShutdown(restart)
if not Settings:GetValues()['UseAnimations'] then
return
end
Drawing.Clear(colours.white)
Drawing.DrawBuffer()
sleep(0)
local x = 0
local y = 0
local w = 0
local h = 0
for i = 1, 8 do
local percent = (i * 0.05)
Drawing.Clear(colours.black)
x = Drawing.Screen.Width * (i * 0.01)
y = math.floor(Drawing.Screen.Height * (i * 0.05)) + 3
w = Drawing.Screen.Width - (2 * x) + 1
h = Drawing.Screen.Height - (2 * y) + 1
if h < 1 then
h = 1
end
Drawing.DrawBlankArea(x + 1, y, w, h, colours.white)
Drawing.DrawBuffer()
sleep(0)
end
Drawing.DrawBlankArea(x + 1, y, w, h, colours.lightGrey)
Drawing.DrawBuffer()
sleep(0)
Drawing.DrawBlankArea(x + 1, y, w, h, colours.grey)
Drawing.DrawBuffer()
sleep(0)
term.setBackgroundColour(colours.black)
term.clear()
if restart then
sleep(0.2)
os.reboot()
else
os.shutdown()
end
end
DrawBuffer = function()
for y,row in pairs(Drawing.Buffer) do
for x,pixel in pairs(row) do
local shouldDraw = true
local hasBackBuffer = true
if Drawing.BackBuffer[y] == nil or Drawing.BackBuffer[y][x] == nil or #Drawing.BackBuffer[y][x] ~= 3 then
hasBackBuffer = false
end
if hasBackBuffer and Drawing.BackBuffer[y][x][1] == Drawing.Buffer[y][x][1] and Drawing.BackBuffer[y][x][2] == Drawing.Buffer[y][x][2] and Drawing.BackBuffer[y][x][3] == Drawing.Buffer[y][x][3] then
shouldDraw = false
end
if shouldDraw then
term.setBackgroundColour(pixel[3])
term.setTextColour(pixel[2])
term.setCursorPos(x, y)
term.write(pixel[1])
end
end
end
Drawing.BackBuffer = Drawing.Buffer
Drawing.Buffer = {}
end