Advertisement
LDDestroier

LDDestroier Lua Animation

Jun 12th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.55 KB | None | 0 0
  1. term.setCursorBlink(false)
  2. local message = {
  3.     "Welcome",
  4.     "to",
  5.     "LDDestroier's",
  6.     "Personal",
  7.     "Download Site!",
  8. }
  9. local spinner = {
  10.     "|",
  11.     "/",
  12.     "-",
  13.     "\\",
  14. }
  15. local spinPoint = 1
  16. local normalColor = colors.gray
  17. local normalTextColor = colors.white
  18. local backgroundFlashes = {
  19.     colors.lightGray,
  20.     colors.white,
  21.     colors.black,
  22.     colors.white,
  23.     colors.lightGray,
  24. }
  25. term.setTextColor(normalTextColor)
  26. term.setBackgroundColor(normalColor)
  27. term.clear()
  28. local scr_x, scr_y = term.getSize()
  29. local midPoint = {
  30.     scr_x / 2,
  31.     scr_y / 2,
  32. }
  33. local spinSpeed = 1
  34.  
  35. local function megaBackground(depth)
  36.     for b = 1, math.ceil(depth) do
  37.         term.setCursorPos(1,math.ceil(b))
  38.         if b == math.ceil(depth) then
  39.             term.setBackgroundColor(colors.black)
  40.         else
  41.             term.setBackgroundColor(colors.blue)
  42.         end
  43.         term.clearLine()
  44.     end
  45.     for b = 1, math.floor(depth) do
  46.         term.setCursorPos(1,math.floor(scr_y-(b-1)))
  47.         if b == math.floor(depth) then
  48.             term.setBackgroundColor(colors.black)
  49.         else
  50.             term.setBackgroundColor(colors.blue)
  51.         end
  52.         term.clearLine()
  53.     end
  54. end
  55.  
  56. local function writeMessages(quick)
  57.     if not quick then
  58.         for a = 1, math.floor(midPoint[1]-(#message[1]/2)) do
  59.             for c = 1, spinSpeed do
  60.                 spinPoint = spinPoint + 1
  61.                 if spinPoint > #spinner then
  62.                     spinPoint = 1
  63.                 end
  64.                 term.setCursorPos(a,math.floor(midPoint[2]-(#message/2))+1)
  65.                 term.clearLine()
  66.                 write(spinner[spinPoint])
  67.                 sleep(0)
  68.             end
  69.         end
  70.     end
  71.     totalLength = 0
  72.     progress = 0
  73.     for a = 1, #message do
  74.         totalLength = totalLength + #message[a]
  75.     end
  76.     for a = 1, #message do
  77.         if not quick then
  78.             for b = 1, #message[a] do
  79.                 progress = progress + 1
  80.                 megaBackground(math.ceil((progress/totalLength)*(midPoint[2]-(#message/2)-1)))
  81.                 term.setBackgroundColor(normalColor)
  82.                 term.setTextColor(colors.orange)
  83.                 term.setCursorPos(midPoint[1]-(#message[a])/2,math.floor(midPoint[2]-(#message/2)+a))
  84.                 term.clearLine()
  85.                 write(string.sub(message[a], 1, b))
  86.                 term.setBackgroundColor(normalColor)
  87.                 term.setTextColor(normalTextColor)
  88.                 for c = 1, spinSpeed do
  89.                     spinPoint = spinPoint + 1
  90.                     if spinPoint > #spinner then
  91.                         spinPoint = 1
  92.                     end
  93.                     if b < #message[a] then
  94.                         term.setCursorPos((midPoint[1]-(string.len(message[a])/2))+b,math.floor(midPoint[2]-(#message/2)+a))
  95.                         write(spinner[spinPoint])
  96.                         sleep(0)
  97.                     end
  98.                 end
  99.             end
  100.             sleep(0.03)
  101.         else
  102.             term.setCursorPos(midPoint[1]-(string.len(message[a])/2),math.floor(midPoint[2]-(#message/2)+a))
  103.             term.setTextColor(colors.orange)
  104.             term.setBackgroundColor(normalColor)
  105.             term.clearLine()
  106.             write(message[a])
  107.         end
  108.     end
  109. end
  110.  
  111. local function flashScreen()
  112.     for a = 1, 2 do
  113.         term.setBackgroundColor(colors.white)
  114.         term.clear()
  115.         sleep(0.1)
  116.         term.setBackgroundColor(colors.black)
  117.         term.clear()
  118.         sleep(0.1)
  119.     end
  120.     return true
  121. end
  122.  
  123. local function exitAnimation()
  124.     term.setBackgroundColor(colors.black)
  125.     term.clear()
  126.     exitMessage = "Goodbye!"
  127.     for a = 1, midPoint[2]-3 do
  128.         megaBackground(a)
  129.         term.setCursorPos(math.floor((scr_x-a)/1.4)+2,midPoint[2])
  130.         term.clearLine()
  131.         write(exitMessage)
  132.         sleep(0.1)
  133.     end
  134.     sleep(0.6)
  135.     term.setCursorPos(1,scr_y)
  136.     return
  137. end
  138.  
  139. writeMessages(false)
  140.  
  141. sleep(0.6)
  142.  
  143. for a = 1, #backgroundFlashes do
  144.     term.setBackgroundColor(backgroundFlashes[a])
  145.     term.clear()
  146.     writeMessages(true)
  147.     sleep(0.1)
  148. end
  149. --Time to make it look normal, and not have the background the last in backgroundFlashes
  150. term.setBackgroundColor(normalColor)
  151. term.clear()
  152. megaBackground(math.ceil((midPoint[2]-(#message/2)-1)))
  153. writeMessages(true)
  154. sleep(0.5)
  155. for a = 1, scr_y-2 do
  156.     term.scroll(1)
  157.     term.setCursorPos(1,scr_y)
  158.     term.setBackgroundColor(colors.blue)
  159.     term.setTextColor(colors.white)
  160.     term.clearLine()
  161.     sleep(0.1)
  162. end
  163. local commandNames = {
  164.     " (1) Download Map ",
  165.     " (2) Download On ",
  166.     " (3) Download Monc ",
  167.     " (4) Download STD",
  168.     " (X) Exit ",
  169. }
  170. local fadeInColors = {
  171.     colors.lightBlue,
  172.     colors.lightGray,
  173.     colors.black,
  174. }
  175. for a = 1, #fadeInColors+1 do
  176.     if a > #fadeInColors then
  177.         term.setTextColor(colors.white)
  178.     else
  179.         term.setTextColor(fadeInColors[a])
  180.     end
  181.     for b = 1, #commandNames do
  182.         term.setCursorPos(math.floor(midPoint[2]-(#commandNames/2)),b+3)
  183.         term.clearLine()
  184.         term.setBackgroundColor(colors.gray)
  185.         print(commandNames[b])
  186.         term.setBackgroundColor(colors.blue)
  187.         print("")
  188.     end
  189.     sleep(0.04)
  190. end
  191.  
  192. local function downloadMap()
  193.     term.setBackgroundColor(normalColor)
  194.     term.clear()
  195.     megaBackground(midPoint[2]-3)
  196.     term.setCursorPos(3,midPoint[2])
  197.     write("Downloading Map...")
  198.     local downloadFile = http.get("http://pastebin.com/raw.php?i=x9ajKSc0").readAll()
  199.     local file = fs.open("/map", "w")
  200.     file.write(downloadFile)
  201.     file.close()
  202.     write("complete!")
  203.     sleep(0.2)
  204.     for a = 1, 4 do
  205.         megaBackground(midPoint[2]-3+a)
  206.     end
  207.     term.setCursorPos(4,midPoint[2]+1)
  208.     term.setTextColor(colors.white)
  209.     print("Press a key to exit!")
  210.     sleep(0)
  211.     os.pullEvent("key")
  212.     flashScreen()
  213.     return
  214. end
  215.  
  216. local function downloadOn()
  217.     term.setBackgroundColor(normalColor)
  218.     term.clear()
  219.     megaBackground(midPoint[2]-3)
  220.     term.setCursorPos(3,midPoint[2])
  221.     write("Downloading On...")
  222.     local downloadFile = http.get("http://pastebin.com/raw.php?i=W4GLNE39").readAll()
  223.     local file = fs.open("/on", "w")
  224.     file.write(downloadFile)
  225.     file.close()
  226.     write("complete!")
  227.     sleep(0.2)
  228.     for a = 1, 4 do
  229.         megaBackground(midPoint[2]-3+a)
  230.     end
  231.     term.setCursorPos(4,midPoint[2]+1)
  232.     term.setTextColor(colors.white)
  233.     print("Press a key to exit!")
  234.     sleep(0)
  235.     os.pullEvent("key")
  236.     flashScreen()
  237.     return
  238. end
  239.  
  240. local function downloadMonc()
  241.     term.setBackgroundColor(normalColor)
  242.     term.clear()
  243.     megaBackground(midPoint[2]-3)
  244.     term.setCursorPos(3,midPoint[2])
  245.     write("Downloading Monc...")
  246.     local downloadFile = http.get("http://pastebin.com/raw.php?i=FRJRneKL").readAll()
  247.     local file = fs.open("monc", "w")
  248.     file.write(downloadFile)
  249.     file.close()
  250.     write("complete!")
  251.     sleep(0.2)
  252.     for a = 1, 4 do
  253.         megaBackground(midPoint[2]-3+a)
  254.     end
  255.     term.setCursorPos(4,midPoint[2]+1)
  256.     term.setTextColor(colors.white)
  257.     print("Press a key to exit!")
  258.     sleep(0)
  259.     os.pullEvent("key")
  260.     flashScreen()
  261.     return
  262. end
  263.  
  264. local function downloadSTD()
  265.     term.setBackgroundColor(normalColor)
  266.     term.clear()
  267.     megaBackground(midPoint[2]-3)
  268.     term.setCursorPos(3,midPoint[2])
  269.     write("Downloading STD...")
  270.     local downloadFile = http.get("http://pastebin.com/raw.php?i=3PBKGR4k").readAll()
  271.     local file = fs.open("std", "w")
  272.     file.write(downloadFile)
  273.     file.close()
  274.     write("complete!")
  275.     sleep(0.2)
  276.     for a = 1, 4 do
  277.         megaBackground(midPoint[2]-3+a)
  278.     end
  279.     term.setCursorPos(4,midPoint[2]+1)
  280.     term.setTextColor(colors.white)
  281.     print("Press a key to exit!")
  282.     sleep(0)
  283.     os.pullEvent("key")
  284.     flashScreen()
  285.     return
  286. end
  287.  
  288. local curX, curY = term.getCursorPos()
  289. term.setCursorPos(4,curY)
  290. local curX, curY = term.getCursorPos()
  291. while true do
  292.     sleep(0)
  293. --  event, key = os.pullEvent("key")
  294. --  key = tostring(keys.getName(key))
  295.     term.setCursorPos(curX,curY)
  296.     term.clearLine()
  297.     write(">")
  298.     local _,key
  299.     repeat
  300.         _,key = os.pullEvent("char")
  301.     until string.find("1234x",key)
  302.     if key == "1" then
  303.         flashScreen()
  304.         downloadMap()
  305.         exitAnimation()
  306.         return
  307.     end
  308.     if key  == "2" then
  309.         flashScreen()
  310.         downloadOn()
  311.         exitAnimation()
  312.         return
  313.     end
  314.     if key == "3" then
  315.         flashScreen()
  316.         downloadMonc()
  317.         exitAnimation()
  318.         return
  319.     end
  320.     if key == "4" then
  321.         flashScreen()
  322.         downloadSTD()
  323.         exitAnimation()
  324.         return
  325.     end
  326.     if key == "x" then
  327.         flashScreen()
  328.         exitAnimation()
  329.         return
  330.     end
  331. end
  332. error("did not expect to get here...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement