Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
834 B
3
Indexable
Never
// Implement DDA Algorithm

#include<graphics.h>  
#include<conio.h>  
#include<stdio.h>  
int main()  
{  
    int gd = DETECT ,gm, i;  
    float x, y,dx,dy,steps;  
    int x0, x1, y0, y1;  
    initgraph(&gd, &gm, "C:\\TC\\BGI");  
    setbkcolor(WHITE);  
    printf("Enter two end points (x0,y0) and (x1,y1): \n");
	scanf("%d%d%d%d",&x0,&y0,&x1,&y1);  
    dx = (float)(x1 - x0);  
    dy = (float)(y1 - y0);  
    if(dx>=dy)  
           {  
        steps = dx;  
    }  
    else  
           {  
        steps = dy;  
    }  
    dx = dx/steps;  
    dy = dy/steps;  
    x = x0;  
    y = y0;  
    i = 1;  
    while(i<= steps)  
    {  
        putpixel(x, y, RED);  
        x += dx;  
        y += dy;  
        i=i+1;  
    }  
    getch();  
    closegraph();  
    return 0;
}  
Leave a Comment