Advertisement
surferpup

Monitor Tutorial P2ex2

Feb 8th, 2014
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. -- Set up variables
  2. local attachedMonitor = peripheral.wrap("top")
  3. local defaultBackgroundColor =colors.black
  4. local defaultTextColor=colors.white
  5.  
  6. local backgroundColorNormal = colors.blue                        
  7. local backgroundColorPressed = colors.red
  8.  
  9. local textColorNormal = colors.white
  10. local textColorPressed = colors.yellow
  11.  
  12. local width=10
  13. local height = 3
  14.  
  15. local label="Button"
  16.  
  17. local startColumn=3
  18. local startRow=3
  19.  
  20. -- Set up Monitor
  21. attachedMonitor.setBackgroundColor(defaultBackgroundColor)
  22. attachedMonitor.setTextColor(defaultTextColor)
  23. --attachedMonitor.setTextScale(.5)
  24. attachedMonitor.clear()
  25.  
  26. -- Display the button Background
  27. attachedMonitor.setBackgroundColor(backgroundColorNormal)
  28. for row = startRow,startRow+height-1 do
  29.     attachedMonitor.setCursorPos(startColumn,row)
  30.     attachedMonitor.write(string.rep(" ",width))
  31. end
  32.  
  33. --Display the label (auto centered)
  34. attachedMonitor.setTextColor (textColorNormal)
  35. attachedMonitor.setCursorPos(startColumn + math.floor((width - #label)/2),startRow)
  36. attachedMonitor.write(label)
  37.  
  38. -- reset to original text/background colors
  39. attachedMonitor.setBackgroundColor(defaultBackgroundColor)
  40. attachedMonitor.setTextColor(defaultTextColor)
  41.  
  42. -- sleep and then let's do it again with our "pressed" colors.
  43. sleep(3)
  44.  
  45. attachedMonitor.setBackgroundColor(backgroundColorPressed)
  46. for row = startRow,startRow+height-1 do
  47.     attachedMonitor.setCursorPos(startColumn,row)
  48.     attachedMonitor.write(string.rep(" ",width))
  49. end
  50.  
  51. attachedMonitor.setTextColor(textColorPressed)
  52. attachedMonitor.setCursorPos(startColumn + math.floor((width - #label)/2),startRow)
  53. attachedMonitor.write(label)
  54.  
  55. attachedMonitor.setBackgroundColor(defaultBackgroundColor)
  56. attachedMonitor.setTextColor(defaultTextColor)
  57.  
  58. attachedMonitor.setCursorPos(1,8)    
  59. attachedMonitor.write("Done.")
  60. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement