home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bounc10.zip / BOUNC.RTA < prev    next >
Text File  |  1993-02-13  |  3KB  |  76 lines

  1. //  RTAG source file for Bouncing Ball Animation.
  2. //  Created by Phillip H. Sherrod
  3.  
  4. //  File declarations
  5. bfile bounc        // bounc.bat will be the batch driver file
  6. //  Simulation parameters
  7. var numframes = 70    // Number of frames to generate
  8. var endtime = 26.2    // Time at end of simulation
  9. var timestep = .05    // Time for each simulation step
  10. var xstart = -9.2    // Initial X position of ball.
  11. var g = .6        // Gravitational acceleration
  12. var drag = .32        // Frictional drag on slide
  13. var angle = 30        // Downward angle of the slide
  14. //  Variable declarations
  15. var x            // Current x position
  16. var y            // Current y position
  17. var xv            // X velocity
  18. var yv            // Y velocity
  19. var time        // Current simulated time
  20. var frametime        // Generate frame after this much time passes
  21. var nextframetime    // Time when next frame should be displayed
  22. // ----- Executable code -----
  23. //  First time inititlization
  24. // Initial position
  25. x = xstart
  26. frametime = endtime / numframes
  27. //  Begin main simulation loop
  28.    for time=0 while time<endtime step timestep do
  29.     //  See if ball is still on the slide
  30.     if (x <= -5.75) then
  31.         // Ball is still on the slide
  32.         y = 7.43 - (5.75 + x) * tan(angle)
  33.         // Compute next x position
  34.         xv = xv + timestep * g * sin(angle) * drag
  35.         x = x + timestep * xv
  36.         //  Compute y velocity
  37.         yv = -xv * sin(angle)
  38.     else
  39.         // Ball is in free fall
  40.         //  Apply acceleration to get new speed
  41.         yv = yv - timestep * g
  42.         //  Compute new ball position
  43.         y = y + timestep * yv
  44.         //  If ball hit floor, reverse direction & loose energy
  45.         if (y <= 0) then
  46.             print "Hit floor.  time=`time`,  x=`x`,  y=`y`"
  47.             y = 0
  48.             yv = -.75 * yv
  49.         endif
  50.         //  Compute x position.  Note: x velocity is not changing.
  51.         x = x + timestep * xv
  52.         //  Don't let ball go past right side of can
  53.         if (x > 8.2) then
  54.             x = 8.2
  55.         endif
  56.     endif
  57.     // See if it is time to start a new frame
  58.     if (time >= nextframetime) then
  59.         // Start a new frame
  60.         nextframe
  61.         //  Print current ball position
  62.         print "At frame `curframe`, time=`time`, X=`x`, and Y=`y`"
  63.         //  Generate commands to create the include file.
  64.         bwrite "echo #declare xpos = `x` > bounc.inc"
  65.         bwrite "echo #declare ypos = `y` >> bounc.inc"
  66.         //  Generate command to run POV-Ray to render the frame.
  67.         bwrite "call render bounc bounc`###`"
  68.         // Remember when next frame should be produced
  69.         nextframetime = curframe * frametime
  70.     endif
  71. //  End of main simulation loop
  72. endfor
  73. //  Write batch command for end of run processing
  74. epilog
  75. bwrite "dodta BOUNC /S7"
  76.