EnterYourName

CCDisplay

Sep 23rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. local monitor = peripheral.wrap( "right" )
  2.  
  3. function writeCentered (dy, text, device)
  4. local w,h = device.getSize()
  5. local x = math.floor((w - string.len(text)) / 2)+1
  6. local y = math.floor(h/2) + dy
  7. device.setCursorPos(x,y)
  8. device.clearLine()
  9. device.write(text)
  10. end
  11.  
  12. function writeCenteredInLine (y, text, device)
  13. local w,h = device.getSize()
  14. local x = math.floor((w - string.len(text)) / 2)+1
  15. device.setCursorPos(x,y)
  16. device.clearLine()
  17. device.write(text)
  18. end
  19.  
  20. function getTime()
  21.  
  22. local time = os.time()
  23. return textutils.formatTime(time, false)
  24.  
  25. end
  26.  
  27. function adjustTextScale(device)
  28.  
  29. device.setTextScale(1)
  30. local w,h = device.getSize()
  31. local scale = 1
  32. while w > 12 do
  33. scale = scale+1
  34. device.setTextScale(scale)
  35. w, h = device.getSize()
  36. end
  37.  
  38. end
  39.  
  40. adjustTextScale(monitor)
  41. monitor.setBackgroundColor(colors.black)
  42. monitor.clear()
  43. monitor.setBackgroundColor(colors.black)
  44.  
  45. while true do
  46.  
  47. writeCentered(1,getTime(),monitor)
  48. sleep(0.1)
  49.  
  50. end
Add Comment
Please, Sign In to add comment