DEFINITION  
    output = "pix/spring";
    xleft  = 0; xright = 323;
    ylow   = 0; yhigh  = 242;

    aalevelmin  = 0;
    aalevelmax  = 0;
    aawidth     = 1;
    aathreshold = 60.000000;

    up         = yaxis;
    grid_cache = 4000;

	triple CameraView(0.0, 0.0, 0.0);
    scalar x(0);
    scalar v(0);
    scalar mass(0);
    scalar k(0);
    scalar f(0);
    scalar dt(0);
    scalar a(0);

startframe = 1.0;
endframe   = 300.0;
byframe    = 1.0;


shader Shader1 (
    model     = lambert,
    diffuse   = 0.8,
    color     = (255.0, 255.0, 255.0),
    incandescence = (0.0, 0.0, 0.0),
    transparency  = 0.0,
    reflection_limit   = 0,
    refraction_limit   = 0,
    shadow_level_limit = -1,
    transparency_shade = 0.0
);


ENVIRONMENT
	background( color = (50.0, 70.0, 100.0) );

MODEL

{
    translate(0.0, 0.0, 4.0);
    light (model = ambient, color = (150.0, 150.0, 150.0),
        ambient_shade = 0.5);
}

{
    camera (
        eye   = (0.0, 0.0, 4.0),
        view  = CameraView,
        twist = 0.0,
        fov   = (40.0),
        viewport = (xleft, xright, ylow, yhigh),
        aspect   = 1.312670,
        near = 0.1,
        far  = 10000
    );
}

/* Define the time and the time increment */
dt   = (1.0 / 30.0);

/* Define the mass of the spheres and the spring constant */
mass = 1.0;
k    = 4.0;

/* If this is the first frame, initialise the variables */
if ((frame == startframe))
{
    x = 1.0;
    v = 0.0;
}

/* Compute the force acting on the mass */
f = (-k * x);

/* Compute the acceleration of the mass */
a = (f / mass);

/* Compute the new positions and velocities */
v = (v + (a * dt));
x = ((x + (v * dt)) + (((0.5 * a) * dt) * dt));

/* Position the sphere using a translate statement */
translate (x, 0.0, 0.0);
scale     (0.5, 0.5, 0.5);
{
    patch (
        shader = ( Shader1 ),
        doublesided = TRUE, vclosed = TRUE, 
        subdivide = uniform,
        divisions = (2, 2),
        udegree = 3, vdegree = 3,
        uknots = (-0.666667, -0.333333, 0.000000, 0.333333, 0.666667,
                  1.000000, 1.333333, 1.666667),
        vknots = (-0.333333, -0.166667, 0.000000, 0.166667, 0.333333,
                  0.500000, 0.666667, 0.833333, 1.000000, 1.166667,
                  1.333333),

        cvs = ((cv( (-0.311775, -0.300000, -0.540010), 1.000000),
                cv( (-0.623550, -0.300000, 0.000000), 1.000000),
                cv( (-0.311775, -0.300000, 0.540010), 1.000000),
                cv( (0.311775, -0.300000, 0.540010), 1.000000),
                cv( (0.623549, -0.300000, 0.000000), 1.000000),
                cv( (0.311774, -0.300000, -0.540010), 1.000000),
                cv( (-0.311775, -0.300000, -0.540010), 1.000000),
                cv( (-0.623550, -0.300000, 0.000000), 1.000000),
                cv( (-0.311775, -0.300000, 0.540010), 1.000000)),

               (cv( (0.000000, -0.600000, 0.000000), 1.000000),
                cv( (0.000000, -0.600000, 0.000000), 1.000000),
                cv( (0.000000, -0.600000, 0.000000), 1.000000),
                cv( (0.000000, -0.600000, 0.000000), 1.000000),
                cv( (0.000000, -0.600000, 0.000000), 1.000000),
                cv( (0.000000, -0.600000, 0.000000), 1.000000),
                cv( (0.000000, -0.600000, 0.000000), 1.000000),
                cv( (0.000000, -0.600000, 0.000000), 1.000000),
                cv( (0.000000, -0.600000, 0.000000), 1.000000)),

               (cv( (0.311769, -0.300000, 0.539999), 1.000000),
                cv( (0.623538, -0.300000, 0.000000), 1.000000),
                cv( (0.311769, -0.300000, -0.539999), 1.000000),
                cv( (-0.311769, -0.300000, -0.539999), 1.000000),
                cv( (-0.623538, -0.300000, 0.000000), 1.000000),
                cv( (-0.311769, -0.300000, 0.539999), 1.000000),
                cv( (0.311769, -0.300000, 0.539999), 1.000000),
                cv( (0.623538, -0.300000, 0.000000), 1.000000),
                cv( (0.311769, -0.300000, -0.539999), 1.000000)),

               (cv( (0.311769, 0.300000, 0.539999), 1.000000),
                cv( (0.623537, 0.300000, 0.000000), 1.000000),
                cv( (0.311769, 0.300000, -0.539999), 1.000000),
                cv( (-0.311769, 0.300000, -0.539999), 1.000000),
                cv( (-0.623537, 0.300000, 0.000000), 1.000000),
                cv( (-0.311768, 0.300000, 0.539999), 1.000000),
                cv( (0.311769, 0.300000, 0.539999), 1.000000),
                cv( (0.623537, 0.300000, 0.000000), 1.000000),
                cv( (0.311769, 0.300000, -0.539999), 1.000000)),

               (cv( (0.000000, 0.599999, 0.000000), 1.000000),
                cv( (0.000000, 0.599999, 0.000000), 1.000000),
                cv( (0.000000, 0.599999, 0.000000), 1.000000),
                cv( (0.000000, 0.599999, 0.000000), 1.000000),
                cv( (0.000000, 0.599999, 0.000000), 1.000000),
                cv( (0.000000, 0.599999, 0.000000), 1.000000),
                cv( (0.000000, 0.599999, 0.000000), 1.000000),
                cv( (0.000000, 0.599999, 0.000000), 1.000000),
                cv( (0.000000, 0.599999, 0.000000), 1.000000)),

               (cv( (-0.311775, 0.299999, -0.540010), 1.000000),
                cv( (-0.623549, 0.299999, 0.000000), 1.000000),
                cv( (-0.311775, 0.299999, 0.540010), 1.000000),
                cv( (0.311775, 0.299999, 0.540010), 1.000000),
                cv( (0.623549, 0.299999, 0.000000), 1.000000),
                cv( (0.311774, 0.299999, -0.540009), 1.000000),
                cv( (-0.311775, 0.299999, -0.540010), 1.000000),
                cv( (-0.623549, 0.299999, 0.000000), 1.000000),
                cv( (-0.311775, 0.299999, 0.540010), 1.000000))
        )
    ); /* end patch */
}
