Advertisement
SemlerPDX

ComputerCraft Monitor Image Tutorial Example

Sep 6th, 2024 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | Gaming | 0 0
  1. --CC Monitor Image Display & Swap
  2. -- a tutorial example
  3. --by SemlerPDX Sept2024
  4.  
  5. -- pastebin get eVa783zx monitorExample
  6.  
  7. --the monitor next to the PC
  8. local monitor = peripheral.find("monitor")
  9.  
  10. --this most likely will need testing/tweaking
  11. --Must be a multiple of 0.5 between 0.5 and 5
  12. monitorScale = 0.5
  13.  
  14. --a time in seconds between image swapping
  15. --...alter value as needed
  16. local interval = 0.25
  17.  
  18. --the images in a string array, as an example of such
  19. local images = {
  20.   "house1.nfp",
  21.   "house2.nfp",
  22.   "house3.nfp",
  23.   "house4.nfp"
  24. }
  25.  
  26. --load each image into an object array using a loop
  27. local imageArray = {}
  28.  
  29. for i = 1, #images do
  30.   imageArray[i] = paintutils.loadImage(images[i])
  31. end
  32.  
  33. --an integer variable we can increment
  34. --...in "for" loops, called an indexer
  35. --...very similar functionality here:
  36. local index = 1
  37.  
  38. --initialize the monitor scale
  39. monitor.setTextScale(monitorScale)
  40.  
  41. --redirect the terminal to the monitor
  42. term.clear()
  43. term.setCursorPos(1,1)
  44. term.redirect(monitor)
  45.  
  46.  
  47. --the functions of our program:
  48.  
  49. local function ClearMonitor()
  50.   monitor.clear()
  51.   monitor.setCursorPos(1,1)
  52. end
  53.  
  54. local function DrawMonitor()
  55.   --reset our "indexer" if out of range
  56.   if index > #images then
  57.     index = 1
  58.   end
  59.  
  60.   --draw the image corresponding to this index
  61.   paintutils.drawImage(imageArray[index],1,1)
  62.  
  63.   --increment our indexer
  64.   index = index + 1
  65. end
  66.  
  67.  
  68. --The main loop of our program
  69. --...it runs indefinitely, at the interval you set
  70. --...or until stopped, or PC is turned off:
  71. while true do
  72.   sleep(interval)
  73.   ClearMonitor()
  74.   DrawMonitor()
  75. end
  76.  
Tags: minecraft
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement