This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
pairak's profile picture

Monitor improvements help

Started by pairak, 14 February 2017 - 11:52 AM
pairak #1
Posted 14 February 2017 - 12:52 PM
Hello, I have made a CC program for monitoring my Mekanism Induction Matrix, but im not quite happy with how it looks. I was hoping maybe someone here could give me some clues to how to make the 2 changes I mainly want.
This is how it currently looks:
http://prnt.sc/e8loxq

The 2 changes im trying for is that I would like the top line "Power: X% Full" to be slightly larger then the rest of the text. The other change is that I would like the numbers to be fixed with a comma or something, like instead of reading 39322KRF if it could read 39'322KRF or something like that to make the numbers more readable.
I am also open for sudgestions if there is any other ideas for what could make this look a bit better. In advance, thank you.


power = peripheral.wrap("Induction Matrix_0")
mon = peripheral.wrap("monitor_27")

local maxPower = 0
local curPower = 0
local perPower = 0
local outPower = 0
local inpPower = 0
local capPower = 0
monX,monY = mon.getSize()

function checkPower()
  maxPower = power.getMaxEnergy()
  curPower = power.getEnergy()
  perPower = math.floor(((curPower/maxPower)*100)+0.5)
  currentPower = math.floor(((curPower/2.5)/1000000)+0.5)

  outPower = power.getOutput()
  inpPower = power.getInput()
  capPower = power.getTransferCap()
  outputPower = math.floor(((outPower/2.5)/1000)+0.5)
  inputPower = math.floor(((inpPower/2.5)/1000)+0.5)
  cappedPower = math.floor(((capPower/2.5)/1000)+0.5)
end


function writeMon()
  mon.setBackgroundColor(colors.black)
  mon.clear()
  mon.setCursorPos(1,1)
--  mon.write("Power")
  title = "  Power: " .. perPower .. "% Full  "
  centerT(title, 3, colors.black, colors.blue)
  title = "  Stored Power: " .. currentPower .."Mrf "
  centerT(title, 5, colors.black, colors.blue)
  title = "  Input: " .. inputPower .. "/" .. cappedPower .. "Krf"
  centerT(title, 7, colors.black, colors.green)
  title = "  Output: " .. outputPower .. "/" .. cappedPower .. "Krf"
  centerT(title, 9, colors.black, colors.red)

end

function centerT(text,line,backColor,txtColor)
  mon.setBackgroundColor(backColor)
  mon.setTextColor(txtColor)
  length = (string.len(text))
  dif= math.floor(monX-length)
  x = math.floor(dif/2)
  mon.setCursorPos(x+1, line)
  mon.write(text)
end

function drawBar()
  bar = math.floor(((curPower/maxPower)*(monX-2))+0.5)
  mon.setCursorPos(2,monY-4)
  mon.setBackgroundColor(colors.red)
  mon.write(string.rep(" ", monX-2))

end

while true do
checkPower()
writeMon()
drawBar()

print(curPower .. "/" .. maxPower)
sleep(1)
end

http://pastebin.com/gD1iSgbv
Bomb Bloke #2
Posted 14 February 2017 - 01:55 PM
http://www.computercraft.info/forums2/index.php?/topic/25367-bigfont-api-write-bigger-letters-v10/
Lupus590 #3
Posted 14 February 2017 - 03:51 PM
http://stackoverflow.com/questions/10989788/lua-format-integer

not sure if will work in CC but have a go