Thursday, February 12, 2015

Write a c program to simulate a kite movement?

Write a c program to simulate a kite movement?
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<dos.h>
#include<alloc.h>
#include<stdlib.h>

#define RAD 3.141592/180

class fig

private:
int x1,x2,y1,y2,xinc,yinc;
public:
void kite()

x1=y1=10;x2=x1+40;y2=y1+40;
int poly[]=30,10,50,30,30,50,10,30;
int sang=240;
xinc=yinc=10;
setcolor(4);
setfillstyle(1,5);
fillpoly(4,poly);
setcolor(3);
arc(x1+20,y2,45,135,28);
line(x1+20,y1,x1+20,y2);
int s=imagesize(x1,y1,x2,y2);
void *buf=malloc(s);
getimage(x1,y1,x2,y2,buf);
setlinestyle(SOLID_LINE,1,1);
line(x1+20,y1+10,0,478);
setlinestyle(SOLID_LINE,1,3);
arc(x1-10,y2,sang,360,30);
while(!kbhit())
if(getpixel(x1+20,y1)!=0) putimage(x1,y1,buf,XOR_PUT);
setcolor(0);
setlinestyle(SOLID_LINE,1,1);
line(x1+20,y1+10,0,478);
setlinestyle(SOLID_LINE,1,3);
arc(x1-10,y2,sang,360,30);
setcolor(3);
if(sang>=240 && sang<300) sang+=10;
else if(sang>240 && sang>=300) sang-=10;
x1+=xinc;y1+=yinc;
x2+=xinc;y2+=yinc;
if(x2>=50 && x2<(getmaxx()-20) && y2>=50 && y2<(getmaxy()-20))
putimage(x1,y1,buf,COPY_PUT);
arc(x1-10,y2,sang,360,30);
setlinestyle(SOLID_LINE,1,1);
line(x1+20,y1+10,0,478);
delay(200);
continue;

if(!(x2>=50 && x2<(getmaxx()-20)))
xinc*=(-1);
x1+=xinc;x2=x1+40;
if(!(y2>=50 && y2<(getmaxy()-20)))
yinc*=(-1);
y1+=yinc;y2=y1+40;

free(buf);
getch();




void main()

int gd=DETECT,gm;
initgraph(&gd,&gm,"d:cplus");
fig f;
f.kite();
cleardevice();
closegraph();

No comments:

Post a Comment