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

Popular posts from this blog

Implement C++ program for expression conversion as infix to postfix and its evaluation using stack.

Write C++ program to maintain club member‘s information using singly linked list. Store student PRN and Name.

Write C++/Java program for line drawing using DDA or Bresenhams algorithm with patterns such as solid, dotted, dashed, dash dot and thick.