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

Need help with monitors

Started by matt55284, 26 November 2013 - 10:46 AM
matt55284 #1
Posted 26 November 2013 - 11:46 AM
Hi im very new to computer craft and im having a bit of trouble.

I created a background that I would like to use for a program im making, so I did

paint .background and saved it.

Im trying to display the background to monitors, but it only displays to the terminal.

Here is my code, sorry if its a mess, I only started yesterday :P/>

m = peripheral.wrap("top")
m.clear()
m.setCursorPos(1,1)

slc = 0
tBarC = 8
tBartC = 1
backColor = 1
m.setBackgroundColor(backColor)
m.clear()

function titleBar()
m.setCursorPos(1,1)
m.setBackgroundColor(tBarC)
m.setTextColor(tBartC)
m.clearLine()
m.setCursorPos(3, 1)
print("[Example]")
end

function drawDesktop()
m.setBackgroundColor(backColor)
m.clear()
bground = paintutils.loadImage(".background")
paintutils.drawImage(bground,1,1)
titleBar()

end

drawDesktop()

Any ideas on how I should draw it to the monitor? Because paintutils.loadimage and drawImage is only displaying to the terminal.

Thanks, Matt
Lyqyd #2
Posted 26 November 2013 - 12:42 PM
Redirect to the monitor. You'd change your drawImage call to be surrounded with a redirect/restore pair:


term.redirect(m)
paintutils.drawImage(bground, 1, 1)
term.restore()

Term.redirect makes it so that calling term functions will call the matching functions in whatever redirect target you pass it, and term.restore undoes the redirect. That way, when paintutils calls term.write, the redirection means that m.write gets called, etc. That means that it will draw to the monitor.
matt55284 #3
Posted 26 November 2013 - 01:16 PM
Redirect to the monitor. You'd change your drawImage call to be surrounded with a redirect/restore pair:


term.redirect(m)
paintutils.drawImage(bground, 1, 1)
term.restore()

Term.redirect makes it so that calling term functions will call the matching functions in whatever redirect target you pass it, and term.restore undoes the redirect. That way, when paintutils calls term.write, the redirection means that m.write gets called, etc. That means that it will draw to the monitor.
Thanks, worked perfectly :)/>