SemlerPDX icon

ComputerCraft Monitor Image Tutorial Example

SemlerPDX | PRO | 09/10/24 03:34:52 AM UTC (Edited) | 0 ⭐ | 1242 👁️ | Never ⏰ | [minecraft]
Lua |

1.6 KB

|

Gaming

|

0 👍

/

0 👎

--CC Monitor Image Display & Swap
-- a tutorial example
--by SemlerPDX Sept2024
 
-- pastebin get eVa783zx monitorExample
 
--the monitor next to the PC
local monitor = peripheral.find("monitor")
 
--this most likely will need testing/tweaking
--Must be a multiple of 0.5 between 0.5 and 5
monitorScale = 0.5
 
--a time in seconds between image swapping
--...alter value as needed
local interval = 0.25
 
--the images in a string array, as an example of such
local images = {
  "house1.nfp",
  "house2.nfp",
  "house3.nfp",
  "house4.nfp"
}
 
--load each image into an object array using a loop
local imageArray = {}
 
for i = 1, #images do
  imageArray[i] = paintutils.loadImage(images[i])
end
 
--an integer variable we can increment
--...in "for" loops, called an indexer
--...very similar functionality here:
local index = 1
 
--initialize the monitor scale
monitor.setTextScale(monitorScale)
 
--redirect the terminal to the monitor
term.clear()
term.setCursorPos(1,1)
term.redirect(monitor)
 
 
--the functions of our program:
 
local function ClearMonitor()
  monitor.clear()
  monitor.setCursorPos(1,1)
end
 
local function DrawMonitor()
  --reset our "indexer" if out of range
  if index > #images then
    index = 1
  end
  
  --draw the image corresponding to this index
  paintutils.drawImage(imageArray[index],1,1)
 
  --increment our indexer
  index = index + 1
end
 
 
--The main loop of our program
--...it runs indefinitely, at the interval you set
--...or until stopped, or PC is turned off:
while true do
  sleep(interval)
  ClearMonitor()
  DrawMonitor()
end
 

Comments