Sunday 1 July 2012

Show movement of flying kite using c++.

#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
#include <dos.h>
#include <stdlib.h>
#define ESC_KEY   0x1b

int tx=0,ty=0;
void getx(int &ox)
{
    if (ox==50)
    {
        tx=0;
        ox=ox+1;
    }
    else if (ox==590)
    {
        tx=-1;
        ox=ox-1;
    }
    else if(tx==0)
        ox=ox+1;
    else  if(tx==-1)
        ox=ox-1;
}

void gety(int &oy)
{
    if (oy==50)
    {
        ty=0;
        oy=oy+1;
    }
    else if (oy==430)
    {
        ty=-1;
        oy=oy-1;
    }
    else if(ty==0)
        oy=oy+1;
    else if(ty==-1)
        oy=oy-1;
}

void main()
{
int i,j;
int gdriver = DETECT, gmode, errorcode;
void kite(int,int);
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "..\\bgi");
int x,y;
x=400;
y=200;

a:
cleardevice();
getx(x);
gety(y);
kite(x,y);
        while(!kbhit())
        {

            delay(10);
            goto a;
        }
        if (getch()==ESC_KEY)
        {
            exit(1);
        }
        else
        goto a;
}
void kite(int i,int j)
{
line(i-50,j,i+50,j);
line(i,j-50,i,j+50);
line(i-50,j,i,j+50);
line(i,j-50,i+50,j);
line(i+50,j,i,j+50);
line(i,j-50,i-50,j);
line(i,j,getmaxx()/2,getmaxy() );
line(i,j+50,i-20,j+70);
line(i,j+50,i+20,j+70);
line(i+20,j+70,i-20,j+70);
}


No comments:

Post a Comment