Created
August 6, 2020 08:03
-
-
Save theabbie/37369cd296c6432ac6b2f65f92a252c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
#include<graphics.h> | |
#include<math.h> | |
#include<dos.h> | |
void main() | |
{ | |
int x,y,xa,ya,xb,yb,dx,dy,choice,p; | |
float xinc,yinc; | |
int gd = DETECT,gm; | |
initgraph(&gd,&gm,"c:\\tc\\bgi"); | |
cleardevice(); | |
printf("Enter the co-ordinates of the starting point of the line"); | |
scanf("%d%d",&xa,&ya); | |
printf("Enter the co-ordinates of the end point of the line"); | |
scanf("%d%d",&xb,&yb); | |
dx=(xb-xa); | |
dy=(yb-ya); | |
p=2*dy-dx; | |
x=xa; | |
y=yb; | |
int i = 0; | |
printf("Enter Type Of line:\n 1.Continuos \n 2.Dotted \n 3.Dashed"); | |
scanf("%d",&choice); | |
switch(choice) { | |
case 1: | |
while (x!=xa && y!=yb) { | |
putpixel(x,y,1); | |
if (p<0) { | |
x++; | |
p += 2*dy; | |
} | |
if (p>=0) { | |
x++; | |
y++; | |
p += (2*dy-2*dx); | |
} | |
i++; | |
} | |
break; | |
case 2: | |
while (x!=xa && y!=yb) { | |
if(i%2==0) putpixel(x,y,1); | |
if (p<0) { | |
x++; | |
p += 2*dy; | |
} | |
if (p>=0) { | |
x++; | |
y++; | |
p += (2*dy-2*dx); | |
} | |
i++; | |
} | |
break; | |
case 3: | |
while (x!=xa && y!=yb) { | |
if(i%5!=0) putpixel(x,y,1); | |
if (p<0) { | |
x++; | |
p += 2*dy; | |
} | |
if (p>=0) { | |
x++; | |
y++; | |
p += (2*dy-2*dx); | |
} | |
i++; | |
} | |
break; | |
} | |
getch(); | |
closegraph(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment