Write C++/Java program to draw circle using Bresenham‘s algorithm. Inherit pixel class.
Second Year Computer Engineering Computer Graphics Programs:
Computer Graphics Lab:
Practical 2:
Write C++/Java program to draw circle using Bresenham‘s algorithm. Inherit pixel class.
----------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <graphics.h>
using namespace std;
void circle(int x1,int y1,int r)
{
int x,y,d;
x=0;
y=r;
d=3-(2*r);
while(x<=y)
{
putpixel(x1+x,y1+y,RED);
putpixel(x1-x,y1+y,RED);
putpixel(x1+x,y1-y,RED);
putpixel(x1-x,y1-y,RED);
putpixel(x1+y,y1+x,RED);
putpixel(x1-y,y1+x,RED);
putpixel(x1+y,y1-x,RED);
putpixel(x1-y,y1-x,RED);
x=x+1;
if(d<0)
{
d=d+4*x+6;
}
else
{
d=d+4*(x-y)+10;
y=y-1;
}
delay(40);
}
}
int main()
{
int x1,y1,r;
cout<<"Enter the starting co-ordinates of a center:";
cin>>x1>>y1;
cout<<"Enter the value of radius:";
cin>>r;
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
circle(x1,y1,r);
getch();
closegraph();
return 0;
}
----------------------------------------------------------------------------------------------------------------------------------
Comments
Post a Comment