Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,954 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,323 people online right now. Registration is fast and FREE... Join Now!




Help in primitive graphics program

 
Reply to this topicStart new topic

Help in primitive graphics program

mohanrohith
5 Dec, 2007 - 03:26 AM
Post #1

New D.I.C Head
*

Joined: 21 Jul, 2007
Posts: 4


My Contributions
i have tried to write the code for implementing DDA algorithm for line drawing in turbo c++ 3.0.

but it is not running as some illegal operation has occured message appearing even though it complies without any error.

CODE

#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#define ROUND(a) ((int)(a+0.5))
#include<math.h>


void main()
{
int x,y,x1,y1,x2,y2,m,gd,gm;

clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI");
cout<<"Enter Starting points";
cin>>x1>>y1;
cout<<"Enter Ending points";
cin>>x2>>y2;

int sign=(x2>x1)?1:-1;

m=(y2-y1)/(x2-x1);
x=x1;
y=y1;
putpixel(x,y,WHITE);
if(abs(m)<=1)
{
  while(x<=x2||y<=y2)
  {
   x=x+sign*1;
   y=y+sign*m;
   putpixel(x,ROUND(y),WHITE);

  }
}
else
{
  while(x<=x2||y<=y2)
  {
   y=y+sign*1;
   x=x+sign*(1/m);
   putpixel(ROUND(x),y,WHITE);
  }
  }
  getch();
  closegraph();
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 05:56PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month