Advertisement
Proxymity

GraphingMC

Aug 23rd, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. local monitor
  2. local hasMonitor = false
  3. local ProgressBar = {}
  4. local FillColor = colors.orange
  5. local EmptyColor = colors.blue
  6. local TextColor = colors.white
  7.  
  8. function SetPeripheral(top)
  9.   if (peripheral.isPresent(top)) then
  10.     monitor = peripheral.wrap(top)
  11.     hasMonitor = true
  12.   end
  13. end
  14.  
  15. function SetTable(name, maxVal, curVal, xmin, xmax, y)
  16.   ProgressBar[name] = {}
  17.   ProgressBar[name]["Max"] = maxVal
  18.   ProgressBar[name]["Current"] = curVal
  19.   ProgressBar[name]["XMin"] = xmin
  20.   ProgressBar[name]["XMax"] = xmax
  21.   ProgressBar[name]["YVal"] = y
  22. end
  23.  
  24. function ClearTable()
  25.   if (hasMonitor) then
  26.     ProgressBar = {}
  27.   end
  28. end
  29.  
  30. function SetFillColor(color)
  31.   if (colors.combine(color,color)) then  
  32.     FillColor = color
  33.   end
  34. end
  35.  
  36. function SetEmptyColor(color)
  37.   if (colors.combine(color,color)) then
  38.     EmptyColor = color
  39.   end
  40. end
  41.  
  42. function SetTextColor(color)
  43.   if (colors.combine(color,color)) then
  44.     TextColor = color
  45.   end
  46. end
  47.  
  48. function SetMaxValue(name, intVal)
  49.   if (ProgressBar[name]) then
  50.     ProgressBar[name]["Max"] = intVal
  51.   end
  52. end
  53.  
  54. function SetCurValue(name, intVal)
  55.   if (ProgressBar[name]) then
  56.     ProgressBar[name]["Current"] = intVal
  57.   end
  58. end
  59.  
  60. function DrawToPeripheral()
  61.   if (hasMonitor) then
  62.     for name, data in pairs(ProgressBar) do
  63.       DrawBar(name, data)
  64.     end
  65.   end
  66. end
  67.  
  68. function DrawBar(name, arr)
  69.   local y = arr["YVal"]
  70.   local fill = math.floor((arr["XMax"] - arr["XMin"]) * (arr["Current"] / arr["Max"]))
  71.  
  72.   monitor.setBackgroundColor(FillColor)
  73.   monitor.setTextColor(TextColor)
  74.  
  75.   for x = arr["XMin"], arr["XMax"] do
  76.     local num = math.floor(x - arr["XMin"])
  77.     monitor.setCursorPos(x,y)
  78.    
  79.     if (num > fill) then
  80.       monitor.setBackgroundColor(EmptyColor)
  81.     end
  82.    
  83.     if (num == 0) then
  84.       monitor.write("[")
  85.     end
  86.     if (x == arr["XMax"]) then
  87.       monitor.write("]")
  88.     else
  89.       monitor.write(" ")
  90.     end
  91.   end
  92.  
  93.   monitor.setBackgroundColor(colors.black)
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement