Saturday, 15 October 2011

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("press\n");
    printf("1 for SOLID_LINE\n2 for DOTTED_LINE\n3 for CENTER_LINE\n");
    printf("4 for DASHED_LINE\n 5 for USERBIT_LINE\n");
    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();
 }

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel