Guest User

Untitled

a guest
Sep 14th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local char="*"
  2.  
  3. local function drawRect(x,y,w,h, clear)
  4.   clear = clear or false
  5.   local ch
  6.   if clear then
  7.     ch = " "
  8.   else
  9.     ch = char
  10.   end
  11.   for i=x-w/2,x+w/2 do
  12.     term.setCursorPos(i,y-h/2)
  13.     term.write(ch)
  14.     term.setCursorPos(i,y+h/2)
  15.     term.write(ch)
  16.   end
  17.   for i=y-h/2+1,y+h/2-1 do
  18.     term.setCursorPos(x-w/2,i)
  19.     term.write(ch)
  20.     term.setCursorPos(x+w/2,i)
  21.     term.write(ch)
  22.   end
  23. end
  24.  
  25. local function animateRect(x,y,w,h)
  26.   local l = math.min(w,h)
  27.   for i=1,l/2 do
  28.     drawRect(x,y,w*2*(i/l),h*2*(i/l))
  29.     sleep(0)
  30.     drawRect(x,y,w*2*(i/l),h*2*(i/l),true)
  31.   end
  32.   drawRect(x,y,w,h)
  33. end
  34.  
  35. local function slowPrint(x,y,str)
  36.   local s=str
  37.   local w = 0
  38.   local h = 0
  39.   while #s > 1 do
  40.     local ind = string.find(s,'\n')
  41.     local line = ""
  42.     if not ind then
  43.       line = s
  44.       s=""
  45.     else
  46.       line = string.sub(s,1,ind)
  47.       s = string.sub(s,ind)
  48.     end
  49.     if not line then
  50.       break
  51.     end
  52.     w=max(w,#line)
  53.     h=h+1
  54.   end
  55.   animateRect(x,y,w+2,h+2)
  56.   term.setCursorPos(x-w/2+1,y-h/2+1)
  57.   textutils.slowPrint(str)
  58. end
  59. --animateRect(25,9,20,10)
  60. slowPrint(25,9,'test')
Add Comment
Please, Sign In to add comment