6 Feb 2013

Program in c/c++ for printing a pattern using dda algorithm


/* Program in c/c++ for printing a pattern using dda algorithm */
#include<graphics.h>
#include<conio.h>
void add(int x1,int y1,int x2,int y2)
{
  int dx,dy,m,s;
  float xi,yi,x,y;
   dx = x2 - x1;
    dy = y2 - y1;

    if (abs(dx) > abs(dy))
    {
s = abs(dx);
    }
    else
    {
s = abs(dy);
     }
    xi = dx / (float) s;
    yi = dy / (float) s;

    x = x1;
    y = y1;

    putpixel(x1, y1, 2);
delay(3);

    for (m = 0; m < s; m++)
{
x += xi;
y += yi;
putpixel(x, y, 2);
delay(3);
    }

}
void main ()
{
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C://tc/BGI");
add(20,50,250,50);
add(250,50,250,200);
add(250,200,20,200);
add(20,200,20,50);
add(40,70,80,70);
add(80,70,80,100);
add(80,100,40,100);
add(40,100,40,70);
add(190,70,230,70);
add(230,70,230,100);
add(230,100,190,100);
add(190,100,190,70);
add(115,150,155,150);
add(155,150,155,180);
add(155,180,115,180);
add(115,180,115,150);
getch();
}


OUTPUT:

No comments:

Post a Comment