-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathSPIDER.PAS
207 lines (185 loc) · 5.04 KB
/
SPIDER.PAS
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
{$M 65084,0,655360 }
Program Spider;
{$N+}
{ Draws some beeeyoootiful 3-d graphics of a spider on a chessboard }
uses
Dos, Crt, Graph, Printer, Mouse;
const
MaxPoly = 500; { Can go up to 650 }
DiskMaxPoly = 5000;
D : Integer = 1200; { 300 }
AR = 1.3;
TempDrive = 'E';
BackgroundColorDuring2dDrawing = Blue;
ForegroundColorDuring2dDrawing = White;
BackgroundColorDuring3dDrawing = Blue;
ForegroundColorDuring3dDrawing = yellow;
ColorForPolygonsDuringHidden = Green;
type
LineType = Record
X, Y, Z : Real;
end;
FootType = Record
X, Y, Z : Real;
end;
var
Ch : Char;
Z, A, B, Button, TT,X, T : Integer;
dX, dZ, CenterX, CenterZ, R : Real;
GraphDriver, GraphMode, GraphError : Integer;
P : Array[1..4] of PointType;
Sp : Array[1..6] of FootType;
Function Get3dX (X, Z : Real) : LongInt;
begin
Get3dX := (GetMaxX div 2)-Trunc(D*X/Z*AR);
end;
Function Get3dY (Y, Z : Real) : LongInt;
begin
Get3dY := (GetMaxY div 2)+Trunc(D*Y/Z);
end;
procedure Line3d (x1,y1,z1,x2,y2,z2 : Real);
begin
Line (Get3dX(x1,z1),Get3dY(y1,z1),Get3dX(x2,z2),Get3dY(y2,z2));
end;
procedure FindCenter;
var
T : Integer;
begin
CenterX := 0;
CenterZ := 0;
For T := 1 to 6 do
begin
CenterX := CenterX + Sp[T].X;
CenterZ := CenterZ + Sp[T].Z;
end;
CenterX := CenterX / 6;
CenterZ := CenterZ / 6;
end;
procedure DrawBoard;
begin
For X := -6 to 6 do
Line3d (X,-2,-18,X,-2,-90);
For Z := -3 downto -15 do
Line3d (-6,-2,Z*6,6,-2,Z*6);
For X := -6 to 5 do
For Z := -3 downto -14 do
begin
If Odd (X+Z) then
begin
SetFillStyle (SolidFill,LightCyan);
SetColor (LightCyan);
end
else
begin
SetFillStyle (SolidFill,Cyan);
SetColor (Cyan);
end;
P[1].X := Get3dX (X,Z*6);
P[1].Y := Get3dY (-2,Z*6);
P[2].X := Get3dX (X,(Z-1)*6);
P[2].Y := Get3dY (-2,(Z-1)*6);
P[3].X := Get3dX (X+1,(Z-1)*6);
P[3].Y := Get3dY (-2,(Z-1)*6);
P[4].X := Get3dX (X+1,Z*6);
P[4].Y := Get3dY (-2,Z*6);
FillPoly (4,P);
end;
{ else
LineTo (Get3dX(Cos(2*Pi*X/9)*T*0.5,-54+Sin(2*Pi*X/9)*T*3),
Get3dY(-2,-54+Sin(2*Pi*X/9)*T*3));
For X := 1 to 9 do
Line3d (0,-2,-54,Cos(2*Pi*X/9)*0.5*17,-2,-54+Sin(2*Pi*X/9)*3*17);
For T := 1 to 12 do
For X := 1 to 9 do
begin
If ((X < 7) and Odd (X+T)) or ((X >= 7) and Not Odd (X+T)) then
begin
SetFillStyle (SolidFill,LightCyan);
SetColor (LightCyan);
end
else
begin
SetFillStyle (SolidFill,Cyan);
SetColor (Cyan);
end;
P[1].X := Get3dX(Cos(2*Pi*X/9)*T*0.5,-54+Sin(2*Pi*X/9)*T*3);
P[1].Y := Get3dY(-2,-54+Sin(2*Pi*X/9)*T*3);
P[2].X := Get3dX(Cos(2*Pi*(X+1)/9)*T*0.5,-54+Sin(2*Pi*(X+1)/9)*T*3);
P[2].Y := Get3dY(-2,-54+Sin(2*Pi*(X+1)/9)*T*3);
P[3].X := Get3dX(Cos(2*Pi*(X+1)/9)*(T+1)*0.5,-54+Sin(2*Pi*(X+1)/9)*(T+1)*3);
P[3].Y := Get3dY(-2,-54+Sin(2*Pi*(X+1)/9)*(T+1)*3);
P[4].X := Get3dX(Cos(2*Pi*X/9)*(T+1)*0.5,-54+Sin(2*Pi*X/9)*(T+1)*3);
P[4].Y := Get3dY(-2,-54+Sin(2*Pi*X/9)*(T+1)*3);
FillPoly (4,P);
end;}
end;
procedure DrawSpider;
var
MidX, MidZ : Real;
T : Integer;
begin
HideCursor;
SetWriteMode (XOrPut);
{ SetLineStyle (SolidLn,0,ThickWidth);}
For T := 1 to 6 do
begin
MidX := (CenterX + Sp[T].X) * 0.5;
MidZ := (CenterZ + Sp[T].Z) * 0.5;
SetColor (LightCyan);
Line3d (CenterX+1.5,-2,CenterZ,MidX+3,-2,MidZ);
Line3d (MidX+3,-2,MidZ,Sp[T].X+3*(Sp[T].Y+2),-2,Sp[T].Z);
end;
For T := 1 to 6 do
begin
MidX := (CenterX + Sp[T].X) * 0.5;
MidZ := (CenterZ + Sp[T].Z) * 0.5;
SetColor (LightRed);
Line3d (CenterX,-1.5,CenterZ,MidX,-1,MidZ);
Line3d (MidX,-1,MidZ,Sp[T].X,Sp[T].Y,Sp[T].Z);
end;
ShowCursor;
end;
begin
GraphDriver := Detect;
InitGraph (GraphDriver,GraphMode,'\TURBO');
GraphError := GraphResult;
If GraphError <> grOk then
begin
Writeln ('Error : ',GraphErrorMsg (GraphError));
Halt;
end;
For T := 1 to 6 do
begin
Sp[T].X := -8+Cos(T/6*2*Pi+0.2)*0.8;
Sp[T].Y := -2;
Sp[T].Z := -54+Sin(T/6*2*Pi+0.2)*6;
end;
SetBorderLimits (0,0,GetMaxX,GetMaxY);
ShowCursor;
Repeat
GetMouseStatus (A,B,Button);
For T := 1 to 6 do
For X := 0 to 3 do
begin
ClearDevice;
DrawBoard;
FindCenter;
DrawSpider;
{ Delay (500);}
{ DrawSpider; }
If T > 3 then
TT := (T-3)*2
else
TT := T*2-1;
dX := (A - GetMaxX div 2) / (GetMaxX div 2) * 0.4;
dZ := (B - GetMaxY div 2) / (GetMaxY div 2) * 1.2;
Sp[TT].X := Sp[TT].X + dX;
If X < 3 then
Sp[TT].Y := -1.8
else
Sp[TT].Y := -2;
Sp[TT].Z := Sp[TT].Z + dZ;
end;
Until Keypressed or (Button > 0);
While Keypressed do Ch := ReadKey;
end.