Translate

Gravity Free Fall Animation Code



#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<stdlib.h>
#include<math.h>
void gotoxy(short x, short y)
{
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD position = { x, y };
    SetConsoleCursorPosition(handle, position);

}
void box(void)
{

    int a;
    for (a = 0; a <= 57; a++)//leftmost line
    {
        printf("%c\n", 186);
        Sleep(10);
    }

    for (a = 0; a <= 149; a++)//uppermost line
    {
        Sleep(10);
        gotoxy(1 + a, 0);
        printf("%c", 240);
    }
    gotoxy(150, 0);
    for (a = 0; a <= 57; a++)//correct
    {
        Sleep(10);
        printf("%c", 186);
        gotoxy(150, a + 1);
    }
    gotoxy(1, 57);
    for (a = 0; a <= 149; a++)//Bottom line
    {
        Sleep(10);
        printf("%c", 240);
    }


}
void graph(void)
{

    for (int a = 0; a <= 130; a++)
    {
        gotoxy(3 + a, 55);//for horizontal line
        printf("_"); Sleep(50);

    }
    for (int a = 0; a<55; a++)
    {
        gotoxy(2, 2 + a);//for vertical line
        printf("|"); Sleep(50);

    }

    for (int a = 0; a <= 130; a = a + 10)//horizontal scale
    {
        gotoxy(3 + a, 56);
        Sleep(100);
        printf("%d", a);

    }
    printf("> Time");
    for (int a = 0; a<57; a = a + 5)
    {
        gotoxy(1, 56 - a);
        Sleep(100);
        printf("%d", a);

    }gotoxy(2, 2);
    printf("Distance");
    gotoxy(2, 3);
    printf("^");
}
void move(int l)//it will move y coordinate
{
    int a;
    char c[7] = { '|','/','-','\\','_','.' };
    a = 1;
    do {
        int b;
        for (b = 0; b <= 6; b++)
        {
            gotoxy(80, l);
            printf("%c", c[b]);
            Sleep(100);

        }
        a = a + 1;
    } while (a <= 4);
}
void conbox(void)
{
    int a; gotoxy(50, 0);//initial point;
    Sleep(500);
    for (a = 0; a <= 50; a++)//upper line
    {
        printf("%c", 240); Sleep(10);
        gotoxy(50 + a, 0);

    }

    for (a = 0; a <= 50; a++)//bottom line
    {
        printf("%c", 240); Sleep(10);
        gotoxy(50 + a, 50);

    }
    for (a = 0; a <= 50; a++)//left border
    {
        printf("%c", 186); Sleep(10);
        gotoxy(50, a);
    }
    for (a = 0; a <= 50; a++)//left border
    {
        printf("%c", 186); Sleep(10);
        gotoxy(100, a);
    }
}


void main(void)
{
    getch();



    short h = 45, h1 = 0; int t;
    short a;
    float a1, b1, p;

    conbox();//Drawing the box
    gotoxy(52, 2);

    printf("\"Free Fall Rebounding\"");
    gotoxy(52, 3);

    printf("Gravity  :>1.6 ");
    //scanf("%d",&a1);

    gotoxy(60, 3);
    move(3);
    gotoxy(60, 3);//taking amplitude
    gotoxy(52, 4);
    printf("Mass :>constant ");
    //scanf("%d",&b1);
    gotoxy(65, 4);
    move(4);
    gotoxy(65, 4);
    gotoxy(52, 5);
    printf("Rebounding  Constant :>h/2");
    //scanf("%d",&p);
    gotoxy(65, 5);
    move(5);
    gotoxy(65, 5);

    system("cls");

    box();
    graph();
    short b = 0;


    h = 0;
    for (t = 0; t<10; t++)//first free fall
    {

        gotoxy(4 + (short)t, 4 + (short)h);

        printf("%c", 233);
        Sleep(150);
        h = t*t;
        h = h / 2;
        h = h*1.6;
    }
    h = h / 2;
    h1 = 0;
    for (t = 1; t<10; t++)//first up
    {
        h1 = (10 - t)*(10 - t);//contionus decrement
        h1 = h1 / 2;
        h1 = h1*1.6;
        h1 = h1 / 2;

        gotoxy(13 + t, h1 + 15);
        printf("%c", 233); Sleep(150);
    }
    for (t = 1; t <= 10; t++)//second free fall
    {
        h = t*t;
        h = h / 2;
        h = h*1.6;
        h = h / 2;

        gotoxy(23 + (short)t, (short)h + 15);

        printf("%c", 233);
        Sleep(150);

    }
    h = h / 2;
    h1 = 0;
    for (t = 1; t<10; t++)//second up
    {
        h1 = (10 - t)*(10 - t);//contionus decrement
        h1 = h1 / 2;
        h1 = h1*1.6;
        h1 = h1 / 4;

        gotoxy(33 + t, h1 + 35);
        printf("%c", 233); Sleep(150);
    }
    for (t = 1; t <= 10; t++)
    {
        h = t*t;
        h = h / 2;
        h = h*1.6;
        h = h / 4;

        gotoxy(43 + (short)t, (short)h + 35);

        printf("%c", 233);
        Sleep(150);

    }
    for (t = 1; t <= 10; t++)
    {
        h1 = (10 - t)*(10 - t);//contionus decrement
        h1 = h1 / 2;
        h1 = h1*1.6;
        h1 = h1 / 6;

        gotoxy(53 + t, h1 + 45);
        printf("%c", 233); Sleep(100);
    }
    for (t = 1; t<10; t = t + 2)
    {
        h = t*t;
        h = h / 2;
        h = h*1.6;
        h = h / 6;

        gotoxy(63 + (short)t, (short)h + 45);

        printf("%c", 233);
        Sleep(100);

    }

    for (t = 1; t <= 10; t = t + 2)
    {
        h1 = (10 - t)*(10 - t);//contionus decrement
        h1 = h1 / 2;
        h1 = h1*1.6;
        h1 = h1 / 14;

        gotoxy(73 + t, h1 + 50);
        printf("%c", 233); Sleep(100);
    }
    for (t = 1; t<10; t = t + 2)
    {
        h = t*t;
        h = h / 2;
        h = h*1.6;
        h = h / 14;

        gotoxy(83 + (short)t, (short)h + 50);

        printf("%c", 233);
        Sleep(1000);

    }


}
Previous
Next Post »

Contact Form

Name

Email *

Message *