Sem 4‎ > ‎CG LAB‎ > ‎

P6: WAP to draw a circle using MidPoint Algo

posted Jan 25, 2012, 2:46 AM by Neil Mathew
 

SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void DrawPoints(int x, int y, int xc, int yc)
{
putpixel(xc+x,yc+y, CYAN);
putpixel(xc-x,yc+y, CYAN);
putpixel(xc+x,yc-y, CYAN);
putpixel(xc-x,yc-y, CYAN);
putpixel(xc+y,yc+x, CYAN);
putpixel(xc+y,yc-x, CYAN);
putpixel(xc-y,yc+x, CYAN);
putpixel(xc-y,yc-x, CYAN);
}
void MidPontCircle(int xc, int yc, int r)
{
int x=0;
int y=r;
DrawPoints(x,y,xc,yc);
 
int P= (int) 5.0/4.0 - r;
 
while(x < y)
{
       if(P < 0)
       {
       P=P+2*x+3;
       DrawPoints(++x, y, xc, yc);
       }
       else
       {
       P=P+2*(x-y)+5;
       DrawPoints(++x,--y, xc, yc);
       }
} }
 
 
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
 
int r;
int xc=getmaxx()/2;
int yc=getmaxy()/2;
 
cout<<"\n Enter the radius: ";
cin>>r;
 
MidPontCircle(xc,yc,r);
 
getch();
closegraph();
 
}


OUTPUT:



Comments