Technicalsymposium



Join Our Email Alerts-Subscribe
Important Note:Login & Check Your Email Inbox and Activate Confirmation Link


Enter Your Email :

Computer Graphics Lab Codings-BRESENHAMíS CIRCLE ALGORITHM

Aim:

To write a C++ Program to draw a line using Bresenhams algorithm.

Algorithm:

1. Start the program .

2. Initialize the variables.

3. Call the initgraph() function

4. Get the values for left and right end points for drawing a line..

5. Calculate the distance to be traveled by the line.

6. Put the pixels in the given color to draw the line.

7. Display the output.

8. stop the program

PROGRAM:

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

int x,y,p;

void plotcircle(int xc,int yc,int color)

{

putpixel(xc+x,yc+y,color);

putpixel(xc+y,yc+x,color);

putpixel(xc+x,yc-y,color);

putpixel(xc+y,yc-x,color);

putpixel(xc-x,yc-y,color);

putpixel(xc-y,yc-x,color);

putpixel(xc-x,yc+y,color);

putpixel(xc-y,yc+x,color);

}

void bicircle(int xcen,int ycen,int rad,int color)

{

x=0;

y=rad;

plotcircle(xcen,ycen,color);

p=1-rad;

while(x<y)

{

if(p<0)

++x;

else

{

++x;

--y;

}

if(p<0)

p+=2*x+1;

else

{

p+=2*(x-y)+1;

plotcircle(xcen,ycen,color);

}

}

}

void main()

{

int gd=DETECT,gm,xc,yc,radius,color;

initgraph(&gd,&gm,"");

printf("\nEnter x pos,y pos and radius");

scanf ("%d%d%d",&xc,&yc,&radius);

x=0;

y=radius;

plotcircle(xc,yc,color);

p=1-radius;

while(x<y) {

if(p<0)

++x;

else

{

++x;

--y;

}

if(p<0)

p+=2*x+1;

else

{

p+=2*(x-y)+1;

plotcircle(xc,yc,color);

}

}

getch();

bicircle(xc,yc,radius,color);

}


All Programming Codes/Onlie Training/ Lab Manuals Download