Worksheet - 4
Worksheet - 4
2.Code:
a)
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int x1, x2, x3, y1, y2, y3, d;
int gdriver=DETECT, gmode;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
cout<<"\nPUSHP RAJ";
cout<<"\n19BCS1372";
settextstyle(3,2,3);
setcolor(5);
setbkcolor(9);
outtextxy(450,150,"PUSHP RAJ");
cout<<"Enter Coordinates:\n";
switch(d)
{
case 1: int x, y;
cout<<"Enter translation coordinates: "; cin>>x>>y;
int translation_arr[] = {x1+x, y1+y, x2+x, y2+y, x3+x, y3+y,
x1+x, y1+y};
drawpoly(4, translation_arr);
break;
getch();
closegraph();
}
Output:
a)transition:
b)scalling:
c)Rotation:
a)anti-clockwise:
b)clockwise:
b) CODE:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int x1, x2, x3, y1, y2, y3, p,x, y;
int gdriver=DETECT, gmode;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
cout<<"\nPUSHP RAJ";
cout<<"\n19BCS1372";
settextstyle(3,2,3);
setcolor(5);
setbkcolor(9);
outtextxy(450,250,"PUSHP RAJ");
cout<<"Enter Coordinates:\n";
switch(p)
{
case 1:
rx2 = x2*cos(theta) - y2*sin(theta);
ry2 = x2*cos(theta) + x2*sin(theta);
rx3 = x3*cos(theta) - y3*sin(theta);
ry3 = y3*cos(theta) + x3*sin(theta);
int rotation_arr1[] = {x1, y1, rx2, ry2, rx3, ry3};
drawpoly(4, rotation_arr1);
break;
case 2:
rx1 = x1*cos(theta) - y1*sin(theta);
ry1 = y1*cos(theta) + x1*sin(theta);
rx3 = x3*cos(theta) - y3*sin(theta);
ry3 = y3*cos(theta) + x3*sin(theta);
case 3:
rx1 = x1*cos(theta) - y1*sin(theta);
ry1 = y1*cos(theta) + x1*sin(theta);
rx2 = x2*cos(theta) - y2*sin(theta);
ry2 = x2*cos(theta) + x2*sin(theta);
getch();
closegraph();
}
Output:
a)anti-clockwise rotation:
b)clockwise rotation:
3. Learning outcome: