
To draw a circle using Bresenham
circle drawing algorithm.
ALGORITHM:
1.
Start
2.
Initialize the graphics mode.
3.
Read the radius of the circle
4.
Initialize the graphics mode.
5.
Initialize starting points x=0,y=r
6.
Initialize decision variable d=3 –
2 * r
7.
plot(x,y)
a.
plot eight points
(+x,+y),(+x,-y),(-x,+y),(-x,-y),(+y,+x) ,(+y,-x),
(-y,+x),(-y,-x)
8.
If d< =0 , d = d + 4 * x +6 else {d = d + 4 (x-y) +10, y = y-1}
9.
x=x+1
10. insert
delay to observe the drawing process
11. Repeat
6- 10 until x<y
PROGRAM:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
main()
{
int
gd=DETECT,gm,x=0,radius,xc,yc,y,p;
void
circleplotpoint(int,int,int,int);
initgraph(&gd,&gm,"");
setbkcolor(15);
setcolor(BLUE);
outtextxy(160,10,"BRESENHAM'S CIRCLE GENERATION ALGORITHM");
printf("\n\nEnter The Values (xc,yc):");
scanf("%d %d",&xc,&yc);
printf("\n\nEnter The Radius :");
scanf("%d",&radius);
cleardevice();
outtextxy(160,10,"BRESENHAM'S CIRCLE GENERATION ALGORITHM");
y=radius;
p=3-2*radius;
while(x<y)
{
x++;
if(p<0)
p+=4*x+6;
else
{
y--;
p+=4*(x-y)+10;
}
circleplotpoint(xc,yc,x,y);
delay(200);
}
getch();
closegraph();
}
void circleplotpoint(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+x,yc-y,5);
putpixel(xc-x,yc-y,8);
putpixel(xc+y,yc+x,3);
putpixel(xc-y,yc+x,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,8);
}
2 comments:
I having lot of had project so plz send me java coding of medical shop management system in java
send me java coding of project medical shop management system
Post a Comment