Particle Animation with Anim8or v0.7


Generating the code for rain animation by means of a script file

 

BEGIN {

particles            = 2000             # rain drops

startRain           = 0                   # starting frame

falling                = 20                 # no. of frames a drop is falling

x_shift              = 30                 # higher value means stronger wind

z_shift               = 10                 # higher value means stronger wind

variation            = 5                   # max. variation from the mean path

ground_level     = 0                   # Y coordinate of the ground

x_origin            = 0                   # birth area location

y_origin            = 150               # birth area location

z_origin            = 0                   # birth area location

x_length            = 300               # birth area x-length    

y_length            = 0                   # birth area y-length

z_length            = -100             # birth area z-length

  

    # initialise the random number generator

    srand()

 

    for ( i = 1; i <= particles; i++ ) {

            # define the object

            object = "object01"

            printf( "  objectelement { \"eobject%d\" \"%s\"\n", i, object )

 

            # generate the position

            x = x_origin + (x_length * rand() - x_length / 2)

            y = y_origin + y_length * rand()

            z = z_origin + z_length * rand()

       

# place the object in position

printf( "    loc { (%f %f %f) }\n", x, y, z )

 

# create a track

printf( "      controller { \"position\"\n" )

printf( "        track {\n" )

 

            # generate birth time of a rain drop

startFrame = startRain + int(144 * rand())

 

            # start frame

printf( "          pointkey { %d (%f %f %f) (0 0 0) (0 0 0) \"?\" }\n", startFrame, x, y, z )

 

            # generate end frame position

            x = x + x_shift + variation*(rand()-0.5)

            y = ground_level

            z = z + z_shift + variation*(rand()-0.5)

 

            # end frame

printf( "          pointkey { %d (%f %f %f) (0 0 0) (0 0 0) \"?\" }\n", startFrame+falling, x, y, z)

 

# close the track

printf( "        }\n" )

 

# close the position controller

printf( "      }\n" )

 

# the visibility controller

printf( "      controller { \"visibility\"\n" )

printf( "        track {\n" )

 

# initially invisible

if (startFrame > 0)

            printf( "          booleankey { 0 0 \"?\" }\n" )

 

            # to avoid phantom-key problem

            if (startFrame > 98)

            printf( "          booleankey { 98 0 \"?\" }\n" )

            printf( "          booleankey { %d 1 \"?\" }\n", startFrame )

    

# hide at end of life

            printf( "          booleankey { %d 0 \"?\" }\n", startFrame+falling )

 

# to avoid phantom-key problem

            if ((startFrame+falling) < 98)

            printf( "          booleankey { %d 0 \"?\" }\n", 98)

 

# close the track

printf( "        }\n" )

 

# close the visibility controller

printf( "      }\n" )

 

# close the object element

printf( "    }\n" )

      }

}

 

You can set your own parameters for the animation: number of particles, the starting frame for raining (startRain), wind effect, location and dimensions of the “rain cloud” (box).

Type in a DOS window the following command line:

Your Path\awk95 –f  Script file > Code file

where Your Path is the path to awk95.exe, -f is a switch, Script file is the name of the file containing the awk script (given above), located in the same folder with awk95.exe and Code file is the name of the file generated by awk95.exe containing the code for 2,000 objectelements. Simply open Code file (generated in the same folder with awk95.exe) with a text editor, copy the whole code and insert it in raintemplate.an8. Save the file as rain.an8. Open rain.an8 in Anim8or, set the proper adjustments for object01 (your particle), apply a suitable rain-drop color, set the fog parameters, set the length of scene01 at 144+startRain and you may run the animation (from frame 0 to frame 143 + stratRain).

 

back               next