Asioron

Graf_drawer

Dec 13th, 2018
138
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -------------------------------------------------------
  2. --        Программа График для Storage drawers       --
  3. --        для компьютеров из мода OpenComputers      --
  4. --          проект http://computercraft.ru           --
  5. --                  Version 0.2                      --
  6. --                 2018, © Asior                     --
  7. -------------------------------------------------------
  8. local charts = require("charts")
  9. local event = require("event")
  10. local gpu = require("component").gpu
  11. local c = require("component")
  12. local drawer = nil
  13. if c.isAvailable("drawer") then
  14.   drawer = c.drawer
  15. else
  16.   print('Подключите адаптер к бочке!')
  17.   os.exit()
  18. end
  19. local term = require("term")
  20. local container = charts.Container()
  21. container.width, container.height = gpu.getViewport()
  22. local payload = charts.Histogram()
  23. if drawer.getMaxCapacity(1) == 0 then
  24.   print('Положите хоть один предмет в бочку!')
  25.   os.exit()
  26. end
  27.  
  28. payload.max = drawer.getMaxCapacity(1)/2
  29. payload.min = -drawer.getMaxCapacity(1)/2
  30. payload.level.value = 0
  31. payload.level.y = 0.5
  32. payload.align = charts.sides.RIGHT
  33. payload.colorFunc = function(index, perc, value, self, container)
  34.   return value >= 0 and 0x20ff20 or 0xff0000
  35. end
  36. container.payload = payload
  37.  
  38. local gr = 0
  39. local count = -1
  40. for i = 1, math.huge, 1 do
  41.   if drawer.getItemCount(1) == 0 then
  42.     gr = payload.min
  43.   else
  44.     gr = -(drawer.getMaxCapacity(1)/2-drawer.getItemCount(1))
  45.   end
  46.   if count ~= gr then
  47.     count = gr
  48.     table.insert(payload.values, gr)
  49.     if #payload.values > container.width then
  50.       table.remove(payload.values, 1)
  51.     end
  52.     container:draw()
  53.   end
  54.   os.sleep(1)
  55. end
RAW Paste Data