Write a Program to implement bouncing ball using sine wave form.

 Write a Program to implement bouncing ball using sine wave form.

  1. #include<stdio.h>  
  2. #include<graphics.h>   
  3. #define HEIGHT getmaxy()  
  4. #define WIDTH getmaxx()  
  5. #define GROUND 450  
  6. #define MAXHEIGHT 420   
  7. void main()  
  8. {  
  9.         int x,y=0,t=MAXHEIGHT,c=1;  
  10.         int gd=DETECT,gm;  
  11.        initgraph(&gd,&gm,"C:\\T urboC3\\BGI");   
  12.       for(x=40;x<=getmaxx();x=x+2)  
  13.  {  
  14.      //Draw Ground  
  15.      rectangle (0,MAXHEIGHT,getmaxx(),MAXHEIGHT+5);  
  16.      floodfill (5,MAXHEIGHT+3,WHITE);  
  17.     //Draw Ball  
  18.    pieslice(x,y,0,360,20);  
  19.    //floodfill(x,y,RED);  
  20.    delay(100);  
  21.    if(y>MAXHEIGHT-20)  
  22.      {  
  23.          c=0;  
  24.          t=t-40;  
  25.      }  
  26.      if(y<=(MAXHEIGHT-t))  
  27.     {  
  28.            c=1;  
  29.      }  
  30.         if(t>=40)  
  31.        y=y+(c? 15:-15);   
  32.        cleardevice();  
  33.        //Exit upon keypress  
  34.        if(kbhit())  
  35.        break;  
  36. }  
  37. getch();  
  38. }  

Output

Computer Graphics Programs

Post a Comment

Previous Post Next Post