Stylish Springs : Turbo C++

  The Conical Waterfall was built to render several cones that created a wonderful waterfall structure. It was made up of 25 inverted cones that formed an animated waterfall. Here, we will show you an animation, the Stylish Springs, that consists of several long curved animated coils.

The Stylish Springs utilizes several functions from the BGI library to render the cones. If you need an introduction to the BGI library, read How to Create Graphical Applications using Turbo C++ 3.0 IDE (BGI library). To learn in detail about BGI library functions, read BGI Library Functions – Part 1, Part 2, Part 3 and Part 4.



The following video illustrates this animation :

 

How does this program work?

The Stylish Springs generates several continuous curved lines, each resulting in a spring-like structure. These springs start coiling when the animation starts, until they’ve reached the maximum size. After this, they begin to uncoil from the bottom. When the entire curve has disappeared, one round of the animation ends. After this, the entire process continues until the user presses a key on the keyboard.

The Rendering Module

The module which performs the task of drawing the curves in this program is Spring_Animation. It draws all the curves as well as clears them when required. The code for this module is displayed below :


/* Stylish Springs by Manish Kumar */

void Spring_Animation()
{
    float i=1,j=1;
    float r = 30,c = 1,r1 = 30;
    float X = 300, Y = 350, Y1 = 350;
    float l = 1;
    int flag = 0;

    Message("Spring Animation");

    while(!kbhit())
    {
	if(c==14)
	    c=1;

	if(l < 240 && flag == 0)
        {
            Y1 = 350;
            r1 = 30;
            j = 1;
            putpixel(r*cos(i)+X-200,r*sin(i)+Y,c);
            putpixel(r*cos(i)+X-100,r*sin(i)+Y,c);
            putpixel(r*cos(i)+X,r*sin(i)+Y,c);
            putpixel(r*cos(i)+X+100,r*sin(i)+Y,c);
            putpixel(r*cos(i)+X+200,r*sin(i)+Y,c);
            i += 0.003;
            Y -= 0.01;
            l += 0.01;
            c++;
            delay(1);
        }
        if(l >=240 && l < 240*2)
        {
            Y = 350;
            c = 1;
            r = 30;
            i = 1;
            if(flag == 0)
                flag = 1;
            if(l >= 240*2-1)
	    {
		flag = 0;
		l = 1;
		clearviewport();
            }

	    putpixel(r1*cos(j)+X-200,r1*sin(j)+Y1,0);
	    putpixel(r1*cos(j)+X-100,r1*sin(j)+Y1,0);
	    putpixel(r1*cos(j)+X,r1*sin(j)+Y1,0);
	    putpixel(r1*cos(j)+X+100,r1*sin(j)+Y1,0);
	    putpixel(r1*cos(j)+X+200,r1*sin(j)+Y1,0);

	    j += 0.003;
	    Y1 -= 0.01;
	    l += 0.01;

	    delay(1);
        }
    }
    Pause();
}

/* End of Program */




Click here to download this program’s source code.

If you like this project, do let us know… πŸ™‚

(Visited 305 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *