You are on page 1of 6

// Program for scan line //

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int p[10][3],p1[10][3],s[3][3];
int i,n,j,k,sx,sy;
clrscr();
printf("\n enter no of edges");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter vertex %d",i);
scanf("%d%d",&p[i][0],&p[i][1]);
p[i][2]=1;
}
printf("enter values of sx and sy");
scanf("%d%d",&sx,&sy);

s[0][0]=sx; //formation of matrix


s[0][1]=0;
s[0][2]=0;
s[1][0]=0;
s[1][1]=sy;
s[1][2]=0;
s[2][0]=0;
s[2][1]=0;
s[2][2]=1;

initgraph(&gd,&gm,"c:\\tc\\bgi");

printf("matrix before scaling");


moveto(p[0][0],p[0][1]);
for(i=1;i<n;i++)
{
lineto(p[i][0],p[i][1]);
}
line(p[n-1][0],p[n-1][1],p[0][0],p[0][1]);
getch();

//multiplication of matrix

for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
p1[i][j]=0;
for(k=0;k<3;k++)
{
p1[i][j]=p1[i][j]+p[i][k]*s[k][j];
}
}
}

printf("matrix after scaling");


moveto(p1[0][0],p1[0][1]);
for(i=1;i<n;i++)
{
lineto(p1[i][0],p1[i][1]);
}
line(p1[n-1][0],p1[n-1][1],p1[0][0],p1[0][1]);
getch();
closegraph();
}
/* COMPUTER GRAPHICS-CGA-12112
PROGRAM TO REFLECTION*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT, gm;
float s[3][3], p1[10][3];
int p[10][3];
int i,j,k,n;
float sx,sy;
clrscr();
printf("\n Enter the edges of the polygon");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the vertex %d",i);
scanf("%d%d",&p[i][0],&p[i][1]);
p[i][2]=1;
}

// printf("\n Enter the scaling factor sx and sy");


// scanf("%f%f", &sx,&sy);
// formation of matrix
s[0][0]=0;
s[0][1]=1;
s[0][2]=0;
s[1][0]=1;
s[1][1]=0;
s[1][2]=0;
s[2][0]=0;
s[2][1]=0;
s[2][2]=1;
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
p1[i][j]=0;
for(k=0;k<3;k++)
{
p1[i][j]=p1[i][j]+p[i][k]*s[k][j];
}
}
}
initgraph(&gd,&gm, "c:\\tc\\bgi");
printf("\n Before scalling: ");
moveto(p[0][0],p[0][1]);
for(i=0;i<n;i++)
{
lineto(p[i][0],p[i][1]);
}
line(p[n-1][0],p[n-1][1],p[0][0],p[0][1]);
getch();
printf("\n After scalling: ");
moveto(p1[0][0],p1[0][1]);
for(i=0;i<n;i++)
{
lineto(p1[i][0],p1[i][1]);
}
line(p1[n-1][0],p1[n-1][1],p1[0][0],p1[0][1]);
getch();
closegraph();
}
PROGRAM FOR ROTATION ABOUT AN ORBETRAY POINT*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
float R[3][3],p1[10][3];
float theta,thetac;
int p[10][3];
int xp,yp;
int i,j,k,n;
int gm,gd=DETECT;
clrscr();

//SCANING THE NO OF EDGES-------------------------------------------

printf("\n\tHOW MANY EDGES U WANT ?");


scanf("%d",&n);

//SCANING VERTICES---------------------------------------------------

printf("\n\tENTER THE VIRTICES:\n");


for(i=0;i<n;i++)
{
printf("\n\t\t\tENTER VIRTICES NUMBER %d",i);
scanf("%d%d",&p[i][0],&p[i][1]);
p[i][2]=1;
}
//SCANING THE ANGLE THETA FOR ROTATION----------

printf("\n\tENTER THE ANGLE FOR AT WHICH U WANT 2 ROTATE: ");


scanf("%f",&theta);
thetac=theta*M_PI/180;
printf("\n\t\tABOUT WHICH POINT U WANT 2 ROTATE");
scanf("%d%d",&xp,&yp);

//FORMATION OF MATRIX------------------------

R[0][0]=cos(thetac);
R[0][1]=sin(thetac);
R[0][2]=0;
R[1][0]=-sin(thetac);
R[1][1]=cos(thetac);
R[1][2]=0;
R[2][0]=xp*cos(thetac)+xp*sin(thetac)+xp;
R[2][1]=yp+sin(thetac)-yp+cos(thetac)+yp;
R[2][2]=1;

//MULTIPLICATION OF MATRIX--------------------

for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
p1[i][j]=0;
for(k=0;k<3;k++)
{
p1[i][j]=p1[i][j]+p[i][k]*R[k][j];
}
}
}

//DISPLAY THE OBJECT B4 AND AFTER------------------

initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\n\t\t\tOBJECT B4 ROTATION:");
moveto(p[0][0],p[0][1]);
for(i=0;i<n;i++)
{
lineto(p[i][0],p[i][1]);
}
line(p[n-1][0],p[n-1][1],p[0][0],p[0][1]);

getch();

//DISPLAY THE OBJECT AFTER ROTATION----------------------


clrscr();
printf("\n\t\t\tOBJECT AFTER ROTATION:");
moveto(p1[0][0],p1[0][1]);
for(i=0;i<n;i++)
{
lineto(p1[i][0],p1[i][1]);
}
line(p1[n-1][0],p1[n-1][1],p1[0][0],p1[0][1]);

getch();
closegraph();
//------------------------------------END-------------------
}
PROGRAM FOR BEZIER CURVE GENERATION*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

void bez(int xA,int yA,int xB,int yB,int xC,int yC,int xD,int yD,int n)
{
float xAB,yAB,xBC,yBC,xCD,yCD,xABC,yABC,xBCD,yBCD,xABCD,yABCD;
if(n==0)
{
line(xA,yA,xB,yB);
line(xB,yB,xC,yC);
line(xC,yC,xD,yD);
}
else
{
xAB=(xA+xB)/2.0;
yAB=(yA+yB)/2.0;
xBC=(xB+xC)/2.0;
yBC=(yB+yC)/2.0;
xCD=(xC+xD)/2.0;
yCD=(yC+yD)/2.0;
xABC=(xAB+xBC)/2.0;
yABC=(yAB+yBC)/2.0;
xBCD=(xBC+xCD)/2.0;
yBCD=(yBC+yCD)/2.0;
xABCD=(xABC+xBCD)/2.0;
yABCD=(yABC+yBCD)/2.0;
bez(xA,yA,xAB,yAB,xABC,yABC,xABCD,yABCD,n-1);
bez(xABCD,yABCD,xBCD,yBCD,xCD,yCD,xD,yD,n-1);
}
}
void main()
{
int gd=DETECT,gm;
int xA,yA,xB,yB,xC,yC,xD,yD;
printf("\n Entet the contrl point");
scanf("%d%d%d%d%d%d%d%d",&xA,&yA,&xB,&yB,&xC,&yC,&xD,&yD);
initgraph(&gd,&gm,"c:\\tc\\bgi");
bez(xA,yA,xB,yB,xC,yC,xD,yD,50);
delay(10);
getch();
closegraph();
}

You might also like