Advertisement
Shazz

MonAPI - Example Program - ComputerCraft

Jun 25th, 2013
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. os.loadAPI('monAPI')
  2. local mon = monAPI.wrapMonitor('left')
  3.  
  4. mon.setTextColour(colours.white)
  5. mon.setBackgroundColour(colours.black)
  6. mon.clear()
  7. mon.setCursorPos(1, 1)
  8.  
  9. local section1 = mon.createSection(1, 1, 7, 5)
  10. section1.setBackgroundColour(colours.orange)
  11. section1.clear()
  12. section1.write('Hello')
  13. section1.registerHitbox('tHello', 1, 1, 5, 1)
  14.  
  15. local section2 = mon.createSection(10, 12, 21, 21)
  16. section2.setTextColour(colours.lime)
  17. section2.drawBorder('-', '|', '+')
  18. section2.setCursorPos(5,4)
  19. section2.write('Test')
  20.  
  21. local section3 = mon.createSection(45, 18, 60, 19)
  22. local w3, h3 = section3.getSize()
  23. local sID3 = section3.getSectionID()
  24. section3.registerHitbox('click_here', 1, 1, w3, h3)
  25. function drawS3(showInfo)
  26.     if showInfo then
  27.         section3.clear()
  28.         section3.setCursorPos(1,1)
  29.         section3.write('x, y: ' .. w3 .. ', ' .. h3)
  30.         section3.setCursorPos(1,2)
  31.         section3.write('sectionID: ' .. sID3)
  32.     else
  33.         section3.setBackgroundColour(colours.green)
  34.         section3.clear()
  35.         section3.setCursorPos(1, 1)
  36.         section3.write('Click here!')
  37.     end
  38. end
  39. local bDraw = false
  40. drawS3(bDraw)
  41.  
  42. local section4 = mon.createSection(68, 32, 82, 40)
  43.  
  44.  
  45. function checkForClick()
  46.     while true do
  47.         local ev = {os.pullEvent()}
  48.         if ev[1] == 'monitor_touch' then
  49.             local name, sectionID = mon.getHitbox(ev[3], ev[4])
  50.             if name == 'click_here' then
  51.                 bDraw = not bDraw
  52.                 drawS3(bDraw)
  53.             end
  54.         end
  55.     end
  56. end
  57.  
  58. function animate()
  59.     while true do
  60.         section4.setBackgroundColour(colours.blue)
  61.         section4.fill('o')
  62.         sleep(1)
  63.         section4.setBackgroundColour(colours.lime)
  64.         section4.fill('O')
  65.         sleep(1)
  66.         section4.setBackgroundColour(colours.red)
  67.         section4.fill('0')
  68.         sleep(1)
  69.     end
  70. end
  71.  
  72. parallel.waitForAll(animate, checkForClick)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement