Code Sketch


Uvats (Physics) Animation
By: Lalit Pant [2]
val a = 20.0
val u = 0.0

val S = Staging
S.clear

axesOn()
gridOn()
zoom(0.75, 500, 300)

val car = S.sprite(0, 25, """C:\Users\lalit\scratch\car2.jpg""")
val splot = S.path(0, 0)
splot.setPenColor(blue)

val vplot = S.path(0, 0)
vplot.setPenColor(green)

val t0 = S.time
val time = S.text("0", 100, -50)
time.setFontSize(17)
time.setPenColor(blue)

S.animate {
    val t = S.time - t0
    val v = u + a*t
    val s = u*t + 0.5*a*S.sq(t)
    car.setPosition(s, 25)
    splot.lineTo(t*50, s)
    vplot.lineTo(t*50, v)
    time.setContent("Time: %.3f seconds" format(t))
}