Graphics Programs: Draw Circle using Polynomial Method
Source Code
/********************************************************** * Program : Simple Circle Drawing Algorithm * Author : Vijay Kumar Verma (VJY) | MCA * Website : vjysoftworx.com * Date : 25-Jan-2014 ***********************************************************/ #include ‹iostream.h› #include ‹conio.h› #include ‹graphics.h› #include ‹math.h› int main(){ int dr=DETECT, md; initgraph(&dr,&md,"c:\\tc\\bgi"); int h, k, r, x, y, xe,col; cout<<"Enter co-ordinate of center(h,k): "; cin>>h>>k; cout<<"Enter radius: "; cin>>r; cout<<"Enter Color code(0-15): "; cin>>col; x= 0; xe = (int)r/sqrt(2)+0.5; //calculate the end point of x y = r; //add the value of r to y while(x <= xe){ putpixel(x+h,y+k, col); putpixel(x+h,-y+k,col); putpixel(y+h,-x+k, col); putpixel(-y+h,-x+k, col); putpixel(-x+h,-y+k, col); putpixel(-x+h,y+k, col); putpixel(-y+h,x+k, col); putpixel(y+h,x+k, col); x++; y = (int)sqrt(r*r-x*x)+0.5; //calculate the value of y } getch(); closegraph(); return 0; }Output:
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment