Skip to content

Instantly share code, notes, and snippets.

@max-kov
Last active November 21, 2015 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save max-kov/cd5f38dbb40db8c3d47e to your computer and use it in GitHub Desktop.
Save max-kov/cd5f38dbb40db8c3d47e to your computer and use it in GitHub Desktop.
matrix falling code sim
program matrix;
uses
graph,
SysUtils;
const
colnum = 15;
var
GrDriver, GrMode, GrError: smallint;
randomChars: ansistring;
headPlace: array [0..1000] of integer;
counter, counter2, curRand, curCol: integer;
charx, chary, maxx, maxy, charlen, charheight: integer;
begin
randomize();
// graph init
GrDriver := Detect;
InitGraph(GrDriver, GrMode, '');
GrError := GraphResult;
if GrError <> GrOK then
begin
Writeln('Zª_Ù” Òì_ § ÒØ”Р£ì ä_”_.');
Writeln(GraphErrorMsg(GrError));
Halt;
end;
maxx := getmaxx;
maxy := getmaxy;
//text style
SetTextStyle(smallFont, 0, 2);
SetTextJustify(righttext, bottomText);
//pallete
SetRGBPalette(1, 255, 255, 255);
SetRGBPalette(2, 150, 255, 150);
SetRGBPalette(3, 100, 205, 100);
SetRGBPalette(4, 0, 100, 0);
SetRGBPalette(5, 0, 100, 0);
SetRGBPalette(6, 0, 100, 0);
SetRGBPalette(7, 0, 100, 0);
SetRGBPalette(8, 0, 100, 0);
SetRGBPalette(9, 0, 100, 0);
SetRGBPalette(10, 0, 100, 0);
SetRGBPalette(11, 0, 100, 0);
SetRGBPalette(12, 0, 50, 0);
SetRGBPalette(13, 0, 25, 0);
SetRGBPalette(14, 0, 0, 0);
SetRGBPalette(15, 0, 0, 0);
charlen := (TextWidth('A'));
charheight := (TextHeight('A'));
charx := round(maxx / charlen);
chary := round(maxy / charheight);
setlength(randomchars,charx*chary);
randomchars := '';
for counter := 1 to charx * chary do
randomchars := randomchars + chr(random(94) + 32);
for counter := 1 to charx do
headPlace[counter] := 0;
headPlace[0] := 1;
while True do
begin
if random(20) = 1 then
curRand := random(charx) + 1
else
currand := 0;
if headplace[currand] = 0 then
headplace[currand] := 1;
for counter := 1 to charx do
begin
counter2 := headplace[counter];
curCol := 1;
if (random(10) = 1) then
begin
while (counter2 > 0) and (curcol < colnum) do
begin
setcolor(curCol);
if (counter2<=chary) then
outtextxy(counter * charlen, counter2 * charheight,
randomchars[counter * counter2]);
Inc(curcol);
Dec(counter2);
end;
if headplace[counter] > 0 then
Inc(headplace[counter]);
if headplace[counter] - colnum > chary then
headplace[counter] := 0;
end;
end;
end;
writeln(randomchars);
readln;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment