timerTicking = false
screenW, screenH = platform.window:width(), platform.window:height()
unitLen = screenW/4
len = 1
ax = 0
ay = 0
angleIni = 3.1
velIni = 0
radiusPend = screenW/30
x0 = screenW/2
y0 = screenH/2
xP = x0+unitLen*len*math.sin(angleIni)
yP = y0+unitLen*len*math.cos(angleIni)
step = 0.01
elapsedTime = 0
function on.paint(gc)
drawPend(x0, y0, xP, yP, radiusPend, gc)
gc:drawString(round(elapsedTime, 2), 1, 1)
platform.window:invalidate()
end
function on.timer()
var.store("len" , len)
var.store("ax" , ax)
var.store("ay" , ay)
var.store("angleini", angleIni)
var.store("velini" , velIni)
var.store("step" , step)
local temp = math.eval("pend(len, ax, ay, angleini, velini, step)")
angleIni = temp[1]
velIni = temp[2]
xP = temp[3] * unitLen + x0
yP = temp[4] * unitLen + y0
elapsedTime = elapsedTime + step
platform.window:invalidate()
end
function on.enterKey()
if timerTicking == false then timer.start(step) timerTicking = true
elseif timerTicking == true then timer.stop() timerTicking = false
end
end
function drawPend(x0, y0, x1, y1, radius, gc)
gc:drawLine(x0, y0, x1, y1)
gc:fillArc(x1 - radius, y1 - radius, radius + radius, radius + radius, 0, 360)
end
function round(number, digits)
return math.eval("round("..number..", "..digits..")")
end