Ex no:3 CIRCLE DRAWING USING MIDPOINT ALGO.
Date:
Aim:
To write a C++ Program to draw a circle using MIdpoint algorithm.
Algorithm:
Step1: Start the program.
Step2: Initialize the variables.
Step3: Call the initgraph() function
Step4: Get the values for centre end points for drawing a circle
Step5: Calculate the distance to be traveled by the circle.
Step6: Put the pixels in the given color to draw the circle.
Step7: Display the output.
Step8: Stop the program
PROGRAM
#include "stdio.h"
#include "conio.h"
#include "math.h"
#include "graphics.h"
main()
{
intgd=DETECT,gm;
intxcenter,ycenter,radius;
intp,x,y;
initgraph(&gd,&gm,"c:\\tc\\bgi");
x=0;
printf("Enter The Radius Value:\n");
scanf("%d",&radius);
y=radius;
printf("Enter The xcenter and ycenter Values:\n");
scanf("%d%d",&xcenter,&ycenter);
plotpoints(xcenter,ycenter,x,y);
p=1-radius;
while(x<y)
{
if(p<0)
x=x+1;
else
{
x=x+1;
y=y-1;
}
if(p<0)
p=p+2*x+1;
else
p=p+2*(x-y)+1;
plotpoints(xcenter,ycenter,x,y);
}
getch();
return(0);
}
intplotpoints(intxcenter,intycenter,intx,int y)
{
putpixel(xcenter+x,ycenter+y,1);
putpixel(xcenter-x,ycenter+y,1);
putpixel(xcenter+x,ycenter-y,1);
putpixel(xcenter-x,ycenter-y,1);
putpixel(xcenter+y,ycenter+x,1);
putpixel(xcenter-y,ycenter+x,1);
putpixel(xcenter+y,ycenter-x,1);
putpixel(xcenter-y,ycenter-x,1);
return(0);
}
OUTPUT
Enter the Radius Value : 80
Enter The xcenter and ycenterValues : 230 260
0 comments:
Post a Comment