Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Computer GraphicsRSS Feeds

Program of DDA line drawing algorithm

Posted By: Easy Tutor     Category: C++ Programming     Views: 48675

Write a program of DDA line drawing algorithm.

Code for Program of DDA line drawing algorithm in C++ Programming

# include <graphics.h>
# include <math.h>
# include <conio.h>
# include <iostream.h>
void DDALine(int x1,int y1,int x2,int y2,int iColor);
void main()
{
    int gDriver=DETECT,gMode;

    int x1,x2,y1,y2,iColor;

    initgraph(&gDriver,&gMode,"c:\\tc\\bgi");
    cleardevice();
    cout<<endl<<"Enter x1  : ";
    cin>>x1;
    cout<<"Enter y1  : ";
    cin>>y1;
    cout<<endl<<"Enter x2  : ";
    cin>>x2;
    cout<<"Enter y2  : ";
    cin>>y2;
    cout<<endl<<"Enter COLOR  : ";
    cin>>iColor;
    cleardevice();
    DDALine(320,1,320,480,12);
    DDALine(1,240,640,240,12);
    circle(320,240,2);
    DDALine(320+x1,240-y1,320+x2,240-y2,iColor%16);
    getch();
}

void DDALine(int x1,int y1,int x2,int y2,int iColor)
{
    float dX,dY,iSteps;
    float xInc,yInc,iCount,x,y;

    dX = x1 - x2;
    dY = y1 - y2;

    if (fabs(dX) > fabs(dY))
    {
        iSteps = fabs(dX);
    }
    else
    {
        iSteps = fabs(dY);
    }

    xInc = dX/iSteps;
    yInc = dY/iSteps;

    x = x1;
    y = y1;
    circle(x,y,1);

    for (iCount=1; iCount<=iSteps; iCount++)
    {
        putpixel(floor(x),floor(y),iColor);
        x -= xInc;
        y -= yInc;
    }
    circle(x,y,1);
    return;
}
  
Share: 


Didn't find what you were looking for? Find more on Program of DDA line drawing algorithm Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program of DDA line drawing algorithm is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 

Other Interesting Articles in C++ Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!