
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.




      MODE 8
      *FLOAT 64
      VDU 23,23,4;0;0;0; : REM Set line thickness
 
      theta = RAD(40) : REM initial displacement
      g = 9.81 : REM acceleration due to gravity
      l = 0.50 : REM length of pendulum in metres
 
      REPEAT
        PROCpendulum(theta, l)
        WAIT 1
        PROCpendulum(theta, l)
        accel = - g * SIN(theta) / l / 100
        speed += accel / 100
        theta += speed
      UNTIL FALSE
      END
 
      DEF PROCpendulum(a, l)
      LOCAL pivotX, pivotY, bobX, bobY
      pivotX = 640
      pivotY = 800
      bobX = pivotX + l * 1000 * SIN(a)
      bobY = pivotY - l * 1000 * COS(a)
      GCOL 3,6
      LINE pivotX, pivotY, bobX, bobY
      GCOL 3,11
      CIRCLE FILL bobX + 24 * SIN(a), bobY - 24 * COS(a), 24
      ENDPROC