Hello There, Guest! RegisterLogin with Facebook
Login with Facebook

Anna University TNEA 2018 Rank List Published. Login to know your Rank.
Anna University April May 2018 Exam Results
Anna University Latest News , Updates and Announcements
>>> Anna University Sixth Semester Question Bank Collection (R2013) ECE,MECH,CSE,IT,EEE,CIVIL,EIE
>>> Anna University Study Materials for all Departments
>>> Anna University Question Papers : April May June 2015 Question Papers | Nov Dec 2014 and Jan 2015 Question Papers

Register or Login to Submit Study Materials , Shoutbox and also to access Many Features !!

Vidyarthiplus Shop :: Handwritten Premium Lecture Notes
Share your Study Materials with us
Share your Study Materials with us : Click Here

IMPLEMENTATION OF BRESENHAM’S LINE C PROGRAM ALGORITHM
#1
Thumbs Up 


PROGRAM NAME:IMPLEMENTATION OF BRESENHAM’S LINE


PROGRAM LANGUAGE:C

PROGRAM SOFTWARE:C Complier

PROGRAM DESCRIPTION:[sub]The Bresenham line algorithm is an algorithm which determines which points in an n-dimensional raster should be plotted in order to form a close approximation to a straight line between two given points. The endpoints of the line are the pixels at (x0, y0) and (x1, y1), where the first coordinate of the pair is the column and the second is the row[/sub]


Code:
#include <graphics.h>  /* include the necessary header files*/
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void draw(int xa, int ya, int xb, int yb);
void main()
{
int xa, ya, xb, yb;
clrscr();
printf("Bresenhnams algorithm");  /* get the coordinates of the line*/
printf("\n Enter the value of xa, ya:");
scanf("%d%d",&xa,&ya);
printf("\n Enter the value of xb, yb:");
scanf("%d%d",&xb,&yb);
draw(xa,ya,xb,yb);
}
void draw(int xa, int ya, int xb, int yb)
{
int x,y,dx,dy,xend,p; /* request auto detection */
int gdriver=DETECT,gmode,errorcode;   /* initialize graphics and local variables */
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");   /* read result of initialization */
errorcode=graphresult();    /* an error occurred */
if(errorcode!=grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
dx=xb-xa;
dy=yb-ya;
p=2*dy-dx;  /* calculate the value of the condition variable*/
if(xa>xb)  /* depending on the position of the coordinates*/
{
x=xb;   /* assign the values for (x,y)*/
y=yb;
xend=xa;
}
else if(xb>xa)
{
x=xa;
y=ya;
xend=xb;
}
putpixel(x,y,1);  /* draw the pixel on the screen*/
while(x<xend)  /* depending on the control condition draw the pixels*/
{
x=x+1;
if(p<0)
{
p=p+2*dy;
}
else
{
y=y+1;
p=p+2*dy;
}
putpixel(x,y,1);
} /* clean up */
getch();
closegraph();
}


Heart
Make a Great History



Possibly Related Threads...
Thread Author Replies Views Last Post
  Fundamentals of Programming - PROGRAM USING while (),for(),switch() Yuvamalathi Velmani 1 757 06-08-2014, 07:44 AM
Last Post: Srini
  A doubt in Assembly lang. Program (PIC16f877a) tush_8600 0 763 03-11-2013, 03:55 PM
Last Post: tush_8600
  What is ALGORITHM in Programing Language ? Arthi Singaravelan 0 759 24-08-2013, 10:03 AM
Last Post: Arthi Singaravelan
  LOGIC BUILDING AND EFFECTIVE PROGRAM SOLVING Arthi Singaravelan 2 1,177 15-08-2013, 10:23 PM
Last Post: Srini
Lightbulb Create and run c++ program in visual studio 2010 venkateshmps 0 1,186 25-07-2013, 07:38 PM
Last Post: venkateshmps
  IMPLEMENTATION OF TWO DIMENSIONAL COMPOSITE TRANSFORMATIONS mohanmo 0 14,522 05-06-2013, 10:25 PM
Last Post: mohanmo
Thumbs Up IMPLEMENTATION OF TWO DIMENSIONAL TRANSFORMATIONS mohanmo 0 1,220 05-06-2013, 10:19 PM
Last Post: mohanmo
  IMPLEMENTATION OF MIDPOINT ELLIPSE ALGORITHM mohanmo 0 1,024 05-06-2013, 10:13 PM
Last Post: mohanmo
Thumbs Up IMPLEMENTATION OF MIDPOINT CIRCLE ALGORITHM mohanmo 0 904 05-06-2013, 10:01 PM
Last Post: mohanmo
  IMPLEMENTATION OF DDA LINE c Program mohanmo 0 891 05-06-2013, 09:51 PM
Last Post: mohanmo
Reply

Subscribe


Recommend on Google



Vidyarthiplus Whatsapp