Академический Документы
Профессиональный Документы
Культура Документы
C/ C++ Stats:
Sponsored by:
Code/Articles
Newest
Browse categories
Search
-----------------------
Upload code / articles
Open letter from moderators
-----------------------
Articles & tutorials
Recommended reading
Top Code
Coding contest
Coding contest leader board
Coding contest 'All-Time Hall of Fame'
-----------------------
Code of the day newsletter
Community
Ask a pro discussion forum
Games
Code of the day newsletter
Jobs
Search for a job
Post a job
Other
My profile
How to link to us
Awards/Reviews/Raves!
Advertising/Media kit
Feedback
About the site
Goto…
C/ C++ home
Site home
Other sites
Print
Bresenham's Line Drawing Algorithm
Email
Submitted on: 9/6/2012 2:57:42 PM
By: Rekha Ram Chaudhary
Level: Beginner
User Rating: Unrated
Compatibility:C
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:
By using this code, you agree to the following terms...
1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages
that allow it) freely and with no charge.
2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so
is a violation of copyright laws.
3. You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
//**************************************
// Name: Bresenham's Line Drawing Algorithm
// Description:This is a simple program to implement Bresenham's Line Drawing Algorithm in
// By: Rekha Ram Chaudhary
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Sourc
#include "stdio.h"
#include "conio.h"
#include "math.h"
#include "graphics.h"
main()
{
int gd=DETECT,gm;
int xa,xb,ya,yb;
int dx,dy,x,y,xend,p;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("Enter The Two Left Endpoints(xa,ya):\n");
scanf("%d%d",&xa,&ya);
printf("Enter The Two Right Endpoints(xb,yb):\n");
scanf("%d%d",&xb,&yb);
dx=abs(xa-xb);
dy=abs(ya-yb);
p=2*dy-dx;
if(xa>xb)
{
x=xb;
y=yb;
xend=xa;
}
else
{
x=xa;
y=ya;
xend=xb;
}
putpixel(x,y,6);
while(x<xend)
{
x=x+1;
if(p<0)
{
p=p+2*dy;
}
else
{
y=y+1;
p =p+2*(dy-dx);
}
putpixel(x,y,6);
}
getch();
return(0);
}
Is this code not quite what you want? Click here for custom coding.
Report it!
Your Vote!
Excellent Good Average Below Average Poor Rate It! See Voting Log. If this
code was not quite what you wanted, then click here for custom coding.
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email
account you registered on the site, so you can correspond directly.
NOTICE: The author of this code has been kind enough to share it with you. If you have a
criticism, please state it politely or it will be deleted.
For feedback not related to this particular code, please click here.
Login
Matrix
Calculations
By Kishan Singh
on 10/2
Scientific
Calculator 001
By Kishan Singh
Clickon
here to put this ticker
10/2
on your site!
Daily
ByCode Email
Dasttann777
on 10/2
Click here to join the
'Code of the Day' mailing list!
ThisBySite
sam on
lee CD
on
9/26
Code/Articles
Newest
Browse categories
Search
Upload code / articles
Open letter from moderators
Articles & tutorials
Recommended reading
Top Code
Coding contest
Coding contest leader board
Community
Jobs
Other
My profile
How to link to us
Awards/Reviews/Raves!
Advertising/Media kit
Feedback
About the site
Goto…
C/ C++ home
Site home
Other sites
By using this site you agree to its Terms and Conditions. Planet Source Code™ and the
phrase "Dream It. Code It"™ are trademarks of Exhedra Solutions, Inc.