home *** CD-ROM | disk | FTP | other *** search
- /*
- * RTAG source file for Bouncing Ball Animation.
- * Created by Phillip H. Sherrod
- */
-
- // File declarations
- bfile "bounc"; // bounc.bat will be the batch driver file
- // Simulation parameters
- var numframes = 70; // Number of frames to generate
- var endtime = 26.2; // Time at end of simulation
- var timestep = .05; // Time for each simulation step
- var xstart = -9.2; // Initial X position of ball.
- var g = .6; // Gravitational acceleration
- var drag = .32; // Frictional drag on slide
- var angle = 30; // Downward angle of the slide
- // Variable declarations
- var x; // Current x position
- var y; // Current y position
- var xv; // X velocity
- var yv; // Y velocity
- var time; // Current simulated time
- var frametime; // Generate frame after this much time passes
- var nextframetime; // Time when next frame should be displayed
- // ----- Executable code -----
- // First time inititlization
- // Initial position
- x = xstart;
- frametime = endtime / numframes;
- // Begin main simulation loop
- for (time=0; time<endtime; time+=timestep) {
- // See if ball is still on the slide
- if (x <= -5.75) {
- // Ball is still on the slide
- y = 7.43 - (5.75 + x) * tan(angle);
- // Compute next x position
- xv = xv + timestep * g * sin(angle) * drag;
- x = x + timestep * xv;
- // Compute y velocity
- yv = -xv * sin(angle);
- } else {
- // Ball is in free fall
- // Apply acceleration to get new speed
- yv = yv - timestep * g;
- // Compute new ball position
- y = y + timestep * yv;
- // If ball hit floor, reverse direction & loose energy
- if (y <= 0) {
- printf("Hit floor. time=`time`, x=`x`, y=`y`\n");
- y = 0;
- yv = -.75 * yv;
- }
- // Compute x position. Note: x velocity is not changing.
- x = x + timestep * xv;
- // Don't let ball go past right side of can
- if (x > 8.2) {
- x = 8.2;
- }
- }
- // See if it is time to start a new frame
- if (time >= nextframetime) {
- // Start a new frame
- nextframe;
- // Print current ball position
- printf("At frame `curframe`, time=`time`, X=`x`, and Y=`y`\n");
- // Generate commands to create the include file.
- bwrite("echo #declare xpos = `x` > bounc.inc\n");
- bwrite("echo #declare ypos = `y` >> bounc.inc\n");
- // Generate command to run POV-Ray to render the frame.
- bwrite("call render bounc bounc`###`\n");
- // Remember when next frame should be produced
- nextframetime = curframe * frametime;
- }
- // End of main simulation loop
- }
- // Write batch command for end of run processing
- epilog;
- bwrite("dodta BOUNC\n");
-