(*
Project: The Matrix Effect
Ported to Delphi by: Sn!per X ^ AT4RE
Original C++ Source: http://xoax.net/cpp/crs/misc/lessons/TheMatrixEffect/
Release Date: 27-11-2015
*)
Program TheMatrixEffect;
{$APPTYPE CONSOLE}
uses Windows;
Function Modulus(iiN, iMod: Integer): Integer;
var iQ : Integer;
Begin
iQ := (iiN div iMod);
Result := iiN - (iQ*iMod);
end;
Function GetChar(iGenerator: Integer; cBase: Char; iRange: Integer): Char;
Begin
Result := Char(Integer(cBase) +(Modulus(iGenerator, iRange)));
end;
var
hConsole: THANDLE;
caRow: array [0..80] of char;
j, k, l, m, i: Integer;
Begin
// Color code
hConsole := GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, 2);
j := 7;
k := 2;
l := 5;
m := 1;
while (true) do
begin
// Output a random row of characters
for i := 0 to 80-1 Do
begin
if (caRow[i] <> ' ') then
begin
caRow[i] := GetChar(j + i*i, Char(33), 30);
if (i*i + k) mod 71 = 0 then
SetConsoleTextAttribute(hConsole, 7)
else
SetConsoleTextAttribute(hConsole, 2);
end;
// std::cout shr caRow[i];
Write(caRow[i]);
SetConsoleTextAttribute(hConsole, 2);
end;
j := (j + 31);
k := (k + 17);
l := (l + 47);
m := (m + 67);
caRow[Modulus(j, 80)] := '-';
caRow[Modulus(k, 80)] := ' ';
caRow[Modulus(l, 80)] := '-';
caRow[Modulus(m, 80)] := ' ';
// Delay
Sleep(10);
end; //end while
// return 0;
End.