Tuesday 18 August 2015

Midpoint Circle Drawing Program (Source Code)

/*Midpoint Circle Drawing Program*/

#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<iostream.h>
#include<dos.h>
void main()
{
float  p;
int i,gd,gm,x,y,maxx,maxy;
int r;

/* initialise graphics
------------------------ */
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");

/* Read the radius
----------------------- */
cout<<"Enter the radius of the circle : ";
cin>>r;

x=0;
y=r;
p = 1.25 - r;
maxx=getmaxx();
maxy=getmaxy();
do
{
putpixel((maxx/2)+x,(maxy/2)+y,5);
putpixel((maxx/2)+y,(maxy/2)+x,6);
putpixel((maxx/2)+x,(maxy/2)-y,7);
putpixel((maxx/2)+y,(maxy/2)-x,8);
putpixel((maxx/2)-x,(maxy/2)-y,9);
putpixel((maxx/2)-x,(maxy/2)+y,10);
putpixel((maxx/2)-y,(maxy/2)+x,11);
putpixel((maxx/2)-y,(maxy/2)-x,12);

if (p < 0)
{
x = x+1;
y = y;
p = p + 2*x + 2;
}
else
{
x= x+1;
y= y-1;
p = p + 2*(x-y) + 1;
}
delay(20);
}
while(x < y);
getch();
closegraph();
}

For OUTPUT check out the video! :



Ps: Please Like and Subscribe--->> https://youtu.be/1xhMs9qko3M

No comments:

Post a Comment