Advertisement
Impshial

Random Text Colors

Oct 2nd, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. -- Random Text colors
  2. -- Set monitor
  3. mon=peripheral.wrap("right")
  4.  
  5. -- Set main text color
  6. mon.setTextColor(colors.white)
  7.  
  8. -- Wipe monitor
  9. mon.clear()
  10.  
  11. -- Set cursor at top-left position
  12. mon.setCursorPos(1,1)
  13.  
  14. -- Big!
  15. mon.setTextScale(3)
  16. mon.write("Bug's")
  17.  
  18. -- Do the same with bottom line of text
  19. mon.setTextColor(colors.white)
  20. mon.setCursorPos(1,3)
  21. mon.write("Shop")
  22.  
  23. -- Local variable
  24. local color = 1
  25.  
  26. -- Randomize the seed based on Operating System's time
  27. math.randomseed(os.time())
  28.  
  29. -- Main loop
  30.  
  31. while true do
  32.  
  33. -- "D"
  34.  
  35.   -- Second line, first letter
  36.   mon.setCursorPos(1,2)
  37.  
  38.   -- Get random number for our color
  39.   -- Ignore if zero, we don't want white, and only go to 14 so we don't get black
  40.  
  41.   color=math.random(14)
  42.  
  43.   if color > 0 then
  44.     mon.setTextColor(2^color)
  45.     mon.write("D")
  46.   end
  47.  
  48. -- Do the same for last 2 letters  
  49. -- "y"
  50.  
  51.   mon.setCursorPos(2,2)
  52.      
  53.   color=math.random(14)
  54.  
  55.   if color > 0 then
  56.     mon.setTextColor(2^color)
  57.     mon.write("y")
  58.   end
  59.  
  60. -- "e"
  61.   mon.setCursorPos(3,2)
  62.      
  63.   color=math.random(14)
  64.  
  65.   if color > 0 then
  66.     mon.setTextColor(2^color)
  67.     mon.write("e")
  68.   end
  69.  
  70. -- Wait for 0.1 seconds before doing another set of colors  
  71.   sleep(0.1)
  72.  
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement