Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p = peripheral.wrap("right") -- wrap Energy cell
- m = peripheral.wrap("top") -- wrap monitor
- m.setTextColor(colors.green) -- set colors
- m.setBackgroundColor(colors.red)
- term.clear()
- term.setCursorPos(1,1)
- function chooseColors()
- coloragain = false
- print("Choose your colors:")
- print("1)")
- term.setTextColor(colors.black)
- print("backgound")
- term.setTextColor(colors.red)
- print("bar")
- print("2)")
- term.setTextColor(colors.red)
- print("backgound")
- term.setTextColor(colors.green)
- print("bar")
- setcolors = read()
- if setcolors == "1" then
- colorback = colors.black
- colorbar = colors.red
- elseif setcolors == "2" then
- colorback = colors.red
- colorbar = colors.green
- else
- print("Invalid number. Please try again.")
- sleep(0.5)
- term.clear()
- term.setCursorPos(1,1)
- coloragain = true
- end
- end
- function getInfo()
- me = p.getMaxEnergyStored() -- get energy levels
- e = p.getEnergyStored() -- ..
- end
- function calculate()
- -- perc = percentage
- perc = e / me -- e.g. 1000/4000 returns 0.25
- perc = perc * 100 -- needed for calculation
- end
- function getMonitor()
- x,y = m.getSize() -- get size
- if vorh == "horizontal" then
- Xvalue = x / 100 -- get multiplier
- else
- Xvalue = y / 100
- end
- end
- function display()
- monperc = perc * Xvalue -- amount of pixels to fill
- fillspace = math.ceil(monperc) -- get number, e.g. not 1,5
- if vorh == "vertical" then
- fillspace = fillspace - 1
- fillspace = y - fillspace
- end
- m.setBackgroundColor(colorback)
- -- sleep(0.1) -- remove "--" if experiencing lagg
- m.clear() -- clear monitor
- -- sleep(0.1)
- m.setBackgroundColor(colorbar)
- if vorh == "horizontal" then
- for i = 1,fillspace do
- for l = 1,y do
- m.setCursorPos(i,l)
- m.write(" ")
- end
- end
- else
- for i = fillspace,y do
- for l = 1,x do
- m.setCursorPos(l,i)
- m.write(" ")
- end
- end
- end
- end
- print("Do you want the monitor vertical or horizontal?")
- vorh = read()
- while true do --loop
- if coloragain == true then
- chooseColor()
- else
- getInfo()
- sleep(0.1) -- short interval due to lagg issues
- calculate()
- sleep(0.1)
- getMonitor()
- sleep(0.1)
- display()
- sleep(0.3)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment