How to make animation in C language (Turbo C++)




Hey guys!

Before moving on I would like to tell you that this post is for the Beginner of C language or above of that.

Now let's move on. 

The project was given to me on any topic to be done in C language with the help of Turbo C++ software, so I decided to make a project on ordering food items which I named the application "Foody". For this purpose, I thought to make something attractive. So I decided to make the welcome screen with the animation. I divided my project with three parts: 

(1) Welcome screen (Animation) 
(2) Ordering Items screen
(3) Getting & showing details of customer screen

This page contains the first part of my project i.e Welcome screen (Animation), remaining parts will be posted later on.

Before moving on I would like to tell you that about the working on animation in C language which I will tell you is not a big or vast animation but just a small basic animation.

Watch the below video:



After watching this video, you have got to know what type of animation I am talking about.
Now let me reveal the code of this program.

=======================================================================

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<iostream.h>

void main()
{
 clrscr();
int kit,count=1;
printf("\n");
printf("                   *     *     *\n");
delay(100);
printf("                     *     *     *\n");
delay(100);
printf("                      *     *     *\n");
delay(100);
printf("                     *     *     *\n");
delay(100);
printf("                    *     *     *\n");
delay(100);
printf("                     *     *     *\n");
delay(100);
printf("                       *     *     *\n");
delay(100);
printf("           ");
for(kit=0;kit<35;kit++)
{
printf("*");
delay(100);
}
printf("\n");
printf("            *                               *\n");
delay(200);
printf("             *                             *\n");
delay(200);
printf("               *                         *\n");
delay(200);
printf("                 *                     *\n");

printf("                   ");

for(kit=0;kit<19;kit++)
{
printf("*");
delay(100);
}
printf("\n\n");
cout<<"            #"; delay(75); cout<<"W"; delay(75); cout<<"E";
delay(75); cout<<"L"; delay(75); cout<<"C"; delay(75); cout<<"O";
delay(75); cout<<"M"; delay(75); cout<<"E"; delay(75); cout<<" T";
delay(75); cout<<"O"; delay(75); cout<<" F"; delay(75); cout<<"(";
delay(75); cout<<")"; delay(75); cout<<"("; delay(75); cout<<")";
delay(75); cout<<"|"; delay(75); cout<<")"; delay(75); cout<<"Y";
delay(75); cout<<" A"; delay(75); cout<<"P"; delay(75); cout<<"P";
delay(75); cout<<"L"; delay(75); cout<<"I"; delay(75); cout<<"C";
delay(75); cout<<"A"; delay(75); cout<<"T"; delay(75); cout<<"I";
delay(75); cout<<"T"; delay(75); cout<<"I"; delay(75); cout<<"O";
delay(75); cout<<"N"; delay(75); cout<<"#"; delay(200);

printf("\n\n\n");

printf("Press any key....");

getch();

}

=======================================================================


Let me explain you little bit of this code:

Before beginning the program we must include three header files i.e "stdio.h", "conio.h" & "dos.h".

And for effect of animation I have used the function "delay()". This delay() function helps us to delay the next instruction. Notice that I have used "delay(100)" & "delay(75)" most the time in program.

100 & 75 is nothing just the time gap you want between the previous instruction & next instruction.

For my knowledge I think the unit would be milliseconds, that's why the stars were appearing after 0.1 seconds but I am not sure of the accurate unit. The more you increase the number inside the delay() function the more you have to wait for the next instruction to perform.

By this I used this function after every "printf()" & "cout<<" command so that the stars & text could be appeared like the appearing of character animation after every seconds.

Remember the delay() function will only work if you have included the "dos.h" header file.

Now you can copy this code and try to run this program.

If you have more information or having query regarding this then you are free to comment here, I will try my best to solve your queries.

That's all guys :)

1 comment:

  1. Why did this happen??? When i compile your code.. It says that this code is syntax error..
    This is the code I mean:
    printf("\n");
    printf(" * * *\n");
    delay(100);
    printf(" * * *\n");
    delay(100);
    printf(" * * *\n");
    delay(100);
    printf(" * * *\n");
    delay(100);
    printf(" * * *\n");
    delay(100);
    printf(" * * *\n");
    delay(100);
    printf(" * * *\n");
    delay(100);

    ReplyDelete