
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.




nomainwin
    WindowWidth = 400
    WindowHeight = 300
 
    open "Pendulum" for graphics_nsb_nf as #main
    #main "down;fill white; flush"
    #main "color black"
    #main "trapclose [quit.main]"
 
    Angle = asn(1)
    DeltaT = 0.1
    PendLength = 150
    FixX = int(WindowWidth / 2)
    FixY = 40
 
    timer 30, [swing]
 
    wait
 
[swing]
 
    #main "cls"
    #main "discard"
 
    PlumbobX = FixX + int(sin(Angle) * PendLength)
    PlumbobY = FixY + int(cos(Angle) * PendLength)
    AngAccel = -9.81 / PendLength * sin(Angle)
    AngVelocity = AngVelocity + AngAccel * DeltaT
    Angle = Angle + AngVelocity * DeltaT
 
    #main "backcolor black"
    #main "place ";FixX;" ";FixY
    #main "circlefilled 3"
    #main "line ";FixX;" ";FixY;" ";PlumbobX;" ";PlumbobY
    #main "backcolor red"
    #main "circlefilled 10"
 
    wait
 
[quit.main]
    close #main
    end