Skip to content

Instantly share code, notes, and snippets.

@theabbie
Created August 6, 2020 08:03
Show Gist options
  • Save theabbie/37369cd296c6432ac6b2f65f92a252c9 to your computer and use it in GitHub Desktop.
Save theabbie/37369cd296c6432ac6b2f65f92a252c9 to your computer and use it in GitHub Desktop.
#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