Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local handLength = args[1] or 15
- local function round(n)
- return math.floor(n + 1)
- end
- local function setColor(color)
- if term.isColor() then
- term.setTextColor(color)
- end
- end
- local function drawClock()
- local w,h = term.getSize()
- local cx, cy = w/2, h/2
- term.clear()
- local setPos = term.setCursorPos
- for i=1, 12 do
- local x,y =
- math.sin(i/12 * math.pi*2)*handLength,
- -math.cos(i/12 * math.pi*2)*handLength * (4/7)
- setPos(round(cx + x),round(cy + y))
- setColor(colors.lightBlue)
- write(i)
- end
- setPos(cx + 1, cy + 1)
- setColor(colors.white)
- write '*'
- local function drawHand(r)
- local char = '.'
- for i=2, round(handLength/3), 2 do
- local x,y =
- math.sin(r * math.pi*2)*i,
- -math.cos(r * math.pi*2)*i
- setPos(round(cx + x), round(cy + y))
- write(char)
- end
- end
- local hours = os.time()
- local minutes = hours%2
- setColor(colors.lime)
- drawHand(hours*2/24)
- setColor(colors.magenta)
- drawHand(minutes/2)
- setPos(w-5, h)
- if hours >= 0 and hours < 12 then
- setColor(colors.orange)
- write 'AM'
- setColor(colors.gray)
- write '/PM'
- else
- setColor(colors.gray)
- write 'AM/'
- setColor(colors.lightBlue)
- write 'PM'
- end
- end
- while true do
- drawClock()
- sleep(0.05)
- end
Advertisement
Add Comment
Please, Sign In to add comment