Drawing from Display File.

Ram Pothuraju
This program is to draw diagram represented by a given Display file. 



#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define XMAX 639
#define XMIN 0
#define YMIN 0
#define YMAX 479

void main()
{
 int gd=DETECT,gm;
 float coord[20][2];
 int op[20];
 int x,y,tempx,tempy,i,j,N;
 initgraph(&gd,&gm,"C:\\TC\\BGI");
 cleardevice();
 printf("Enter the no. of instructions in your prg: ");
 scanf("%d",&N);
 printf("Enter the coordinates ");
 for(i=0;i<N;i++)
 {
   for(j=0;j<2;j++)
   {
   scanf("%f",&coord[i][j]);
   }
 }
 printf("Enter the opcodes: ");
 for(i=0;i<N;i++)
  scanf("%d",&op[i]);

 cleardevice();
 for(i=0;i<N;i++)
 {
  if(op[i]==0)
  {
   tempx=coord[i][0]*XMAX+XMIN;
   tempy=coord[i][1]*YMAX+YMIN;
   moveto(tempx,tempy);
  }
  else if(op[i]==1)
  {
   x=coord[i][0]*XMAX+XMIN;
   y=coord[i][1]*YMAX+YMIN;
   line(tempx,tempy,x,y);
   tempx=x;
   tempy=y;
  }
 }
 getch();
 closegraph();
}


Post a Comment

0Comments

Post a Comment (0)