
One good way of making an animation is by simulating a physical system and illustrating the variables in that system using a dynamically changing graphical display.

The classic such physical system is a simple gravity pendulum.



Task

Create a simple physical model of a pendulum and animate it.




clear screen
open window 400, 300
window origin "cc"
 
rodLen = 160
gravity = 2
damp = .989
TWO_PI = pi * 2
angle = 90 * 0.01745329251 // convert degree to radian
 
repeat
    acceleration = -gravity / rodLen * sin(angle)
    angle = angle + velocity : if angle > TWO_PI angle = 0
    velocity = velocity + acceleration
    velocity = velocity * damp
    posX = sin(angle) * rodLen
    posY = cos(angle) * rodLen - 70
    clear window
    text -50, -100, "Press 'q' to quit"
    color 250, 0, 250
    fill circle 0, -70, 4
    line 0, -70, posX, posY
    color 250, 100, 20
    fill circle posX, posY, 10
until(lower$(inkey$(0.02)) = "q")
 
exit