Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MonitorSide = "right"
- Monitor1 = peripheral.wrap(MonitorSide)
- cell1 = peripheral.wrap("left")
- ProgressBarBackgroundColour = colours.grey
- function GetHexFromColour(clr)
- local colourOut = 0xCC4C4C --red
- if (clr == colours.white) then colourOut = 0xFFFFFF end
- if (clr == colours.orange) then colourOut = 0xF2B233 end
- if (clr == colours.yellow) then colourOut = 0xDEDE6C end
- if (clr == colours.green) then colourOut = 0x57A64E end
- if (clr == colours.cyan) then colourOut = 0x4C99B2 end
- return colourOut;
- end
- function GetColourFromPercent(percentage)
- local colourOut = colours.red
- if (percentage > 15) then colourOut = colours.orange end
- if (percentage > 45) then colourOut = colours.yellow end
- if (percentage > 70) then colourOut = colours.cyan end
- if (percentage > 90) then colourOut = colours.green end
- return colourOut
- end
- function ClearScreens()
- Monitor1.setTextColor(colours.black)
- Monitor1.setBackgroundColor(colours.black)
- Monitor1.clear()
- Monitor1.setCursorPos(1,1)
- end
- function DrawText(xPos, yPos, text, textColour, backgroundColour)
- Monitor1.setBackgroundColor(backgroundColour)
- Monitor1.setTextColor(textColour)
- Monitor1.setCursorPos(xPos,yPos)
- Monitor1.write(text)
- end
- function DrawLine(xPos, yPos, lineLength, colour)
- Monitor1.setBackgroundColor(colour)
- Monitor1.setTextColor(colour)
- Monitor1.setCursorPos(xPos,yPos)
- Monitor1.write(string.rep(" ", lineLength))
- end
- function ProgressBar(xPos, yPos, barLength, value, maxValue, backgroundColour, progressColour)
- DrawLine(xPos, yPos, barLength, backgroundColour) --backgoround bar
- local barSize = math.floor((value/maxValue) * barLength)
- DrawLine(xPos, yPos, barSize, progressColour) --progress so far
- end
- function DrawPowerBar(monitorX, yPos, cellName, cellEnergy, cellMaxEnergy, cellPercent, barColour)
- DrawText(3, yPos, cellName, colours.white, colours.black)
- ProgressBar(10, yPos, monitorX - 15, cellEnergy, cellMaxEnergy, barColour, GetColourFromPercent(cellPercent))
- DrawText(monitorX - 4, yPos, cellPercent .. "%", colours.white, colours.black)
- end
- function GetCellBarColour(cellEnergyPercent)
- if (cellEnergyPercent == 0) then
- return colours.red
- else
- return colours.grey
- end
- end
- function FetchAndRedraw()
- Monitor1.setTextScale(1)
- local monX, monY = Monitor1.getSize()
- local cell1Energy = cell1.getEnergyStored("unknown")
- local cell1MaxEnergy = cell1.getMaxEnergyStored("unknown")
- local cell1Percent = math.floor((cell1Energy / cell1MaxEnergy) * 100)
- ClearScreens()
- DrawText(2, 2, "ME Backup Power Cell", colours.white, colours.black)
- DrawText(2, 4, cell1Percent .. "%", colours.white, colours.black)
- ProgressBar(2, 6, monX - 2, cell1Energy , cell1MaxEnergy , ProgressBarBackgroundColour, GetColourFromPercent(cell1Percent))
- end
- while true do
- FetchAndRedraw()
- os.sleep(2)
- end
Add Comment
Please, Sign In to add comment