Stories on maker education and innovation 

Home game based learning Learn how to create a mobile app in minutes using Corona SDK
formats

Learn how to create a mobile app in minutes using Corona SDK

Many of my readers may enjoy learning how they can create apps for their favorite mobile devices: ipad, iphone, or Android.    The Corona SDK provides an elegant framework for quickly creating applications and games.    I have heard stories of middle school students creating rocking games with this tool.    So, I just had to check it out.   In this five minute tutorial, I will walk through the process of creating a simple clock.

Clock


The Corona and Lua community have created an extensive collection of learning resources:

Please let me know if you find this tutorial helpful.

What do you want to build today?

local function drawClock(e)
now = os.date(“*t”) — defaults to current date and time

display_width = display.contentWidth
display_height = display.contentHeight

local background = display.newRect(0, 0, display_width, display_height)
background.strokeWidth = 3
background:setFillColor(20, 20, 20)
background:setStrokeColor(180, 180, 180)

— draw circle
center_x = display_width / 2
center_y = display_height / 2
clock_radius = display_width /2

local myCircle = display.newCircle( center_x, center_y, clock_radius)
myCircle:setFillColor(128,128,128)

— draw hours hand
hour = now.hour
print(hour)
degree = -3.14/2 + (3.14*2/12)*hour
hours_x = center_x + (clock_radius-50) * math.cos(degree)
hours_y = center_y + (clock_radius-50) * math.sin(degree)
local hours_line = display.newLine( center_x,center_y, hours_x,hours_y )
hours_line:setColor( 0, 102, 102, 255 )
hours_line.width = 5

— draw minutes hand
minute = now.min
degree = -3.14/2 + (3.14*2/60)*minute
min_x = center_x + (clock_radius-10) * math.cos(degree)
min_y = center_y + (clock_radius-10) * math.sin(degree)
local min_line = display.newLine( center_x,center_y, min_x,min_y )
min_line:setColor( 255, 102, 102, 255 )
min_line.width = 5

— draw second hand
second = now.sec
degree = -3.14/2 + (3.14*2/60)*second
sec_x = center_x + (clock_radius-10) * math.cos(degree)
sec_y = center_y + (clock_radius-10) * math.sin(degree)
local sec_line = display.newLine( center_x,center_y, sec_x,sec_y )
sec_line:setColor( 1, 1, 1, 255 )
sec_line.width = 5
end

timer.performWithDelay(1000, drawClock, 0)

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
2 Comments  comments 
  • Tim Haut

    cool michael! i just wanted to also see it in action though.

    • michaelprosario

      Glad that you liked it. I’ll see if I can record a video of it running on my phone. If you’d like to learn more about the process of using Corona, I would check out the other YouTube videos on http://www.learningcorona.com/ . Are you interested in making apps? What are you thinking about making?

© Inspired To Educate
credit