Advertisement
BruceWplays

GLTime V2

Oct 11th, 2022 (edited)
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.74 KB | None | 0 0
  1.     local sizemul = 1
  2.  
  3.  
  4.  
  5.     local txthi = 2
  6.  
  7. epoch_mul = 72000
  8. norm_clr = {255, 255, 255}
  9. prev_col = nil
  10. cur_col = norm_clr
  11. first_time = 1
  12.     local widsize = 80
  13.     local hisize = 10
  14.  
  15.     hisize = hisize * txthi
  16.     local dedwid = 2
  17.     local dedhi = 5
  18.  
  19.     os.loadAPI("AndysPrograms/gltime/api/getmnth")
  20.  
  21.     local mineminute = 60 / 72
  22.     --mineminute = mineminute * 0.999
  23.     local sizediv = 1
  24.     widsize = widsize / sizediv
  25.     hisize = hisize / sizediv
  26.     local scaletsize = sizemul / sizediv
  27.  
  28.     local canvas = peripheral.wrap("back").canvas()
  29.     canvas.clear() -- Get rid of our previous clock
  30.  
  31.     local group = canvas.addGroup({ 0, 0 })
  32.  
  33.     -- Look, we add items to our group instead
  34.     --group.addRectangle(0, 0, widsize, hisize, 0xFF000064)
  35.  
  36.     local text = group.addText({ 5, 5 }, "")
  37.     local text2 = group.addText({ 5, 5 }, "")
  38.     text.setScale(scaletsize)
  39.     --text.setColour(255,1,255)
  40.  
  41.     local x, y, dx, dy = 0, 0, 5, 5
  42.  
  43.     -- Compute the dimensions we can move within
  44.     local width, height = canvas.getSize()
  45.     width = width - widsize
  46.     height = height - hisize
  47.     width = width - dedwid
  48.     height = height - dedhi
  49.     y = height
  50.  
  51. trans_time = 15 * 1000000
  52. trans_time = 5 * epoch_mul
  53. col_prev_time = 0
  54. prev_col = {1,1,1}
  55. function mix(mix_end, mix_start)
  56.     if (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1) > 1 then
  57.         -- term.setCursorPos(1,13)
  58.         -- term.clearLine()
  59.         -- print("done")
  60.         -- term.setCursorPos(1,11)
  61.         -- term.clearLine()
  62.         -- print(mix_end)
  63.         return mix_end
  64.     end
  65.  
  66.     --local temp_start = mix_start * (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1)
  67.     --local temp_end = mix_end * (1 - (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1))
  68.    
  69.     local temp_start = mix_start * (1 - (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1))
  70.     local temp_end = mix_end * (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1)
  71.     -- term.setCursorPos(1,7)
  72.     -- term.clearLine()
  73.     -- print(1 - (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1))
  74.     -- term.setCursorPos(1,8)
  75.     -- term.clearLine()
  76.     -- print(os.epoch())
  77.  
  78.     -- term.setCursorPos(1,9)
  79.     -- term.clearLine()
  80.     -- print(((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1)
  81.     -- term.setCursorPos(1,10)
  82.     -- term.clearLine()
  83.     -- print(temp_start)
  84.     return temp_start + temp_end
  85. end
  86.  
  87. disp_col = {1,1,1}
  88. function table_to_textcol(tab)
  89.     disp_col = {1,1,1}
  90.     if tab ~= nil then
  91.         prev_col = cur_col
  92.         cur_col = tab
  93.         --prev_col = nil
  94.         col_prev_time = os.epoch()
  95.     end
  96.     if prev_col == nil then
  97.         if tab ~= nil then
  98.             text.setColour(tab[1], tab[2], tab[3])
  99.             prev_col = tab
  100.         end
  101.     end
  102.    
  103.     if prev_col ~= nil then
  104.         --disp_col[1] = prev_col[1] / (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1)
  105.         for i=1,3 do
  106.             disp_col[i] = mix(cur_col[i], prev_col[i])
  107.         end
  108.         if disp_col[1] == nil then
  109.             disp_col = {1,1,1}
  110.         end
  111.         --print(disp_col[1])
  112.         text.setColour(disp_col[1], disp_col[2], disp_col[3])
  113.         term.setCursorPos(1,6)
  114.         --print(disp_col[1])
  115.     end
  116.  
  117.  
  118.    
  119. end
  120. prev_time = 0
  121. loops_gltm = 0
  122. cur_color = {-1,-1,-1}
  123.  
  124. function req_color_change(table)
  125.     istrue = 0
  126.     first_time_do = 1
  127.     while first_time_do == 1 do
  128.         if cur_color[1] ~= table[1] or first_time == 1 then
  129.             if cur_color[2] ~= table[2] or first_time == 1 then
  130.                 if cur_color[3] ~= table[3] or first_time == 1 then
  131.                     table_to_textcol(table)
  132.                     cur_color = table
  133.                     --print("true")
  134.                     istrue = istrue + 1
  135.                     if istrue > 20 then
  136.                         istrue = 20
  137.                     end
  138.                     if istrue >= 2 then
  139.                         first_time_do = 0
  140.                         first_time = 0
  141.                     end
  142.                 end
  143.             end
  144.  
  145.         end
  146.         if first_time == 0 then
  147.             first_time_do = 0
  148.         end
  149.     end
  150.    
  151.     if istrue == 0 then
  152.         --print("false")
  153.     end
  154. end
  155.  
  156. --req_color_change({1,1,1})
  157. --req_color_change(norm_clr)
  158.  
  159. time_sub = 0
  160.     while true do
  161.         loops_gltm = loops_gltm + 1
  162.         if os.epoch() >= prev_time + (mineminute * (epoch_mul / 8)) - (time_sub * epoch_mul) then
  163.             time_st = os.epoch()
  164.  
  165.             local _, day, month, _ = getmnth.getmnth()
  166.             print(os.epoch())
  167.             group.setPosition(x, y)
  168.  
  169.             if true then
  170.                 otftim2 = string.gsub(textutils.formatTime( os.time(), true ), ":", "")
  171.                 norm_clr = norm_clr
  172.                 warn_clr = {252, 136, 3}
  173.                 night_clr = {191, 72, 61}
  174.                 print(otftim2)
  175.                 print(tonumber(otftim2))
  176.  
  177.                 if tonumber(otftim2) >= 1600 and tonumber(otftim2) < 1800 then
  178.                     req_color_change(warn_clr)
  179.                 elseif tonumber(otftim2) >= 1800 and tonumber(otftim2) <= 2359 then
  180.                     req_color_change(night_clr)
  181.                 elseif tonumber(otftim2) >= 0 and tonumber(otftim2) <= 600 then
  182.                     req_color_change(night_clr)
  183.                 else
  184.                     req_color_change(norm_clr)
  185.                 end
  186.  
  187.                 -- if tonumber(otftim2) % 30 == 0 then
  188.                 --     req_color_change(norm_clr)
  189.                 -- elseif (tonumber(otftim2) + 15) % 30 == 0 then
  190.                 --     req_color_change(night_clr)
  191.                 -- end
  192.  
  193.             end
  194.             -- And update the time
  195.  
  196.             time_nospace_zero = string.gsub(textutils.formatTime(os.time(), false), " ", " ")  
  197.             time_nospace_10error = string.gsub(time_nospace_zero, "0:", "12:")
  198.             time_nospace = string.gsub(time_nospace_10error, "112:", "10:")
  199.  
  200.             text.setText(time_nospace)
  201.             text2.setText("\n"..day.." "..month)
  202.             if time_en == nil then
  203.                 time_sub = 0
  204.             end
  205.             mineminute = 60 / 72
  206.             time_en = os.epoch()
  207.             time_sub = time_en - time_st
  208.             if time_sub < 0 then
  209.                 time_sub = time_sub / -1
  210.             end
  211.             mineminute = mineminute - (time_sub / 1000)
  212.             prev_time = os.epoch()
  213.             if prev_time< 0 then
  214.                 prev_time = prev_time / -1
  215.             end
  216.             --sleep(mineminute)
  217.         end
  218.         table_to_textcol()
  219.         if loops_gltm >= 50 then
  220.             sleep(0)
  221.             loops_gltm = 0
  222.         end
  223.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement