Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. local monitor = peripheral.find( "left", function( id, obj )
  2. return obj.isColor() -- filter for color monitors
  3. end )
  4.  
  5. local w, h = monitor.getSize() -- width, height
  6. local e, time = {}, nil
  7. local fg, bg = 1, 2 -- text and bg colors and color
  8.  
  9. monitor.setBackgroundColor( bg )
  10. monitor.setTextColor( fg )
  11. monitor.clear()
  12.  
  13. -- main loop
  14. while e[1] ~= "key" and e[2] ~= keys.q do -- hit 'q' to exit
  15.  
  16. os.startTimer( 1 )
  17. time = textutils.formatTime( os.time(), false )
  18. local x, y = math.floor( (w - #time) / 2 + .5 ), math.floor( h / 2 + .5 )
  19. monitor.setCursorPos( 1, y )
  20. time = x > 0 and string.rep(" ", x-1) .. time .. " " or time
  21. monitor.write(time)
  22. e = { os.pullEvent() }
  23. if e[1] == "monitor_touch" then -- hit the text or bg to cycle the colors of the display
  24. if e[3] >= x and e[3] <= x + #time and e[4] == y then
  25. fg = fg < 32768 and fg * 2 or 1
  26. monitor.setTextColor( fg )
  27. else
  28. bg = bg < 32768 and bg * 2 or 1
  29. monitor.setBackgroundColor( bg )
  30. monitor.clear()
  31. end
  32. end
  33.  
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement