Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("top")
- rednet.open("right")
- local kapacitapos = 0
- local x=1
- local nazev = "Reaktor"
- mon.setBackgroundColor(colors.black)
- mon.setTextScale(1)
- function comma_value(amount)
- local formatted = amount
- local swap = false
- if formatted < 0 then
- formatted = formatted*-1
- swap = true
- end
- while true do
- formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')
- if k == 0 then
- break
- end
- end
- if swap then
- formatted = "-"..formatted
- end
- return formatted
- end
- function bar(a)
- w,h = mon.getSize()
- mon.setCursorPos(2,a)
- mon.setTextScale(0.5)
- mon.setBackgroundColor(colors.gray)
- for i=1, w-2 do
- mon.write(" ")
- end
- mon.setCursorPos(2,a+1)
- mon.write(" ")
- mon.setBackgroundColor(colors.lime)
- barproc = (w-4)/100
- barproc = math.floor(barproc*kapacitaproc)
- for i=1, barproc do
- mon.write(" ")
- end
- mon.setBackgroundColor(colors.gray)
- for i=1, w-barproc-3 do
- mon.write(" ")
- end
- mon.setCursorPos(2,a+2)
- for i=1, w-2 do
- mon.write(" ")
- end
- --mon.setTextScale(1)
- mon.setCursorPos(w-1,a)
- mon.setBackgroundColor(colors.black)
- end
- while true do
- --local event, side, xx, yy = os.pullEvent("monitor_touch")
- local event, p1, p2, p3 = os.pullEvent()
- if event=="rednet_message" then
- rednet.receive(1) --ceka 1s na prijem
- if p1==14 then --14 je id vysilace
- mon.clear()
- mon.setCursorPos(1,1)
- celkem = p2[2]
- kapacita = p2[1]
- if kapacitapos == 0 then
- kapacitapos = kapacita
- end
- kapacitaroz = kapacita - kapacitapos
- kapacitaroz = kapacitaroz/20
- proc = celkem/100
- kapacitaproc = kapacita/proc
- kapacitaproc = math.floor(kapacitaproc)
- kapacita = math.floor(kapacita)
- kapacitaroz = math.floor(kapacitaroz)
- --tik = kapacita - kapacitapos
- mon.setCursorPos(1,x)
- mon.write(nazev)
- mon.setCursorPos(1,x+1)
- mon.write("Kapacita: "..comma_value(math.floor(kapacita)).." Rf")
- mon.setCursorPos(1,x+2)
- mon.write("Kapacita: "..kapacitaproc.." %")
- if kapacitaroz>0 then
- mon.setCursorPos(1,x+3)
- mon.setTextColor(colors.lime)
- mon.write("RF/tik : "..comma_value(math.floor(kapacitaroz)).." Rf")
- mon.setTextColor(colors.white)
- else
- mon.setCursorPos(1,x+3)
- mon.setTextColor(colors.red)
- mon.write("RF/tik : "..comma_value(math.floor(kapacitaroz)).." Rf")
- mon.setTextColor(colors.white)
- end
- bar(7)
- mon.setCursorPos(1,x+5)
- mon.write("Celkova kapacita: "..comma_value(math.floor(celkem)).." Rf")
- end
- kapacitapos = tonumber(p2[1])
- --sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement