1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
| #include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
int x0=340,y0=220,x,y,xt,yt,xxt,yyt,xx,yy,k;
float fi=0,s;
int pyr[8][3],
v[8][3]={{240,320,1},{240,160,1},{400,160,1},{400,320,1},{280,280,1},{280,120,1},{440,120,1},{440,280,1}};
float tmp[8][3];
float r[8][3],tt[8][3];
int t[8][3];
int rect[8];
void recta(int i,int j,int k,int l)
{rect[0]=pyr[i][0];
rect[1]=pyr[i][1];
rect[2]=pyr[j][0];
rect[3]=pyr[j][1];
rect[4]=pyr[k][0];
rect[5]=pyr[k][1];
rect[6]=pyr[l][0];
rect[7]=pyr[l][1];
}
void draw(void)
{moveto(pyr[0][0],pyr[0][1]);
lineto(pyr[1][0],pyr[1][1]);
lineto(pyr[2][0],pyr[2][1]);
lineto(pyr[3][0],pyr[3][1]);
lineto(pyr[0][0],pyr[0][1]);
lineto(pyr[4][0],pyr[4][1]);
lineto(pyr[5][0],pyr[5][1]);
lineto(pyr[6][0],pyr[6][1]);
lineto(pyr[7][0],pyr[7][1]);
lineto(pyr[4][0],pyr[4][1]);
moveto(pyr[1][0],pyr[1][1]);
lineto(pyr[5][0],pyr[5][1]);
moveto(pyr[2][0],pyr[2][1]);
lineto(pyr[6][0],pyr[6][1]);
moveto(pyr[3][0],pyr[3][1]);
lineto(pyr[7][0],pyr[7][1]);
//raskraska
setfillstyle(2,11);
recta(0,1,2,3);
fillpoly(4,rect);
setfillstyle(5,11);
recta(1,5,6,2);
fillpoly(4,rect);
setfillstyle(4,11);
recta(2,6,7,3);
fillpoly(4,rect);
}
void matrix_r(float fi)
{r[0][0]=cos(fi);
r[0][1]=sin(fi);
r[0][2]=0;
r[1][0]=-sin(fi);
r[1][1]=cos(fi);
r[1][2]=0;
r[2][0]=0;
r[2][1]=0;
r[2][2]=1;
}
void matrix_t(int x,int y)
{int i,j;
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
if (i==j) t[i][j]=1;
else t[i][j]=0;
t[2][0]=x;
t[2][1]=y;
}
void main(void)
{int gdriver = DETECT, gmode, errorcode,i,j,c;
char msg[80];
initgraph(&gdriver,&gmode,"");
errorcode=graphresult();
if (errorcode !=grOk)
{printf("Graphics error:%s\n",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();exit(1);
}
settextstyle(0,HORIZ_DIR,2);
setcolor(4);
outtextxy(10,445,"\x01a \x01b esc ");
setcolor(11);
settextstyle(1,HORIZ_DIR,4);
outtextxy(10,430,"-right -left -end");
setviewport(50,50,getmaxx()-50,getmaxx()-50,1);
for(i=0;i<=7;i++)
for(k=0;k<=2;k++)
pyr[i][k]=v[i][k];
draw();
do
{c=getch();
switch(c)
{case 77: fi-=0.15;
break;
case 75: fi+=0.15;
break;
}
matrix_r(fi);
matrix_t(-x0,-y0);
for(i=0;i<=2;i++)
for(k=0;k<=2;k++)
{s=0;
for(j=0;j<=2;j++)
s=s+t[i][j]*r[k][j];
tt[i][k]=s;}
for(i=0;i<=7;i++)
for(k=0;k<=2;k++)
{s=0;
for(j=0;j<=2;j++)
s=s+v[i][j]*tt[j][k];
tmp[i][k]=s;}
matrix_t(x0,y0);
for(i=0;i<=7;i++)
for(k=0;k<=2;k++)
{s=0;
for(j=0;j<=2;j++)
s=s+tmp[i][j]*t[j][k];
pyr[i][k]=s;}
clearviewport();
//stiranie okna
draw();
}while(c!=27);
closegraph();
} |