Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _, err = pcall(function()
- local timezones = {
- {'America/Los_Angeles', 'Los Angeles', 0},
- {'Europe/London', 'London', 0},
- {'Australia/Adelaide', 'Adelaide', 0},
- {'Pacific/Auckland', 'Auckland', 0}
- }
- -- Thanks tobit for this
- function drawCircle( centerX, centerY, radius, col, solid )
- solid = solid or false
- local isAdvanced = term.isColor and term.isColor()
- local char = isAdvanced and " " or "|"
- if isAdvanced then term.setBackgroundColor( col ) end
- local radStep = 1/(1.5*radius)
- for angle = 1, math.pi+radStep, radStep do
- local pX = math.cos( angle ) * radius * 1.5
- local pY = math.sin( angle ) * radius
- if solid then
- local chord = 2*math.abs(pX)
- term.setCursorPos( centerX - chord/2, centerY - pY )
- write( char:rep( chord ) )
- term.setCursorPos( centerX - chord/2, centerY + pY )
- write( char:rep( chord ) )
- else
- for i=-1,1,2 do
- for j=-1,1,2 do
- term.setCursorPos( centerX + i*pX, centerY + j*pY )
- write( char )
- end
- end
- end
- end
- end
- local function drawClock(timezone)
- local night = false
- local time = timezones[timezone][3]
- if time <= 6 or time >= 18 then
- night = true
- end
- local w, h = term.getSize()
- term.setBackgroundColour(colours.black)
- term.clear()
- local centerX, centerY = math.ceil(w/2)+1, math.ceil(h/2)
- drawCircle(centerX, centerY, math.ceil(h/2), (night and colours.grey or colours.white), true)
- for i = 0, 11 do
- local minDeg = i * 2 * math.pi / 12
- hyp1 = math.ceil(h/2) - 1
- _w1 = math.cos(minDeg) * hyp1 * 1.5
- _h1 = math.sin(minDeg) * hyp1
- hyp2 = math.ceil(h/2) - 4
- _w2 = math.cos(minDeg) * hyp2 * 1.5
- _h2 = math.sin(minDeg) * hyp2
- paintutils.drawLine(centerX + _w1, centerY + _h1, centerX + _w2, centerY + _h2, colours.lightGrey)
- end
- local hour = time % 12
- local minute = math.floor((time - math.floor(time))*60)
- local hourDeg = hour * 2 * math.pi / 12 - math.pi/2
- local hyp = math.ceil(h/2) - 6
- local _w = math.cos(hourDeg) * hyp * 1.5
- local _h = math.sin(hourDeg) * hyp
- paintutils.drawLine(centerX, centerY, centerX + _w, centerY + _h, (night and colours.white or colours.black))
- local minDeg = minute * 2 * math.pi / 60 - math.pi/2
- hyp = math.ceil(h/2) - 3
- _w = math.cos(minDeg) * hyp * 1.5
- _h = math.sin(minDeg) * hyp
- paintutils.drawLine(centerX, centerY, centerX + _w, centerY + _h, colours.red)
- end
- local monitors = {}
- local sides = {'front','right', 'back', 'left'}
- for i, v in ipairs(sides) do
- if peripheral.getType(v) == 'modem' then
- local tRemote = peripheral.call( v, "getNamesRemote" )
- monitors[i] = {}
- for i2, name in ipairs(tRemote) do
- if peripheral.getType(name) == 'monitor' then
- local m = peripheral.wrap(name)
- local w,h = m.getSize()
- if h == 40 then
- monitors[i][1] = m
- else
- monitors[i][2] = m
- m.setTextScale(4)
- end
- end
- end
- end
- end
- local function drawTimezone(i)
- local w, h = term.getSize()
- term.setBackgroundColour(colours.black)
- term.clear()
- local name = timezones[i][2]
- term.setCursorPos(math.ceil((w - #name)/2) + 1, 1)
- term.write(name)
- end
- local function updateTimes()
- os.startTimer(60)
- for i, v in ipairs(timezones) do
- v[3] = v[3] + 1/60
- end
- end
- local function downloadTimes()
- for i, v in ipairs(timezones) do
- local h = http.get('http://api.timezonedb.com/?zone='..v[1]..'&key=ASEPIBTKXXQA')
- local s = h.readAll()
- local t = s:match('<timestamp>(%d+)</timestamp>')
- v[3] = (t/60/60)%24
- print('Downloaded: '..v[2] .. ' ('..v[3]..')')
- end
- os.setAlarm(0)
- end
- downloadTimes()
- os.startTimer(60)
- os.queueEvent('draw')
- while true do
- local event, detail = os.pullEvent()
- if event == 'alarm' then
- downloadTimes()
- elseif event == 'timer' then
- updateTimes()
- elseif event == 'char' and detail == '\\' then
- os.reboot()
- end
- for i, v in ipairs(monitors) do
- term.redirect(v[2])
- drawTimezone(i)
- term.redirect(v[1])
- drawClock(i)
- end
- term.redirect(term.native())
- end
- end)
- if err then
- term.redirect(term.native())
- printError(err)
- os.startTimer(5)
- print('Press any key to cancel reboot.')
- local ev = os.pullEvent()
- if ev == 'timer' then
- os.reboot()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement