mon = peripheral.wrap("right")
while true do
mon.setBackgroundColor(colors.black)
mon.clear()
mon.setTextScale(2)
mon.setCursorPos(2,2)
mon.setTextColor(colors.yellow)
mon.write("Welcome Back")
event, side, x, y = os.pullEvent("monitor_touch")
if x > 1 and x < 12 and y == 2 then
local image = paintutils.loadImage("right")
mon.setBackgroundColor(colors.black)
mon.clear()
mon.setCursorPos(1,3)
mon.setTextScale(2)
mon.setTextColor(colors.yellow)
mon.write(paintutils.drawImage(image, 3 ,3))
redstone.setOutput("left", true)
sleep(5)
redstone.setOutput("left", false)
sleep(5)
end
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
I need help with displaying an image on a monitor
Started by Wolvenlp, 12 June 2016 - 06:26 PMPosted 12 June 2016 - 08:26 PM
I have made a code to display an image on a monitor but it doesnt seem to be working.
Edited on 12 June 2016 - 11:58 PM
Posted 13 June 2016 - 02:01 AM
paintutils functions don't return anything you can write to a display. Instead, they directly act on the "current" display; you can set this via term.redirect().
Eg:
Eg:
local mon = peripheral.wrap("right")
term.redirect(mon)
local image = paintutils.loadImage("right")
paintutils.drawImage(image, 3 ,3)
Posted 13 June 2016 - 02:14 AM
Two things I noticed - one I'm curious about and one I'd like to point out…
1. Are you loading an image named "right" ? If not, this still won't work. You'll need to specify the path/name of the image file you want to load.
2. I noticed you're setting the monitor cursor position then changing text scale (lines 6 & 7 and lines 17 & 18) - this can have strange results iirc - I recommend setting the text scale first then setting the cursor position.
In fact, I don't think you even need that setCursorPosition call on line 17 just before mon.setTextScale(2) - you're specifying the cursor position in your drawImage call. You also don't need the mon.setTextColor(colors.yellow) call (line 19) as you are already setting it above (on line 8) just before you write text to the monitor.
1. Are you loading an image named "right" ? If not, this still won't work. You'll need to specify the path/name of the image file you want to load.
2. I noticed you're setting the monitor cursor position then changing text scale (lines 6 & 7 and lines 17 & 18) - this can have strange results iirc - I recommend setting the text scale first then setting the cursor position.
In fact, I don't think you even need that setCursorPosition call on line 17 just before mon.setTextScale(2) - you're specifying the cursor position in your drawImage call. You also don't need the mon.setTextColor(colors.yellow) call (line 19) as you are already setting it above (on line 8) just before you write text to the monitor.
Posted 13 June 2016 - 11:41 PM
Thanks for the replys, i havent tested it just yet but i just have 2 quick questions.
Where/How did you learn to write this code?
And where should I enter the code you wrote Bomb Bloke?
Where/How did you learn to write this code?
And where should I enter the code you wrote Bomb Bloke?
Posted 14 June 2016 - 02:51 AM
Where/How did you learn to write this code?
By this I assume you mean how/where could I learn to write this code. The answer differs for many, but for ComputerCraft in general, the wiki is a great resource. I used the API list to familiarize myself with the majority of computercraft's APIs, which is extremely important. For non-CC specific lua, I would recommend the lua 5.1 manual. You don't need to memorize all this by any means, you just need to know it exists so that you can search it quickly when you need it. Stack Overflow is also a great resource. I believe there's a series of tutorials out there aimed at beginners, which are helpful.
For many specific tasks, you can find previous ask-a-pro topics (don't necro them though!) and tutorials through a google search of the forums.
As for explaining what BB did in the code shown;
peripheral.wrap
term.redirect
paintutils.loadImage
paintutils.drawImage
And where should I enter the code you wrote Bomb Bloke?
The first three lines should be placed outside of your loop; they only need to be performed once. The fourth line should be placed at the point in your loop when you wish to draw the image - probably immediately after you clear the screen.
Posted 14 June 2016 - 03:15 AM
Here is the code:
Here is also what it looks like in-game:
http://imgur.com/z2c52u8
- mon = peripheral.wrap("right")
- while true do
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setTextScale(2)
- mon.setCursorPos(2,2)
- mon.setTextColor(colors.yellow)
- mon.write("Welcome Back")
- event, side, x, y = os.pullEvent("monitor_touch")
- if x > 1 and x < 12 and y == 2 then
- mon.setBackgroundColor(colors.black)
- mon.clear()
- local mon = peripheral.wrap("right")
- term.redirect(mon)
- local image = paintutils.loadImage("right")
- paintutils.drawImage(image, -8,1)
- redstone.setOutput("left", true)
- sleep(5)
- redstone.setOutput("left", false)
- sleep(5)
- end
- end
Here is also what it looks like in-game:
http://imgur.com/z2c52u8
Posted 14 June 2016 - 05:44 AM
Set your text scale lower (either 1 or 0.5)
Posted 14 June 2016 - 06:50 AM
Threads merged; you don't need more than one for the one project.