Tag Cloud

CRM 2011 (161) CRM 4.0 (144) C# (116) JScript (109) Plugin (92) Registry (90) Techpedia (77) PyS60 (68) WScript (43) Plugin Message (31) Exploit (27) ShellCode (26) FAQ (22) JavaScript (21) Killer Codes (21) Hax (18) VB 6.0 (17) Commands (16) VBScript (16) Quotes (15) Turbo C++ (13) WMI (13) Security (11) 1337 (10) Tutorials (10) Asp.Net (9) Safe Boot (9) Python (8) Interview Questions (6) video (6) Ajax (5) VC++ (5) WebService (5) Workflow (5) Bat (4) Dorks (4) Sql Server (4) Aptitude (3) Picklist (3) Tweak (3) WCF (3) regex (3) Config (2) LINQ (2) PHP (2) Shell (2) Silverlight (2) TSql (2) flowchart (2) serialize (2) ASHX (1) CRM 4.0 Videos (1) Debug (1) FetchXml (1) GAC (1) General (1) Generics (1) HttpWebRequest (1) InputParameters (1) Lookup (1) Offline Plug-ins (1) OutputParameters (1) Plug-in Constructor (1) Protocol (1) RIA (1) Sharepoint (1) Walkthrough (1) Web.config (1) design patterns (1) generic (1) iframe (1) secure config (1) unsecure config (1) url (1)

Pages

Wednesday, August 03, 2011

Bresenham line drawing algorithm


#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<iostream.h>


//Bresenham line drawing algorithm
//ULTIMATE NAPSTR


int wid;
void setpixel(int cx, int cy, int cz)
{
//setcolor(8);
bar(cx,cy,cx+cz,cy+cz);
}





void linebres(int xa,int ya,int xb,int yb)
{
int dx,dy,x,y,xend,p;
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;
}
setpixel(x,y,wid);
while (x < xend)
{
x++;
if (p < 0)
{
p = p + 2 * dy;
}
else
{
y++;
p = p + 2 * (dy - dx);
}
setpixel(x,y,wid);
}
}






void main()
{
clrscr();
int gdriver=DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "\\tc\\bgi");




/*if (errorcode != grOk)  // an error occurred
{
   printf("Graphics error: %s\n", grapherrormsg(errorcode));
   printf("Press any key to halt:");
   getch();
   exit(1);             // return with error code
}
*/
int x1,x2,y1,y2;


cout<<" BRESENHAM LINE DRAWING"<<endl;
cout<<"Input X1 < 639 ";
cin>>x1;
cout<<"Input Y1 < 479 ";
cin>>y1;
cout<<"Input X2 < 639 ";
cin>>x2;
cout<<"Input Y2 < 479 ";
cin>>y2;
cout<<"input line width";
cin>>wid;
clrscr();
linebres(x1,y1,x2,y2);


getch();
}





No comments: