Friday, June 21, 2013

ball hitting wicket using graphics in C

//cricket by fensa
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
 float x=1,y=0.0,j=0.5,count=0.1,i,k,r=10;
 int gd=DETECT,gm;
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 line(0,210,650,210);
 line(470,150,470,210);//stump
 line(490,150,490,210);
 line(510,150,510,210);
 line(471,149,489,149);//wicket
 line(491,149,509,149);

 sleep(1);

 for(k=0;k<3;k++)
 {
  for(i=90;i<=250;i=i+5)
  {
    y=cos((i*22/7)/180)/j;
    if(y>0)
    y=-y;
    x=x+5;
    setcolor(14);
    setfillstyle(1,14);
    circle(x,y*100+200,r);
    floodfill(x,y*100+200,14);
    delay(40);
    setcolor(0);
    setfillstyle(1,0);
    circle(x,y*100+200,r);
    floodfill(x,y*100+200,0);
  }
    j=j+count;
    count=count+0.1;
 }
 cleardevice();
 setcolor(15);
 line(0,210,650,210);
 line(450,150,470,210);//stump
 line(490,150,490,210);
 line(530,150,510,210);
 line(471,149,489,139);//wicket
 line(493,139,512,149);
 getch();
}

No comments:

Post a Comment