Bresenham's Circle Drawing Algorithm
3)
#include<graphics.h>
#include<math.h>
main()
{
int gd=DETECT,gm;
int xc,yc,s,r,x,y;
initgraph(&gd,&gm," ");
printf("\nEnter x,y range");
scanf("%d%d",&xc,&yc);
xc+=20;
yc=470-yc;
printf("\nEnter the radius");
scanf("%d",&r);
cleardevice();
outtextxy(190,60,"**********BRESENHAM'S CIRCLE DRAWING ALGORITHM**********");
line(60,60,60,470);
line(20,440,550,440);
outtextxy(57,466,"v");
outtextxy(20,437,"<");
outtextxy(57,60,"^y");
outtextxy(547,437,">x");
x=0;
y=r;
s=3-2*y;
while(x<y)
{
bcircle(xc,yc,x,y);
if(s<0)
s=s+4*x+6;
else
{
s=s+4+(x+y)+10;
y=y-1;
}
x=x+1;
}
if(x==y)
{
bcircle(xc,yc,x,y);
}
getch();
}
bcircle(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,15);
putpixel(xc-x,yc+y,15);
putpixel(xc+x,yc-y,15);
putpixel(xc-x,yc-y,15);
putpixel(xc+y,yc+x,15);
putpixel(xc-y,yc+x,15);
putpixel(xc+y,yc-x,15);
putpixel(xc-y,yc-x,15);
}
CODE:
#include<stdio.h>
#include<conio.h>#include<graphics.h>
#include<math.h>
main()
{
int gd=DETECT,gm;
int xc,yc,s,r,x,y;
initgraph(&gd,&gm," ");
printf("\nEnter x,y range");
scanf("%d%d",&xc,&yc);
xc+=20;
yc=470-yc;
printf("\nEnter the radius");
scanf("%d",&r);
cleardevice();
outtextxy(190,60,"**********BRESENHAM'S CIRCLE DRAWING ALGORITHM**********");
line(60,60,60,470);
line(20,440,550,440);
outtextxy(57,466,"v");
outtextxy(20,437,"<");
outtextxy(57,60,"^y");
outtextxy(547,437,">x");
x=0;
y=r;
s=3-2*y;
while(x<y)
{
bcircle(xc,yc,x,y);
if(s<0)
s=s+4*x+6;
else
{
s=s+4+(x+y)+10;
y=y-1;
}
x=x+1;
}
if(x==y)
{
bcircle(xc,yc,x,y);
}
getch();
}
bcircle(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,15);
putpixel(xc-x,yc+y,15);
putpixel(xc+x,yc-y,15);
putpixel(xc-x,yc-y,15);
putpixel(xc+y,yc+x,15);
putpixel(xc-y,yc+x,15);
putpixel(xc+y,yc-x,15);
putpixel(xc-y,yc-x,15);
}
Comments
Post a Comment