Advertisement
Zantag

Clock Display

Jun 12th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. imgWidth = 71
  2. imgHeight = 33
  3. if fs.exists("clocks") then
  4. imgs = paintutils.loadImage("clocks")
  5. else
  6. shell.run("pastebin get NkF2vfMN clocks")
  7. --Assumes you have http enabled
  8. imgs = paintutils.loadImage("clocks")
  9. end
  10. local function readLines(sPath)
  11. local file = fs.open(sPath, "r")
  12. if file then
  13. local tLines = {}
  14. local sLine = file.readLine()
  15. while sLine do
  16. table.insert(tLines, sLine)
  17. sLine = file.readLine()
  18. end
  19. file.close()
  20. return tLines
  21. end
  22. return nil
  23. end
  24.  
  25. function drawImg(index, x,y, dark)
  26. index = index - 1
  27. curY = 0
  28. for yy = index*imgHeight+1, (index+1)*imgHeight do
  29. for xx = 1, imgWidth do
  30. color = imgs[yy][xx]
  31. if not dark then
  32. if color == '0' then
  33. color = 'F'
  34. end
  35. if color == 'b' then
  36. color = '0'
  37. end
  38. end
  39. paintutils.drawPixel(x+xx-1, y+curY, color)
  40. end
  41. curY = curY + 1
  42. end
  43. end
  44. mon = peripheral.wrap("back")
  45. term.redirect(mon)
  46. term.clear()
  47.  
  48.  
  49. function toint(n)
  50. local s = tostring(n)
  51. local i, j = s:find('%.')
  52. if i then
  53. return tonumber(s:sub(1, i-1))
  54. else
  55. return n
  56. end
  57. end
  58. function main()
  59. while true do
  60. local time = os.time()
  61. local hour = toint(time)
  62. if hour > 12 then
  63. hour = hour - 12
  64. end
  65. drawImg(hour, 1,1, hour <= 7 or hour >= 19)
  66. os.sleep(4)
  67. end
  68. end
  69.  
  70. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement