Advertisement
Mlntcandy

bigtime.lua

Dec 18th, 2021
1,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.10 KB | None | 0 0
  1. args = {...}
  2. monitor = peripheral.find("monitor")
  3. digitColor = "0"
  4. bgColor = "f"
  5.  
  6.  
  7. function blitBg(matrixSlice)
  8.     local x, y = monitor.getCursorPos()
  9.     matrixSlice = matrixSlice:gsub(" ", bgColor)
  10.     matrixSlice = matrixSlice:gsub("0", digitColor)
  11.     local msLen = matrixSlice:len()
  12.     local fillerText = string.rep(" ", msLen)
  13.     local fillerTextColor = string.rep("0", msLen)
  14.     monitor.blit(fillerText, fillerTextColor, matrixSlice)
  15.     monitor.setCursorPos(x, y + 1)
  16. end
  17.  
  18. function blitDigit(digit)
  19.     local x, y = monitor.getCursorPos()
  20.     if digit == "0" then
  21.         blitBg(" 000 ")
  22.         blitBg("0   0")
  23.         blitBg("0   0")
  24.         blitBg("0   0")
  25.         blitBg(" 000 ")
  26.     elseif digit == "1" then
  27.         blitBg("  0  ")
  28.         blitBg(" 00  ")
  29.         blitBg("  0  ")
  30.         blitBg("  0  ")
  31.         blitBg("00000")
  32.     elseif digit == "2" then
  33.         blitBg(" 000 ")
  34.         blitBg("0   0")
  35.         blitBg("   0 ")
  36.         blitBg(" 00  ")
  37.         blitBg("00000")
  38.     elseif digit == "3" then
  39.         blitBg(" 000 ")
  40.         blitBg("0   0")
  41.         blitBg("   0 ")
  42.         blitBg("0   0")
  43.         blitBg(" 000 ")
  44.     elseif digit == "4" then
  45.         blitBg("  00 ")
  46.         blitBg(" 0 0 ")
  47.         blitBg("0  0 ")
  48.         blitBg("00000")
  49.         blitBg("   0 ")
  50.     elseif digit == "5" then
  51.         blitBg("00000")
  52.         blitBg("0    ")
  53.         blitBg("0000 ")
  54.         blitBg("    0")
  55.         blitBg("0000 ")
  56.     elseif digit == "6" then
  57.         blitBg(" 000 ")
  58.         blitBg("0    ")
  59.         blitBg("0000 ")
  60.         blitBg("0   0")
  61.         blitBg(" 000 ")
  62.     elseif digit == "7" then
  63.         blitBg("00000")
  64.         blitBg("    0")
  65.         blitBg("   0 ")
  66.         blitBg("  0  ")
  67.         blitBg("  0  ")
  68.     elseif digit == "8" then
  69.         blitBg(" 000 ")
  70.         blitBg("0   0")
  71.         blitBg(" 000 ")
  72.         blitBg("0   0")
  73.         blitBg(" 000 ")
  74.     elseif digit == "9" then
  75.         blitBg(" 000 ")
  76.         blitBg("0   0")
  77.         blitBg(" 0000")
  78.         blitBg("    0")
  79.         blitBg(" 000 ")
  80.     elseif digit == ":" then
  81.         blitBg("   ")
  82.         blitBg(" 0 ")
  83.         blitBg("   ")
  84.         blitBg(" 0 ")
  85.         blitBg("   ")
  86.     end
  87.     if digit == ":" then
  88.         monitor.setCursorPos(x + 4, y)
  89.     else
  90.         monitor.setCursorPos(x + 6, y)
  91.     end
  92. end
  93.  
  94. function gameTime()
  95.     time = os.time("ingame")
  96.     h = math.floor(time)
  97.     if math.floor(h / 10) == 0 then
  98.         h = '0'..h
  99.     end
  100.     m = math.floor((time - h)*60)
  101.     if math.floor(m / 10) == 0 then
  102.         m = '0'..m
  103.     end
  104.     return (h..':'..m)
  105. end
  106.  
  107. function irlTime()
  108.     time = os.time("utc")
  109.     h = math.floor(time)
  110.     if math.floor(h / 10) == 0 then
  111.         h = '0'..h
  112.     end
  113.     m = math.floor((time - h)*60)
  114.     if math.floor(m / 10) == 0 then
  115.         m = '0'..m
  116.     end
  117.     h = h + 3
  118.     if h > 23 then
  119.         h = h - 24
  120.     end
  121.     return (h..':'..m)
  122. end
  123.  
  124. function getTOD()
  125.     time = os.time("ingame")
  126.     if time < 4 then
  127.         return "night"
  128.     elseif time < 6 then
  129.         return "early morning"
  130.     elseif time < 11 then
  131.         return "morning"
  132.     elseif time < 13 then
  133.         return "noon"
  134.     elseif time < 17 then
  135.         return "afternoon"
  136.     elseif time < 20 then
  137.         return "early evening"
  138.     elseif time < 22 then
  139.         return "evening"
  140.     elseif time > 22 then
  141.         return "late evening"
  142.     end
  143. end
  144.  
  145.  
  146. cycle = true
  147. while cycle do
  148.     if args[1] == "test" then
  149.         cycle = false
  150.     end
  151.     monitor.clear()
  152.     monitor.setTextScale(1)
  153.     local width, heigth = monitor.getSize()
  154.     local centerX = math.floor(width/2) + 1
  155.     local centerY = math.floor(heigth/2)
  156.     monitor.setCursorPos(centerX - 13, centerY - 4)
  157.     gameTime():gsub(".", blitDigit)
  158.     local tod = getTOD()
  159.     monitor.setCursorPos(centerX - math.floor(tod:len() / 2), centerY + 3)
  160.     monitor.write(tod)
  161.     monitor.setTextColor(colors.gray)
  162.     local irl = irlTime().." in Moscow"
  163.     monitor.setCursorPos(centerX - math.floor(irl:len() / 2), centerY + 5)
  164.     monitor.write(irl)
  165.     sleep(0.4)
  166. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement