Preamble   ''Example "Eagle"

     Normally mode is undefined
     Define  NUM.ROTATIONS, SPEED as double variables 
 

'' Animation declarations:
     Processes include IMAGE.MOTION
     Dynamic graphic entities include IMAGE
     Graphics entities include BACKGROUND, WEATHER

'' Presentation graphics declarations:
     Define CLOCK.TIME as double variables
     Display variables include CLOCK.TIME


End ''Preamble

Main

'' Open graphics window with specified coordinates,
'' and a title
''--------------------------------------------------
   
   Define WINDOW.ID as integer variable

   call OPENWINDOW.R given 4096, 28672, 0 , 32767,
                          " Eagle",
                          0
                          yielding WINDOW.ID

   call SETWINDOW.R given WINDOW.ID


'' Set world view and view port


   Let VXFORM.V =1
   call SETWORLD.R ( -16767.0, 16767.0, -16767.0, 16767.0)

'' Display icons from f15.sg2 library
  
   call read.glib.r ("f15.sg2")

   show BACKGROUND with "Background.icn"   at (0.0 , 0.0)

   show WEATHER with "weather.icn"    at (0.0 , 0.0)

''   show IMAGE with "eagle.icn"  at (-10000.0, 2000.0)


'' Forms definitions:
     Define FORM.PTR as a pointer variable

'' Set up the world view and view port
     Let VXFORM.V = 1                                    
     Call SETWORLD.R (-1000.0, 1000.0,-1000.0, 1000.0)  


'' Presentation graphics:
     Let TIMESYNC.V = 'CLOCK'
     show CLOCK.TIME with "clock.grf"

'' Display the form and get model parameters
       Show FORM.PTR with "image.frm"
       If ACCEPT.F(FORM.PTR, 0) eq "OK"

         '' Set timescale and speed:
         '' timescale is the number of 1/100ths seconds 
         '' that will pass for every simulation time unit. 
         '' The speed is in real world units / second.

         Let TIMESCALE.V = DDVAL.A(DFIELD.F("TIMESCALE", FORM.PTR))
         Let SPEED = DDVAL.A(DFIELD.F("SPEED", FORM.PTR))
         Let NUM.ROTATIONS = DDVAL.A(DFIELD.F("NUM ROTATIONS", FORM.PTR))

         

         '' Accept icon name for graphics entity IMAGE,
         '' show it with that name and   
         '' activate an 'image.motion' process.

          Activate an IMAGE.MOTION now
          Show IMAGE with DTVAL.A(DFIELD.F("ICON NAME", FORM.PTR)) 
                                at ( -10000.0, 2000) 
        
          Start simulation

      Always
End ''Main
Process IMAGE.MOTION

     Define CURRENT.COURSE, NUM.SIDES, ANGLE as real variables
     Define I, J as integer variables
     
     For I = 1 to NUM.ROTATIONS
     Do


          let num.sides = 4
          Let ANGLE = (2 * PI.C * (1 - 2 * RANDI.F(0,1,2))) / NUM.SIDES

          For J = 1 to NUM.SIDES 
          Do
               Let orientation.a(IMAGE) = CURRENT.COURSE
               Let velocity.a(IMAGE) = velocity.f(SPEED, CURRENT.COURSE)
               
               Wait (1000 * PI.C) / (NUM.SIDES * SPEED) units  
               Add ANGLE * min.f(NUM.SIDES - J,1) to CURRENT.COURSE
          Loop
     Loop
End '' process IMAGE

Routine CLOCK given TIME yielding NEWTIME

     Define  TIME, NEWTIME as double variables

     Let CLOCK.TIME = TIME / (24*60*60)
     Let NEWTIME = TIME
return
end

  
  

