Page 63 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 63
Unit 4: Implementing Circle Algorithm
printf(“Enter the radius of the circle :”); Notes
scanf(“%d”, &R);
clrscr();
driver = DETECT;
initgraph(&driver, &mode, “\\tc\\bgi”); //the path may be different in your case.
draw_circle(x c , y c , R);
getch();
closegraph();
}
void draw_circle(int xc, int yc, int rad)
{
int x = 0;
int y = rad;
int p = 1–rad;
symmetry(x, y, x c , y c );
for(x= 0; y>x; x++)
{
if(p<0)
p += 2*x + 3;
else
{
p += 2*(x–y) + 5;
y– –;
}
symmetry(x, y, x c , y c );
}
}
void symmetry(int x, int y, int x c , int y c )
{
putpixel(x c +x, y c – y, EGA_WHITE);//For pixel (x, y)
putpixel(x c +y, y c – x, EGA_WHITE);//For pixel (y, x)
putpixel(x c +y, y c +x, EGA_WHITE);//For pixel (y, – x)
putpixel(x c +x, y c +y, EGA_WHITE);//For pixel (x, – y)
putpixel(x c – x, y c +y, EGA_WHITE);//For pixel (–x,–y)
putpixel(x c –y, y c +x, EGA_WHITE);//For pixel (–y,–x)
putpixel(x c –y, y c –x, EGA_WHITE);//For pixel (–y, x)
putpixel(x c –x, y c –y, EGA_WHITE);//For pixel (–x, y)
}
Output
Example Result Output Computer Graphics
Enter the centre point:
400
200
LOVELY PROFESSIONAL UNIVERSITY 57