The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Friday, April 15, 2011

Reflecting Circle Animation


#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>


void init_graph();
void bresenham_circle(const int,const int,const int,int);

void main( )
{
 int ho = 95;
 int ko = 55;
 int ro = 25;
 int hdo = 2;
 int kdo = 2;

 init_graph();

 do
 {
 ho += hdo;
 ko += kdo;
 cleardevice();
 if(ho <= 40 || ho >= 600)
  hdo *= -1;
 if(ko <= 10 || ko >= 470)
  kdo *= -1;
 bresenham_circle(ho,ko,ro,RED);
 delay(5);
 }while(!kbhit());
 getch();
}

void init_graph()
{
 int gdriver = DETECT, gmode, errorcode;
 initgraph(&gdriver, &gmode, "");
 errorcode = graphresult();
 if (errorcode != grOk)  /* an error occurred */
 {
   printf("Graphics error: %s\n", grapherrormsg(errorcode));
   printf("Press any key to halt:");
   getch();
 }
}



void bresenham_circle(const int h,const int k,const int r,int col)
{
 int x=0;
 int y=r;
 int p=(3-(2*r));
 do
 {
  putpixel(h+x,k+y,col);
  putpixel(h+y,k+x,col);
  putpixel(h+y,k-x,col);
  putpixel(h+x,k-y,col);
  putpixel(h-x,k-y,col);
  putpixel(h-y,k-x,col);
  putpixel(h-y,k+x,col);
  putpixel(h-x,k+y,col);
  x++;
  if(p<0)
   p+=((4*x)+6);
  else
  {
   y--;
   p+=((4*(x-y))+10);
  }
 }while(x<=y);

}

No comments:

Post a Comment