Advertisement
Symmetryc

Scroll

Feb 16th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. -- Scroll, by Symmetryc
  2. -- Edit the following variables to
  3. -- change how the program behaves
  4.  
  5. -- Change the scrolling text with this
  6. local str = "Example text"
  7.  
  8. -- Change the speed that the text scrolls
  9. -- With this (higher is faster)
  10. local speed = 1
  11.  
  12. -- Change the side of the monitor with this
  13. local side = "right"
  14.  
  15. -- Change text scale
  16. local scale = 1
  17.  
  18. -- Change the text and back colors
  19. local textcolor = colors.white
  20. local backcolor = colors.lime
  21.  
  22. --###### Actual program ######
  23.  
  24. local mon = peripheral.wrap(side)
  25. mon.setTextScale(scale)
  26. mon.setTextColor(textcolor)
  27. mon.setBackgroundColor(backcolor)
  28.  
  29. local max_x, max_y = mon.getSize()
  30. assert(max_x > #str, "String too large")
  31.  
  32. str = str..(" "):rep(max_x - #str)
  33.  
  34. local text_pos = 0
  35. local pos_y = math.ceil(max_y / 2)
  36.  
  37. mon.clear()
  38. while true do
  39.     mon.setCursorPos(1, pos_y)
  40.     mon.write(str:sub(text_pos + 1)..str:sub(1, text_pos))
  41.     text_pos = text_pos == max_x - 1 and 0 or text_pos + 1
  42.     sleep(1 / speed)
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement