This repository was archived by the owner on Mar 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmainfrm.pas
236 lines (208 loc) · 5.2 KB
/
mainfrm.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
{
SSG's Matrix ScreenSaver
mainfrm.pas
Coded by SSG obviously
}
unit mainfrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
const
appVer = '1.01';
fontName = 'Matrix Code Font';
fontHeight = 12;
maxStreams = 5000;
maxSpeed = 4;
minSpeed = 1;
baseDelay = 50;
matrixAlphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd';
matrixAlphabetLength = length(matrixAlphabet);
maxR = 150;
maxB = 100;
type
PMatrixStream = ^TMatrixStream;
TMatrixStream = record
x,y:integer;
speed:integer;
brightness:integer;
lastchar:char;
lastcharindex:byte;
end;
TMainForm = class(TForm)
tmTimer: TTimer;
procedure FormCreate(Sender: TObject);
procedure tmTimerTimer(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
outCanvas:TCanvas;
matrixWidth,matrixHeight,charWidth,charHeight:integer;
bitmapWidth,bitmapHeight:integer;
procedure Init;
procedure Iterate;
procedure AdjustBitmap;
procedure InitStreams;
procedure AddStream;
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
var
streams : array[0..maxStreams-1] of TMatrixStream;
streamCount : integer;
tick : integer;
procedure TMainForm.Init;
var
n:integer;
R:TRect;
begin
tick := 0;
Randomize;
outCanvas := Self.Canvas;
FillChar(R,SizeOf(R),0);
with Screen do begin
for n:=0 to MonitorCount-1 do begin
with Monitors[n] do begin
if BoundsRect.Left < R.Left then R.Left := BoundsRect.Left;
if BoundsRect.Top < R.Top then R.Top := BoundsRect.Top;
if BoundsRect.Right > R.Right then R.Right := BoundsRect.Right;
if BoundsRect.Bottom > R.Bottom then R.Bottom := BoundsRect.Bottom;
end;
end;
end;
Self.BoundsRect := R;
bitmapWidth := Width;
bitmapHeight := Height;
AdjustBitmap;
tmTimer.Interval := baseDelay;
tmTimer.Enabled := true;
Screen.Cursor := crNone;
end;
procedure TMainForm.AddStream;
begin
if streamCount>=maxStreams then exit;
with streams[streamCount] do begin
x := streamCount mod matrixWidth;
y := random(matrixHeight);
speed := Random(maxSpeed-minSpeed)+minSpeed;
brightness := Random(100);
lastcharindex := Random(matrixAlphabetLength)+1;
end;
inc(streamCount);
end;
procedure TMainForm.InitStreams;
var
n:integer;
begin
streamCount := 0;
for n:=1 to matrixWidth*2 do addStream;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Init;
end;
procedure TMainForm.Iterate;
var
n,c1,c2:integer;
stream:PMatrixStream;
procedure PutChar(c:char);
begin
with outCanvas,stream^ do begin
c1 := x*charWidth;
c2 := y-40;
while c2 < 0 do c2 := (matrixHeight+1)+c2;
c2 := c2*charHeight;
FillRect(Rect(c1,c2,c1+charWidth,c2+charHeight));
c1 := (255*brightness) div 100;
c2 := c1 div 3;
c1 := (c1*maxR div 255) or (c1 shl 8) or ((c1*maxB div 255) shl 16);
c2 := (c2*maxR div 255) or (c2 shl 8) or ((c2*maxB div 255) shl 16);
if(y > 0) then begin
Font.Color := c2;
TextOut(x*charWidth,(y-1)*charHeight,lastchar);
end;
Font.Color := c1;
TextOut(x*charWidth,y*charHeight,c);
lastchar := c;
end;
end;
begin
for n:=0 to streamCount-1 do begin
stream := @streams[n];
with stream^ do begin
if tick mod speed = 0 then begin
PutChar(matrixAlphabet[Random(matrixAlphabetLength)]);
inc(y);
if(y > matrixHeight+1) then begin
y := 0;
speed := Random(maxSpeed-minSpeed)+minSpeed;
brightness := Random(100);
end;
end else begin
PutChar(matrixAlphabet[Random(matrixAlphabetLength)]);
end;
end;
end;
inc(tick);
end;
procedure TMainForm.tmTimerTimer(Sender: TObject);
begin
Iterate;
end;
procedure TMainForm.FormPaint(Sender: TObject);
begin
outCanvas.FillRect(BoundsRect);
end;
procedure TMainForm.AdjustBitmap;
begin
with outCanvas do begin
TextFlags := 0;
Brush.Color := clBlack;
FillRect(Rect(0,0,Width,Height));
Font.Name := fontName;
Font.Height := fontHeight;
charWidth := fontHeight-4;
charHeight := fontHeight;
matrixWidth := bitmapWidth div charWidth;
matrixHeight := bitmapHeight div charHeight;
end;
InitStreams;
end;
procedure TMainForm.FormResize(Sender: TObject);
begin
AdjustBitmap;
end;
var
lastx:integer = 0;
lasty:integer = 0;
procedure TMainForm.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (lastx=0) and (lasty=0) then begin
lastx := x;
lasty := y;
end else begin
if (abs(x-lastx) > 10) or (abs(y-lasty) > 10) then begin
Close;
end;
end;
end;
procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Close;
end;
procedure TMainForm.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Close;
end;
end.