Advertisement
C0BRA

Battery thing

Dec 25th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. local screen = self.CreateLink("screen")
  2. local bats = {}
  3.  
  4. for i = 1, 10 do
  5.     bats[i] = self.CreateLink("battery" .. tostring(i))
  6. end
  7.  
  8. function ProgressBar(x, y, w, perc)
  9.     local extra = w * perc
  10.     local fg = string.rep(" ", extra)
  11.     local bg = string.rep(" ", w)
  12.    
  13.     screen.Draw(bg, x, y, Color(0, 0, 0, 0), Color(0, 0, 0, 127))
  14.     screen.Draw(fg, x, y, Color(0, 0, 0, 0), Color(127, 127, 127))
  15.    
  16.     screen.Draw( tostring(math.Round(perc * 100 * 100) / 100) .. "%", x + w * 0.5 - 2, y)
  17. end
  18.  
  19. function Think()
  20.     if not screen.Connected then return 1 end
  21.     screen.Clear(Color(0, 0, 0, 0))
  22.    
  23.     local y = 0
  24.     local x = 1
  25.    
  26.     for k,v in pairs(bats) do
  27.         if v.Connected then
  28.             screen.Draw("Battery " .. tostring(k), x, y)
  29.             print(v.Charge(), v.Capacity())
  30.             ProgressBar(x, y + 1, 60, v.Charge() / v.Capacity())
  31.             y = y + 3
  32.         end
  33.     end
  34.    
  35.     return 0.0001
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement