


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



#include<stdio.h> #include<conio.h> #include<dos.h> //for delay()function #include<graphics.h> int abs_val(int n) //to calculate absolute value to plot { if (n>0) { return n; } else { return -n; } } int dda(int x1,int y1,int x2, int y2) //line drawing algorithm { int dx, dy , step; float xinc,yinc,x,y; dx = x2-x1; dy = y2-y1; if(abs_val(dx)>abs_val(dy)) { step = abs_val(dx); }
else { step = abs_val(dy); } xinc = dx/step; yinc = dy/step; x=x1; y=y1; for(int i = 0; i<=step; i++) //putting pixels { if(i%2==0) { x+=xinc; y+=yinc; delay(200); } putpixel(x,y,YELLOW); x+=xinc; y+=yinc; delay(200); } return 0; } int main() { int gd = DETECT,gm; int x1,x2,y1,y2; clrscr(); initgraph(&gd,&gm,"..\BGI"); printf("\n\nSiddhi Mehta - 213\n\n"); printf("Enter Starting points of line: "); scanf("%d %d",&x1,&y1); printf("Enter Ending points of line: "); scanf("%d %d",&x2,&y2);