You are on page 1of 2

CG EXPERIMENT 1

NAME: Shreyansh Raut UID: 18bcs1703

CODE:
#include<graphics.h>

#include<conio.h>

#include<stdio.h>

#include<math.h>

#include<dos.h>

#define round(a)((int)(a+0.5))

void main()

int gd=DETECT,gm,x,y,x0,y0,x1,y1,steps,dx,dy,i;

float xinc,yinc;

initgraph(&gd,&gm,"C:\\TURBOC3\\bgi");

printf("Enter the value of starting and ending point of the user");

scanf("%d",&x0);

scanf("%d",&y0);scanf("%d",&x1);scanf("%d",&y1);

dx=x1-x0;

dy=y1-y0;

if(abs(dx)>abs(dy))

steps=abs(dx);

else

steps=abs(dy);

xinc=(float)dx/steps;
yinc=(float)dy/steps;

x=x0;

y=y0;

putpixel(x,y,BLUE);

for(i=0;i<steps;i++)

x+=xinc;

y+=yinc;

putpixel(round(x),round(y),BLUE);

delay(200);

getch();

closegraph();

OUTPUT:

You might also like