Page 134 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 134
Lab on Computer Graphics
Notes while(1)
{
printf("******2D Transformations*******n");
printf("1.Translationn2.Rotationn3.Scalingn4.Reflectionn5.Shearingn6.
ExitnEnter your choice:n");
scanf("%d",&ch);
switch(ch)
{
case 1:
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:tcBGI");
rectangle(x,y,az,w);
printf("*******Translation*******nn");
printf("Enter the value of shift vector:n");
scanf("%f%f",&dx,&dy);
x1=x+dx;
y1=y+dy;
az1=az+dx;
w1=w+dy;
rectangle(x1,y1,az1,w1);
break;
case 2:
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:tcBGI");
rectangle(x,y,az,w);
printf("*******Rotation*******nn");
printf("Enter the value of fixed point and angle of rotation:Enter the
value of fixed point and angle of rotation:n");
scanf("%d%d%d",&xa,&ya,&ra);
theta=(float)(ra*(3.14/180));
for(i=0;i<4;i++)
{
a1[i]=(xa+((a[i]–xa)*cos(theta)–(b[i]–ya)*sin(theta)));
b1[i]=(ya+((a[i]–xa)*sin(theta)+(b[i]–ya)*cos(theta)));
}
for(i=0;i<4;i++)
{
if(i!=3)
line(a1[i],b1[i],a1[i+1],b1[i+1]);
else
line(a1[i],b1[i],a1[0],b1[0]);
}
128 LOVELY PROFESSIONAL UNIVERSITY