Advertisement
Guest User

Boot

a guest
Oct 8th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. --Needs to do: Text snapping to the left at approximately 40% completion of loading bar needs fixing
  2.  
  3.  
  4. --Variables
  5.  
  6. mon = term
  7. monX, monY = mon.getSize()
  8.  
  9.  
  10. --Functions
  11. clear = function()
  12.   mon.setBackgroundColor(colors.black)
  13.   mon.clear()
  14.   mon.setCursorPos(1,1)
  15. end
  16.  
  17. drawText = function(x,y,text,color_text,color_bg)
  18.   mon.setBackgroundColor(color_bg)
  19.   mon.setTextColor(color_text)
  20.   mon.setCursorPos(x,y)
  21.   mon.write(text)
  22. end
  23.  
  24. drawLine = function(x,y,length,size,color_bar)
  25.   for yPos = y, y+size-1 do
  26.     mon.setBackgroundColor(color_bar)
  27.     mon.setCursorPos(x,yPos)
  28.     mon.write(string.rep(" ", length))
  29.   end
  30. end
  31.  
  32. drawProg = function(x,y,name,length,size,minVal,maxVal,color_bar,color_bg)
  33.   drawLine(x,y,length,size,color_bg)
  34.   local barSize = math.floor((minVal/maxVal)*length)
  35.   drawLine(x,y,barSize,size,color_bar)
  36.   local text = name.." "..math.floor((minVal/maxVal)*100).."%"
  37.   if barSize > monX/2+#text/2 then
  38.     drawText(monX/2-#text/2+2,y+size/2,text,colors.black,color_bar)
  39.   elseif barSize > #text then
  40.     drawText((x+barSize)-#text,y+size/2,text,colors.black,color_bar)
  41.   else
  42.     drawText(monX/2-#text/2+2,y+size/2,text,colors.black,color_bg)
  43.   end
  44. end
  45.  
  46.  
  47. --Main Stuff Loop
  48.  
  49. for i = 1, 100 do
  50.   drawProg(2,12,"Initialising",monX-2,3,i,100,colors.lime,colors.gray)
  51.   sleep(0.1)
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement