#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<math.h>
#define pie 3.14
void init_graph();
void bresenham_circle(const int,const int,const int,int);
void main( )
{
int h=320;
int k=300;
int r=50;
init_graph();
delay(1000);
do
{
bresenham_circle(h,k,r,WHITE);
floodfill(h,k-r+1,getmaxcolor());
delay(150);
if(k>=100)
k -= 1;
cleardevice();
line(0,300,100,150);
line(100,150,200,300);
line(200,300,250,200);
line(250,200,400,250);
line(400,250,450,50);
line(450,50,550,100);
line(550,100,650,0);
floodfill(50,350,getmaxcolor());
}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