Advertisement
Imgoodisher

animate

Jun 15th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 0 0
  1. local w, h = term.getSize()
  2.  
  3. local function cprint(str, nocenterheight)
  4.     local _w, _h = term.getCursorPos()
  5.     local xpos = math.floor(w/2 - str:len()/2)
  6.     local ypos = (not nocenterheight and math.floor(h/2)) or _h
  7.     term.setCursorPos(xpos, ypos)
  8.     term.write(str)
  9. end
  10.  
  11. local animations = {
  12.     function (str) -- flash
  13.         for i = 1, 5 do
  14.             cprint(str)
  15.             sleep(0.5)
  16.             term.clear()
  17.             sleep(0.5)
  18.         end
  19.     end,
  20.     function(str) -- marquee
  21.         for i = w+1, -str:len() - 1, -1 do
  22.             term.clear()
  23.             term.setCursorPos(i, math.floor(h/2))
  24.             term.write(str)
  25.             sleep(0.1)
  26.         end
  27.     end,
  28.     function(str) -- random fill
  29.         local screen = {}
  30.         local clear = false
  31.         local pos = 0
  32.         local function setscreen(x, y, char)
  33.             if clear then char = " " end
  34.             --if y == math.floor(h/2) and x > math.floor(w/2 - str:len()/2) and x < math.floor(w/2 + str:len()/2) then
  35.             --end
  36.  
  37.             if not screen[x] then screen[x] = {} end
  38.             screen[x][y] = char
  39.         end
  40.         while true do
  41.             for i = 1, 50 do
  42.                 setscreen(math.random(1, w), math.random(1, h), string.char(math.random(32, 126)))
  43.  
  44.                 for n = 1, str:len() do
  45.                     if n <= pos then
  46.                         setscreen(math.floor(w/2 - str:len()/2) + n - 1, math.floor(h/2), str:sub(n, n))
  47.                     end
  48.                 end
  49.  
  50.                 for x, ytbl in pairs(screen) do
  51.                     for y, char in pairs(ytbl) do
  52.                         term.setCursorPos(x, y)
  53.                         term.write(char)
  54.                     end
  55.                 end
  56.  
  57.                 --term.setCursorPos(math.floor(w/2 - str:len()/2), math.floor(h/2))
  58.                 --term.write(str:sub(1, pos))
  59.             end
  60.             pos = pos + 1
  61.             if pos > str:len() then
  62.                 term.clear()
  63.                 term.setCursorPos(math.floor(w/2 - str:len()/2), math.floor(h/2))
  64.                 term.write(str:sub(1, pos))
  65.                 sleep(3)
  66.                 break
  67.             end
  68.             sleep(0)
  69.         end
  70.     end,
  71. }
  72.  
  73. local messages = {
  74.     "Welcome to the Server!",
  75.     "Play Nice!",
  76. }
  77.  
  78. local lasta = -1
  79. local lastm = -1
  80.  
  81. while true do
  82.     local message = math.random(#messages)
  83.     while message == lastm do message = math.random(#messages) end
  84.     lastm = message
  85.  
  86.     local animation = math.random(#animations)
  87.     while animation == lasta do animation = math.random(#animations) end
  88.     lasta = animation
  89.  
  90.     term.setTextColor(2^math.random(0, 15))
  91.  
  92.     animations[animation](messages[message])
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement