Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require('component')
- local term = require("term")
- local gpu = com.gpu
- local background = 0x161a1e
- local foreground = 0xf5f5f5
- local timeSleep = 2
- local components = {"mfe","chargepad_mfe","mfsu","chargepad_mfsu"}
- local totalEU
- local growth
- local mf
- local graph = {
- [1]={
- ["EU"] = 0,
- ["y"] = 1,
- ["color"] = 0xb32821,
- ["colorShadow"] = 0x591410
- }
- }
- local function componentTest()
- local noComponent = true
- for i=1,#components do
- if com.isAvailable(components[i]) then
- noComponent = false
- mf = com[components[i]]
- end
- end
- if noComponent then
- print("Не подключен энергохранитель через адаптер!")
- os.exit()
- end
- end
- local function init()
- componentTest()
- totalEU = mf.getCapacity()
- gpu.setResolution(80,40)
- gpu.setBackground(background)
- gpu.setForeground(foreground)
- term.clear()
- end
- local function drawBar()
- gpu.fill(1,1,80,1," ")
- gpu.set(1,1,"Хранится EU: "..graph[#graph].EU.." из "..totalEU.." | Прирост: "..growth)
- gpu.set(70,1,"by lokin135")
- gpu.fill(1,2,80,1,"_")
- end
- local function drawGraph()
- for i=1,#graph do
- gpu.setBackground(background)
- gpu.fill(i,3,1,(40-graph[i].y)-3," ")
- gpu.setForeground(graph[i].color)
- gpu.setBackground(graph[i].color)
- gpu.set(i,(40-graph[i].y),"X")
- gpu.setForeground(graph[i].colorShadow)
- gpu.setBackground(graph[i].colorShadow)
- gpu.fill(i,(40-graph[i].y)+1,1,40,"X")
- end
- gpu.setForeground(foreground)
- gpu.setBackground(background)
- end
- local function calculGraph()
- local EUNow = mf.getStored()
- local nextGraph = graph
- growth = EUNow - graph[#graph].EU
- local nextY = math.ceil((EUNow / totalEU) * 40)
- nextGraph[#graph+1] = {}
- if not (#graph <= 80) then
- table.remove(graph,1)
- end
- if nextY > 37 then
- nextGraph[#graph].y = 37
- else if nextY < 2 then
- nextGraph[#graph].y = 1
- else
- nextGraph[#graph].y = nextY
- end
- end
- nextGraph[#graph].EU = EUNow
- if growth > 1024 then
- nextGraph[#graph].color = 0x27a327
- nextGraph[#graph].colorShadow = 0x145214
- else if growth < -1024 then
- nextGraph[#graph].color = 0xb32821
- nextGraph[#graph].colorShadow = 0x591410
- else
- nextGraph[#graph].color = 0x007dff
- nextGraph[#graph].colorShadow = 0x004a99
- end
- end
- end
- init()
- while true do
- calculGraph()
- drawBar()
- os.sleep(timeSleep)
- drawGraph()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement