This is the most popular algorithm in graphics programming.In this c programming is related to graphics programming when you will
run this program in you own mechine do not forget to set the path. of
you don't the program will not work.
/* mid point circle algorithm using C http://native-code.blogspot.com -------------------------------------------- */ #include<stdio.h> #include<conio.h> #include<graphics.h> #define GPATH "C:\\TC\\BGI" void mp(int, int, int); void cpp(int, int, int, int); void main() { int xc, yc, r; int gd=DETECT, gm; initgraph(&gd, &gm, GPATH); printf("\nEnter radius:\n"); scanf("%d", &r); printf("\nEnter the centre of X and Y:\n"); scanf("%d %d", &xc, &yc); mp(r, xc, yc); getch(); } void mp(int r, int xc, int yc) { int x, y, p; x=0; y=r; p=1-r; cpp(xc, yc, x, y); while(x<=y) { x++; if(p<0) p+=2*(x-1); else { p+=2*(x-y)+1; y--; } cpp(xc, yc, x, y); } } void cpp(int xc, int yc, int x, int y) { putpixel(xc+x, yc+y, WHITE); putpixel(xc+y, yc+x, WHITE); putpixel(xc-x, yc+y, WHITE); putpixel(xc+y, yc-x, WHITE); putpixel(xc+x, yc-y, WHITE); putpixel(xc-y, yc+x, WHITE); putpixel(xc-x, yc-y, WHITE); putpixel(xc-y, yc-x, WHITE); }
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us
Post a Comment