
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.




 
PROGRAM PENDULUM
 
!
! for rosettacode.org
!
 
!$KEY
 
!$INCLUDE="PC.LIB"
 
PROCEDURE PENDULUM(A,L)
      PIVOTX=320
      PIVOTY=0
      BOBX=PIVOTX+L*500*SIN(a)
      BOBY=PIVOTY+L*500*COS(a)
      LINE(PIVOTX,PIVOTY,BOBX,BOBY,6,FALSE)
      CIRCLE(BOBX+24*SIN(A),BOBY+24*COS(A),27,11)
      PAUSE(0.01)
      LINE(PIVOTX,PIVOTY,BOBX,BOBY,0,FALSE)
      CIRCLE(BOBX+24*SIN(A),BOBY+24*COS(A),27,0)
END PROCEDURE
 
BEGIN
      SCREEN(9)
      THETA=40*p/180     ! initial displacement
      G=9.81             ! acceleration due to gravity
      L=0.5              ! length of pendulum in metres
      LINE(0,0,639,0,5,FALSE)
      LOOP
        PENDULUM(THETA,L)
        ACCEL=-G*SIN(THETA)/L/100
        SPEED=SPEED+ACCEL/100
        THETA=THETA+SPEED
      END LOOP
END PROGRAM
 