C PROGRAMS TO PLOT DIFFERENT TYPES OF LINES

C programs for plotting different kinds of lines

//program for line attributes(line style)

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int xa,xb,ya,yb,x1,x2,y1,y2;
void pol(int xa,int ya,int xb,int yb)
{
printf("Enter starting point (x1,y1)");
scanf("%d%d",&xa,&ya);
printf("Enter Endpoints(x2,y2)");
scanf("%d%d",&xb,&yb);
x1=xa;x2=xb;y1=ya;y2=yb;
}
void main()
{
int gd = DETECT, gm,i;
initgraph(&gd,&gm, "c:\tc\bgi");
setbkcolor(BLUE);
do
{
clrscr();
printf("pressn");
printf("1 for SOLID_LINEn2 for DOTTED_LINEn3 for CENTER_LINEn");
printf("4 for DASHED_LINEn 5 for USERBIT_LINEn");
scanf("%d",&i);
switch(i)
{
case 1:
pol(xa,ya,xb,yb);
setlinestyle(SOLID_LINE,1,1);
setcolor(RED);
line(x1,y1,x2,y2);
getch();
cleardevice();
break;

case 2:
pol(xa,ya,xb,yb);
setlinestyle(DOTTED_LINE,1,1);
setcolor(RED);
line(x1,y1,x2,y2);
getch();
cleardevice();
break;
 
    case 3:
pol(xa,ya,xb,yb);
setlinestyle(CENTER_LINE,1,1);
setcolor(RED);
line(x1,y1,x2,y2);
getch();
cleardevice();
break;
 
    case 4:
pol(xa,ya,xb,yb);
setlinestyle(DASHED_LINE,1,1);
setcolor(RED);
line(x1,y1,x2,y2);
getch();
cleardevice();
break;

case 5:
pol(xa,ya,xb,yb);
setlinestyle(USERBIT_LINE,1,1);
setcolor(RED);
line(x1,y1,x2,y2);
getch();
cleardevice();
break;
 
    default:exit(0);
}
}while(i!=0);
getch();
closegraph();
}

Leave a Reply

Your email address will not be published. Required fields are marked *