-- line lengths
local rClock = 30 -- clock disc radius
local rHour = 16
local rMinute = 20
local rSecond = 25
graphics.addDrawFunc("drawClock()", 0)
function drawClock()
-- setting user friendly variables
local mouseX = getCursorPos().x
local mouseY = getCursorPos().y
-- Clock circle
-- !!! this is high CPU load solution! Just think about global warming. Or not.
-- But it's anyways ugly looking and just for demonstration purposes. Use Sprites!
for i = 1, 360 do
local angle = i * math.pi / 180
graphics.drawLine(mouseX, mouseY, mouseX+rClock*math.cos(angle), mouseY+rClock*math.sin(angle), colorRGB(40,80,170), 0.85)
end
-- getting computer time
local timePC = os.date("*t")
-- converting to 12hour format
local hourNow = timePC.hour
if hourNow > 12 then hourNow = hourNow - 12 end
-- drawing clock hands
local angleHour = (hourNow * 30 - 90) * math.pi / 180
graphics.drawLine(mouseX, mouseY, mouseX+rHour*math.cos(angleHour), mouseY+rHour*math.sin(angleHour), 000, 1.0)
local angleMinute = (timePC.min*3 -45) * math.pi / 90
graphics.drawLine(mouseX, mouseY, mouseX+rMinute*math.cos(angleMinute), mouseY+rMinute*math.sin(angleMinute), colorRGB(160,160,160), 1.0)
local angleSecond = (timePC.sec*3 -45) * math.pi / 90
graphics.drawLine(mouseX, mouseY, mouseX+rSecond*math.cos(angleSecond), mouseY+rSecond*math.sin(angleSecond), colorRGB(255,255,255), 1.0)
end