MIDPOINT ELLIPSE DRAWING PROGRAM IN C
Similar Programs
- Flood Fill program in C
- Triangle Rotation Program
- Text animation program in C
- C program for fixed point scaling and rotation
- C Program for shearing of triangle, line and rectangle
- C program to plot different types of lines
- Scaling program in C
- Font animation program in C
- Midpoint ellipse drawing program in C
- Circle Midpoint program in C
- Translation program in C
- Bresenhem Circle drawing program in C
- String Generation program in C
- Bresenhem Line drawing program in C
- Plotting a pixel in C
- DDA line drawing program in C
- Boundary fill program in C
- Character Generation program in C
- Triangle Rotation program in C
#include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> #define Round(a)((int)(a+0.5)) void emidpoint(int xc, int yc, int a, int b); void eplotpoints(int, int ,int,int); void main() { int gd=DETECT,gm,x1,y1,a1,b1,xc,yc,x,y; initgraph(&gd,&gm,"../bgi"); printf("enter the center coordinates:"); scanf("%d%d",&x1,&y1); printf("enter a and b such that b>>a:"); scanf("%d%d",&a1,&b1); emidpoint(x1,y1,a1,b1); eplotpoints(xc,yc,x,y); getch(); } void emidpoint(int xc, int yc, int a, int b) { int a2=a*a; int b2=b*b; int twoa2=2*a2; int twob2=2*b2; int p; int x=0; int y=b; int px=0; int py=twoa2*b; eplotpoints(xc,yc,x,y); /*Region 1*/ p=Round(b2-(a2*b)+(0.25*a2)); while(px<py) { x++; px+=twoa2; if(p<0) p+=b2+px; else { y--; py-=twoa2; p+=b2+px-py; } eplotpoints(xc,yc,x,y); }
/*Region 2*/ p=Round(b2*(x+0.5)*(x+0.5)+a2*(y-1)*(y-1)-(a2*b2)); while(y>0) { y--; py-=twoa2; if(p>0) p+=a2-py; else { x++; px+=twob2; p+=a2-py+px; } eplotpoints(xc,yc,x,y); } } void eplotpoints(int xc, int yc, int x, int y) { delay(100); putpixel(xc+x,yc-y,58); putpixel(xc-x,yc-y,58); putpixel(xc+x,yc+y,58); putpixel(xc-x,yc+y,58); }
0 comments:
Post a Comment