View Port

#include<stdio.h>
#include <stdlib.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void draw2d(int,int [],int [],int,int);
void main()
{
int gd=DETECT,gm;
int x[20],y[20],tx=0,ty=0,i,fs;
int xv1,xv2,yv1,yv2;
float sx,sy;
initgraph(&gd,&gm,"");
printf("No of sides : ");
scanf("%d",&fs);
printf("Co-ordinates : ");
for(i=0;i<fs;i++)
{
printf("(x%d,y%d)",i,i);
scanf("%d%d",&x[i],&y[i]);
}
printf("Enter view port values : ");
scanf("%d%d%d%d",&xv1,&yv1,&xv2,&yv2);
cleardevice();
rectangle(0,0,639,479);
draw2d(fs,x,y,tx,ty);
sx=(xv2-xv1)/(639.0);
sy=(yv2-yv1)/(479.0);
for(i=0;i<fs;i++)
{
x[i]=xv1+(x[i])*sx;
y[i]=yv1+(y[i])*sy;
}
getch();
cleardevice();
rectangle(xv1,yv1,xv2,yv2);
draw2d(fs,x,y,tx,ty);
getch();
}
void draw2d(int fs,int x[20],int y[20],int tx,int ty)
{
int i;
for(i=0;i<fs;i++)
{
if(i!=(fs-1))
line(x[i]+tx,y[i]+ty,x[i+1]+tx,y[i+1]+ty);
else
line(x[i]+tx,y[i]+ty,x[0]+tx,y[0]+ty);
}
}

Popular posts from this blog

Simple Animation Using C

Personal Diary - A Mini Project Written in Turbo C With Graphical Interface

Random Bouncing Ball Animation