-
Notifications
You must be signed in to change notification settings - Fork 54
/
FIREWORK.PAS
105 lines (92 loc) · 1.99 KB
/
FIREWORK.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
program FireWorks;
{$R+}
uses
Crt, Graph;
var
GraphDriver, GraphMode, ErrorCode : Integer;
Ch : Char;
I, J, K, XStart, YStart : Integer;
XX,YY,CC : Array[1..1000] of Integer;
FX,FY,DX,DY : Array[1..70] of Real;
R, T, X, Y : Real;
procedure Explode (C : Integer);
begin
T := -Pi;
I := 0;
Repeat
I := I + 1;
DX[I] := Sin(T)*5;
DY[I] := Cos(T)*5;
FX[I] := X;
FY[I] := Y;
T := T + 0.15;
Until T > Pi;
K := 0;
Repeat
For J := 1 to I do
begin
If C = 0 then
PutPixel (Round(FX[J]),Round(FY[J]),0)
else
PutPixel (Round(FX[J]),Round(FY[J]),Random(GetMaxColor+1));
FX[J] := FX[J] + DX[J];
FY[J] := FY[J] - DY[J];
DY[J] := DY[J] - 0.2;
end;
K := K + 1;
Delay(10); { This was not in the original. }
Until Keypressed or (K > 50);
end;
procedure ShootFireWork;
begin
{ Delay (1000); }
Randomize;
T := Random / 2 - 0.25 + Pi/2;
X := XStart;
Y := YStart;
R := 20;
I := 0;
Repeat
Inc (I);
XX[I] := Round(X);
YY[I] := Round(Y);
CC[I] := GetPixel (XX[I],YY[I]);
If I > 1 then
If (XX[I] = XX[I-1]) and (YY[I] = YY[I-1]) then CC[I] := CC[I-1];
PutPixel (XX[I],YY[I],Random(GetMaxColor+1));
If I > 5 then
PutPixel (XX[I-5],YY[I-5],CC[I-5]);
X := X + Cos(T)*R;
Y := Y - Sin(T)*R;
If T > Pi/2 then
T := T + 0.02
else
T := T - 0.02;
R := R * 0.93;
Delay (20);
Until KeyPressed or (T < 0) or (T > Pi);
For J := I-5 to I do
PutPixel (XX[J],YY[J],CC[J]);
{ ch := readkey; }
Explode (1);
Explode (0);
end;
begin
GraphDriver := Detect;
InitGraph (GraphDriver, GraphMode, '..');
ErrorCode := GraphResult;
If ErrorCode <> grOk then
begin
Writeln ('Graphics Error: ',GraphErrorMsg(ErrorCode));
Halt;
end;
SetColor (GetMaxColor);
XStart := GetMaxX div 2;
YStart := GetMaxY - 20;
Repeat
ShootFireWork;
Until Keypressed;
Ch := ReadKey;
ClearDevice;
CloseGraph;
end.