Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sizemul = 1
- local txthi = 2
- epoch_mul = 72000
- norm_clr = {255, 255, 255}
- prev_col = nil
- cur_col = norm_clr
- first_time = 1
- local widsize = 80
- local hisize = 10
- hisize = hisize * txthi
- local dedwid = 2
- local dedhi = 5
- os.loadAPI("AndysPrograms/gltime/api/getmnth")
- local mineminute = 60 / 72
- --mineminute = mineminute * 0.999
- local sizediv = 1
- widsize = widsize / sizediv
- hisize = hisize / sizediv
- local scaletsize = sizemul / sizediv
- local canvas = peripheral.wrap("back").canvas()
- canvas.clear() -- Get rid of our previous clock
- local group = canvas.addGroup({ 0, 0 })
- -- Look, we add items to our group instead
- --group.addRectangle(0, 0, widsize, hisize, 0xFF000064)
- local text = group.addText({ 5, 5 }, "")
- local text2 = group.addText({ 5, 5 }, "")
- text.setScale(scaletsize)
- --text.setColour(255,1,255)
- local x, y, dx, dy = 0, 0, 5, 5
- -- Compute the dimensions we can move within
- local width, height = canvas.getSize()
- width = width - widsize
- height = height - hisize
- width = width - dedwid
- height = height - dedhi
- y = height
- trans_time = 15 * 1000000
- trans_time = 5 * epoch_mul
- col_prev_time = 0
- prev_col = {1,1,1}
- function mix(mix_end, mix_start)
- if (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1) > 1 then
- -- term.setCursorPos(1,13)
- -- term.clearLine()
- -- print("done")
- -- term.setCursorPos(1,11)
- -- term.clearLine()
- -- print(mix_end)
- return mix_end
- end
- --local temp_start = mix_start * (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1)
- --local temp_end = mix_end * (1 - (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1))
- local temp_start = mix_start * (1 - (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1))
- local temp_end = mix_end * (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1)
- -- term.setCursorPos(1,7)
- -- term.clearLine()
- -- print(1 - (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1))
- -- term.setCursorPos(1,8)
- -- term.clearLine()
- -- print(os.epoch())
- -- term.setCursorPos(1,9)
- -- term.clearLine()
- -- print(((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1)
- -- term.setCursorPos(1,10)
- -- term.clearLine()
- -- print(temp_start)
- return temp_start + temp_end
- end
- disp_col = {1,1,1}
- function table_to_textcol(tab)
- disp_col = {1,1,1}
- if tab ~= nil then
- prev_col = cur_col
- cur_col = tab
- --prev_col = nil
- col_prev_time = os.epoch()
- end
- if prev_col == nil then
- if tab ~= nil then
- text.setColour(tab[1], tab[2], tab[3])
- prev_col = tab
- end
- end
- if prev_col ~= nil then
- --disp_col[1] = prev_col[1] / (((os.epoch() - (col_prev_time - trans_time)) / trans_time) - 1)
- for i=1,3 do
- disp_col[i] = mix(cur_col[i], prev_col[i])
- end
- if disp_col[1] == nil then
- disp_col = {1,1,1}
- end
- --print(disp_col[1])
- text.setColour(disp_col[1], disp_col[2], disp_col[3])
- term.setCursorPos(1,6)
- --print(disp_col[1])
- end
- end
- prev_time = 0
- loops_gltm = 0
- cur_color = {-1,-1,-1}
- function req_color_change(table)
- istrue = 0
- first_time_do = 1
- while first_time_do == 1 do
- if cur_color[1] ~= table[1] or first_time == 1 then
- if cur_color[2] ~= table[2] or first_time == 1 then
- if cur_color[3] ~= table[3] or first_time == 1 then
- table_to_textcol(table)
- cur_color = table
- --print("true")
- istrue = istrue + 1
- if istrue > 20 then
- istrue = 20
- end
- if istrue >= 2 then
- first_time_do = 0
- first_time = 0
- end
- end
- end
- end
- if first_time == 0 then
- first_time_do = 0
- end
- end
- if istrue == 0 then
- --print("false")
- end
- end
- --req_color_change({1,1,1})
- --req_color_change(norm_clr)
- time_sub = 0
- while true do
- loops_gltm = loops_gltm + 1
- if os.epoch() >= prev_time + (mineminute * (epoch_mul / 8)) - (time_sub * epoch_mul) then
- time_st = os.epoch()
- local _, day, month, _ = getmnth.getmnth()
- print(os.epoch())
- group.setPosition(x, y)
- if true then
- otftim2 = string.gsub(textutils.formatTime( os.time(), true ), ":", "")
- norm_clr = norm_clr
- warn_clr = {252, 136, 3}
- night_clr = {191, 72, 61}
- print(otftim2)
- print(tonumber(otftim2))
- if tonumber(otftim2) >= 1600 and tonumber(otftim2) < 1800 then
- req_color_change(warn_clr)
- elseif tonumber(otftim2) >= 1800 and tonumber(otftim2) <= 2359 then
- req_color_change(night_clr)
- elseif tonumber(otftim2) >= 0 and tonumber(otftim2) <= 600 then
- req_color_change(night_clr)
- else
- req_color_change(norm_clr)
- end
- -- if tonumber(otftim2) % 30 == 0 then
- -- req_color_change(norm_clr)
- -- elseif (tonumber(otftim2) + 15) % 30 == 0 then
- -- req_color_change(night_clr)
- -- end
- end
- -- And update the time
- time_nospace_zero = string.gsub(textutils.formatTime(os.time(), false), " ", " ")
- time_nospace_10error = string.gsub(time_nospace_zero, "0:", "12:")
- time_nospace = string.gsub(time_nospace_10error, "112:", "10:")
- text.setText(time_nospace)
- text2.setText("\n"..day.." "..month)
- if time_en == nil then
- time_sub = 0
- end
- mineminute = 60 / 72
- time_en = os.epoch()
- time_sub = time_en - time_st
- if time_sub < 0 then
- time_sub = time_sub / -1
- end
- mineminute = mineminute - (time_sub / 1000)
- prev_time = os.epoch()
- if prev_time< 0 then
- prev_time = prev_time / -1
- end
- --sleep(mineminute)
- end
- table_to_textcol()
- if loops_gltm >= 50 then
- sleep(0)
- loops_gltm = 0
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement