Here is a clock in less than 50 lines of code using SSK2 (which is now free).
https://www.youtube.com/watch?v=4dYM5gdoZMw&feature=youtu.be
Code for this example (w/o SSK 2): https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/06/clock.zip
SSK2 Docs: https://roaminggamer.github.io/RGDocs/pages/SSK2/
SSK2 GitHub: https://github.com/roaminggamer/SSK2
You can easily convert this to raw Corona, by:
-
Reading the code carefully and using standard corona calls for the rectangles.
-
Use your own 2d math code or someone else’s.
-
Use standard Runtime:* calls instead of listen:* shorthand equivalent.
However I suggest at least using my (SSK2) 2d math library.
io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- ============================================================= require "ssk2.loadSSK" \_G.ssk.init() -- Localizations local newRect = ssk.display.newRect local newCircle = ssk.display.newCircle local angle2Vector = ssk.math2d.angle2Vector local scaleVec = ssk.math2d.scale local mFloor = math.floor -- ============================================================= -- Example Begins - Uses SSK2 library! -- ============================================================= local clockGroup = display.newGroup() clockGroup.x = centerX clockGroup.y = centerY -- Draw Dial Marks local degPerTick = 360/12 for i = 1, 12 do local vec = angle2Vector( (i-1) \* degPerTick, true ) vec = scaleVec( vec, 270 ) newRect( clockGroup, vec.x, vec.y, { w = 8, h = 24, rotation = (i-1) \* degPerTick} ) end local back = newRect( nil, centerX, centerY, { w = fullw, h = fullh, fill = \_B\_, alpha = 0.15 } ) local hourHand = newRect( clockGroup, 0, 0, { w = 32, h = 180, anchorY = 1, fill = \_W\_ } ) local minHand = newRect( clockGroup, 0, 0, { w = 16, h = 220, anchorY = 1, fill = \_LIGHTGREY\_ } ) local secHand = newRect( clockGroup, 0, 0, { w = 6, h = 240, anchorY = 1, fill = \_GREY\_ } ) local dialCenter = newCircle( clockGroup, 0, 0, { radius = 40, stroke = \_DARKERGREY\_, strokeWidth = 6 } ) function back.enterFrame( self ) local tt = os.date("\*t") hourHand.rotation = tt.hour \* 360/12 minHand.rotation = tt.min \* 360/60 secHand.rotation = mFloor( tt.sec \* 360/60 ) end; listen( "enterFrame", back ) local timeTable = os.date("\*t") table.dump(timeTable)