Advertisement
bob558

Динамический индикатор буфера --- разобрать

Nov 20th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. local component = require("component")
  2. local gpu = component.gpu
  3. local term = require("term")
  4. local storage = component.draconic_rf_storage
  5. local stored = storage.getEnergyStored --ПОЛУЧАЕМ ЗАПОЛНЕНОСТЬ ХРАНИЛИЩА
  6. local max = storage.getMaxEnergyStored --ПОЛУЧАЕМ ЁМКОСТЬ ХРАНИЛИЩА
  7.   gpu.setBackground(0x202020)
  8.   gpu.setForeground(0xFFDD00)
  9. term.clear()
  10.  
  11. gpu.setResolution(40,6)
  12.  
  13. --===================РИСУЕМ РАМКУ И ПИШЕМ ТЕКСТ================
  14. gpu.set(12,1,"Energy Storage")
  15. gpu.set(1, 2, " ┌────────────────────────────────────┐ ")
  16. gpu.set(1, 3, " │") gpu.set(39,3, "│")
  17. gpu.set(1, 4, " └────────────────────────────────────┘ ")
  18.  
  19.  
  20. while true do
  21.   local procent = "Накоплено энергии: " .. math.ceil(stored()/max()*100) .. "%" --ТЕКСТ И ЗАПОЛНЕНОСТЬ В ПРОЦЕНТАХ
  22.   local progress = math.ceil(stored()/max()*32)                        -- ЗНАЧЕНИЕ ШИРИНЫ ДЛЯ ОТРИСОВКИ ШКАЛЫ
  23.   local details = math.ceil( stored()/1) .. "RF из " .. math.ceil( max()/1) .. "RF" --ТОЧНОЕ ЗНАЧЕНИЕ ХРАНИЛИЩА
  24.  
  25.   gpu.set(5,37-string.len(details),details)  --ПИШЕМ ТОЧНУЮ ЗАПОЛНЕНОСТЬ
  26.   gpu.set(11-string.len( math.ceil( stored()/max()*100 )),6,procent)  --ПИШЕМ ЗАПОЛНЕНОСТЬ В ПРОЦЕНТАХ
  27.  
  28. --=================РИСУЕМС ШКАЛУ===============
  29.   local x = 4
  30.   for i = 1, progress do
  31.     gpu.set(x,3,"▒")
  32.     x = x + 1
  33.   end
  34.  
  35.   os.sleep(0.1) --ЖДЕМ 0.1 СЕКУНДУ
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement