0% found this document useful (0 votes)
419 views2 pages

#Include #Include #Include Int Round (Float) Void Main

This C program uses the DDA line drawing algorithm to draw a line between two endpoints on a graph. It initializes graphics mode, gets the x and y coordinates of the start and end points from the user, calculates the change in x and y per step, and uses a for loop to incrementally draw pixels between the points over the total number of steps. It rounds the x and y values to integers before drawing each pixel to smooth the line.

Uploaded by

abhishek6c1109
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
419 views2 pages

#Include #Include #Include Int Round (Float) Void Main

This C program uses the DDA line drawing algorithm to draw a line between two endpoints on a graph. It initializes graphics mode, gets the x and y coordinates of the start and end points from the user, calculates the change in x and y per step, and uses a for loop to incrementally draw pixels between the points over the total number of steps. It rounds the x and y values to integers before drawing each pixel to smooth the line.

Uploaded by

abhishek6c1109
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<conio.h>
#include<graphics.h>
int Round(float);
void main()
{

int x1,x2,y1,y2,x,y,dx,dy,steps,abs_dx,abs_dy,k;
float xincrement,yincrement;

int gdriver = DETECT, gmode, errorcode;

/* initialize graphics mode */

initgraph(&gdriver, &gmode, "c:\\tc\\bgi");


//algo linedda(x1,y1,x2,y2)
//here the endpoints are (x1,y1) and (x2,y2)
//Round(x)=int(x+0.5)

printf("Enter first  endpoint= ");


scanf("%d %d",&x1,&y1);
printf("Enter second endpoint= ");
scanf("%d %d",&x2,&y2);

dx=x2-x1;
dy=y2-y1;
x=x1;
y=y1;
if(dx<0)
abs_dx=dx*(-1);
else
abs_dx=dx;

if(dy<0)
abs_dy=dy*(-1);
else
abs_dy=dy;

if(abs_dx>=abs_dy)
steps=abs_dx;
else
steps=abs_dy;

xincrement=(abs_dx/steps);
yincrement=(abs_dy/steps);
putpixel(Round(x),Round(y),2);

for(k=1;k<=steps;k++)
{
  x=x+xincrement;
  y=y+yincrement;
  putpixel(Round(x),Round(y),2);
}

getch();
}

int Round(float z)
{
int z1,z2;
z1=z+0.5;
z2=(int)z;
if((z2-z1)>=0.5)
{
z=z2+1;
}
return z;
}

You might also like