platform.apilevel = "2.4"
local slateblue = 0x7171C6
local salmon = 0xC67171
local brightgray = 0xC5C1AA
local lightsteelblue = 0xCAE1FF
local dodgerblue = 0x104E8B
platform.window:setBackgroundColor(dodgerblue)
local time = 0
local step = 0.1
function on.resize()
w, h = platform.window:width(), platform.window:height()
x0, y0 = w/5, h/2
unit = h/10
radius_center = h/20
dia_center = radius_center * 2
radius_sat = h/40
dia_sat = radius_sat * 2
fontSize = math.floor(h/17)
end
var.store("gm", 9.8)
var.store("tstart", 0)
var.store("tstop", step)
var.store("ini_lx", -1)
var.store("ini_vx", 0)
var.store("ini_ly", 0)
var.store("ini_vy", 4.2)
var.store("step", step)
var.store("tol", 0.001)
function drawCircle(x, y, radius, dia, color, gc)
gc:setColorRGB(color)
gc:fillArc(x - radius, y - radius, dia, dia, 0, 360)
end
function on.paint(gc)
gc:setPen("thin")
gc:setFont("sansserif", "r", fontSize)
mat = math.eval("satellite(gm, tstart, tstop, ini_lx, ini_vx, ini_ly, ini_vy, step, tol)")
x1 = x0 + unit * mat[2][1]
y1 = y0 - unit * mat[4][1]
gc:setColorRGB(slateblue)
gc:drawLine(x0, y0, x1, y1)
drawCircle(x1, y1, radius_sat, dia_sat, lightsteelblue, gc)
drawCircle(x0, y0, radius_center, dia_center, salmon, gc)
gc:setColorRGB(brightgray)
gc:drawString("time = "..math.floor(time).." s", fontSize, fontSize)
end
function on.enterKey()
timer.start(0.01)
end
function on.escapeKey()
timer.stop()
end
function on.timer()
platform.window:invalidate()
var.store("ini_lx", mat[2][2])
var.store("ini_vx", mat[3][2])
var.store("ini_ly", mat[4][2])
var.store("ini_vy", mat[5][2])
time = time + step
end