Technicalsymposium.com-Free Email Alerts


Enter Your Email :

Important Note:Login & Check Your Email Inbox and Activate Confirmation Link

Subscribe & Get All Fresher Jobs Information & Study Materials PDF and Projects- Free Download

Computer Graphics Book PDF


Computer Graphics Projects


CG Projects PDF



Computer Graphics Source Codings & Projects PDF- Free Download

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);

}

Download All C Programming & Study Materials PDF