Advertisement
Plazter

MFSU

May 12th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. component = require("component")
  2. mfsu = component.ic2_te_mfsu
  3. mfsu2 = component.proxy(component.get("253d"))
  4. term = require("term")
  5. gpu = component.gpu
  6.  
  7.  
  8.   colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
  9.             purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
  10.             lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
  11.             olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
  12.             folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
  13.             englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
  14.             lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }
  15.  
  16. bar_col   = colors.gray
  17. default_bg  = colors.black
  18. border_bar  = colors.white
  19. text_col    = colors.diamond
  20. stat_col = colors.gray
  21. gpu.setResolution(104,10)
  22.  
  23. function dot(n)
  24.     local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
  25.     return left..(num:reverse():gsub('(%d%d%d)','%1.'):reverse())..right
  26. end
  27.  
  28. function borderBar( x, y, len, s)
  29.     gpu.setBackground(border_bar)
  30.     gpu.fill(x,y, len, 1, s)
  31.     gpu.setBackground(default_bg)
  32. end
  33.  
  34. function Center(y,text) -- CENTERS TEXT  
  35.     w, h = gpu.getResolution()
  36.     term.setCursor((w-string.len(text))/2+1, y)
  37.     term.write(text)
  38. end
  39.  
  40. function initbar(y, title)
  41.     w, h = gpu.getResolution()
  42.         x1 = w-w+2
  43.         x2 = w-w+102
  44.         x3 = w-w+4
  45.     borderBar(x1, y+1, 102, " ")
  46.     borderBar(x1, y+3, 102, " ")
  47.     borderBar(x1, y+2, 1," ")
  48.     borderBar(x3+1, y+2,1," ")
  49.   --
  50.     gpu.setBackground(bar_col)
  51.     borderBar(x3,y+2,100," ")
  52.   --
  53.     gpu.setBackground(default_bg)
  54.     Center(y,"  "..title.."  ")
  55. end
  56.  
  57. function set(y, perc, comp)
  58.     gpu.setBackground(bar_col)
  59.     gpu.fill(3,y+2,100, 1, " ")
  60.    
  61.         if perc >= 0 and perc <= 25 then
  62.             gpu.setBackground(colors.red)
  63.         elseif perc >= 25 and perc < 50 then
  64.             gpu.setBackground(colors.orange)
  65.         elseif perc >= 50 and perc <= 75 then
  66.             gpu.setBackground(colors.yellow)
  67.         elseif perc >= 75 and perc <= 100 then
  68.             gpu.setBackground(colors.lime)
  69.     end
  70.  
  71.     gpu.fill(3,y+2, perc, 1," ")
  72.     gpu.setBackground(stat_col)
  73.     Center(y+1,"  ".. perc .." %  ")
  74.     Center(y+3, "  Stored: ".. dot(tostring(comp.getEnergy())) .." / ".. dot(tostring(comp.getCapacity())).."  ")
  75.     gpu.setBackground(default_bg)
  76. end
  77.  
  78. function bar(y, perc, comp)
  79.   set(y, perc, comp)
  80. end
  81.  
  82. gpu.setBackground(default_bg)
  83. gpu.setForeground(text_col)
  84. term.clear()
  85.  
  86.  
  87. initbar(2, "MFSU # 1")
  88. initbar(7, "MFSU # 2")
  89.  
  90. while true do
  91.   perc = math.floor((mfsu.getEnergy() / mfsu.getCapacity() * 100)+0.5)
  92.   perc2 = math.floor((mfsu2.getEnergy() / mfsu2.getCapacity()*100)+0.5)
  93.     set(2, perc, mfsu)
  94.     set(7, perc2, mfsu2)
  95.    
  96.   os.sleep(1)
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement