Drawing from Display File.


This program is to draw diagram represented by a given Display file. This is a part of Mumbai University MCA Colleges CG Programs MCA Computer Graphics
#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();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.