Mid Point Circle Algorithm
C Program For Mid Point Circle Algorithm Source Code: #include<stdio.h> #include<stdlib.h> #include<graphics.h> #include<conio.h> #include<math.h> ----------------------- Function Prototypes ------------------------- void show_screen( ); void midpoint_circle(const int,const int,const int); ------------------------------ main( ) ------------------------------ int main( ) { int driver=VGA; int mode=VGAHI; int h=0; int k=0; int r=0; clrscr(); do { show_screen( ); gotoxy(8,10); printf("Central Point of the Circle : (h,k) :"); gotoxy(8,11); printf("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"); gotoxy(12,13); printf("Enter the value of h = "); scanf("%d", &h); gotoxy(12,14); printf("Enter the value of k = "); scanf("%d", &k); gotoxy(8,18); printf("Radius of the Circle : r :"); gotoxy(8,19); printf("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"); gotoxy(12,21); printf("Enter the value of r = "); scanf("%d", &r); initgraph(&driver,&mode,"c:/tc/bgi"); setcolor(15); midpoint_circle(h,k,r); setcolor(15); outtextxy(110,460,"Pressto continue or any other key to exit."); int key=int(getch( )); if(key!=13) break; } while(1); return 0; } ------------------------ Funcion Definitions ------------------------ ----------------------- midpoint_circle( ) -------------------------- void midpoint_circle(const int h,const int k,const int r) { int color=getcolor( ); int x=0; int y=r; int p=(1-r); do { putpixel((h+x),(k+y),color); putpixel((h+y),(k+x),color); putpixel((h+y),(k-x),color); putpixel((h+x),(k-y),color); putpixel((h-x),(k-y),color); putpixel((h-y),(k-x),color); putpixel((h-y),(k+x),color); putpixel((h-x),(k+y),color); x++; if(p<0) p+=((2*x)+1); else { y--; p+=((2*(x-y))+1); } } while(x<=y); } -------------------------- show_screen( ) -------------------------- void show_screen( ) { restorecrtmode( ); textmode(C4350); textbackground(1); cprintf(" MidPoint Circle Algorithm "); textbackground(8); for(int count=0;count<42;count++) gotoxy(1,46); gotoxy(1,2); }
Tags:
Graphics& Multimedia
0 comments