Advertisement
surferpup

Monitor Tutorial Word Example

Feb 4th, 2014
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. ocal attachedMonitor = peripheral.wrap("top")
  2. attachedMonitor.setTextScale(0.5)
  3. attachedMonitor.setBackgroundColor(colors.blue)
  4. attachedMonitor.clear();
  5. attachedMonitor.setCursorPos(1,3)
  6. attachedMonitor.write("This is white")
  7. attachedMonitor.setTextColor(colors.yellow)
  8. attachedMonitor.setCursorPos(1,4)
  9. attachedMonitor.write("This is yellow")
  10.  
  11. local attachedMonitor = peripheral.wrap("top")
  12.  
  13. local backgroundColorTable = {
  14.     colors.white;
  15.     colors.lightGray;
  16.     colors.gray;
  17.     colors.black;
  18.     colors.lightBlue;
  19.     colors.blue;
  20.     colors.brown;
  21.     colors.green;
  22. }
  23.  
  24.  
  25. local textColorTable = {
  26.     colors.yellow;
  27.     colors.orange;
  28.     colors.red;
  29.     colors.magenta;
  30.     colors.purple;
  31.     colors.lime;
  32.     colors.cyan;
  33. }
  34.  
  35. local sentence = "The quick colorful fox jumped over the lazy dog"
  36. local backgroundColor,textColor
  37. local width,height
  38.  
  39. -- Break the sentence into a table of words
  40. local wordTable = {}
  41. for word in string.gmatch(sentence,"%w+") do
  42.     table.insert(wordTable, word)
  43. end
  44.  
  45. --set the scale so we can print one word on each line.
  46. for scale = 5,0.5,-0.5 do
  47.     attachedMonitor.setTextScale(scale)
  48.     width,height = attachedMonitor.getSize()
  49.     if height >= #wordTable then
  50.         print("Scale ="..tostring(scale))
  51.         break
  52.     end
  53. end
  54.  
  55. -- scale is set, and we know width and height.
  56.  
  57. -- set a random background color
  58.  
  59. attachedMonitor.setBackgroundColor(backgroundColorTable[math.random(#backgroundColorTable)])
  60. attachedMonitor.clear() -- will repaint monitor background
  61.  
  62. -- For each word, print it on a line in a random background and random text color
  63. for line = 1,#wordTable do
  64.     local word = wordTable[line]
  65.     -- set a random background color
  66.     attachedMonitor.setBackgroundColor(backgroundColorTable[math.random(#backgroundColorTable)])
  67.     -- set a random text color
  68.     attachedMonitor.setTextColor(textColorTable[math.random(#textColorTable)])
  69.     --set a random column for our line position
  70.     attachedMonitor.setCursorPos(math.random(width-#word),line)
  71.     attachedMonitor.write(word)
  72.         sleep(1)
  73. end
  74.  
  75. -- reset monitor colors
  76. attachedMonitor.setBackgroundColor(colors.black)
  77. attachedMonitor.setTextColor(colors.white)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement