Program Brown;
{
Por Alexandre Oliveira - alep_rj@bol.com.br
Compilado com o TmtPascal, que pode ser conseguido em www.tmt.com.
Units nescessárias: Crt e Graph, ambas vem com o compilador.
}
Uses Crt,graph;
Const
  NumeroDeParticulas = 1500; {Número de particulas que serão mostradas}

  DeslocamentoMaximo = 4; {Número máximo de pixels que uma particula pode andar
                           por vez}
  Cor = 7;                {Cor das particulas}
Type TPart = record
   x,y,x_,y_: integer;
   end;
Var
  i,i2: integer;
  Particula: Array[1..NumeroDeParticulas+1] of TPart;
  d,m : integer;

Procedure vsinc; assembler;
  asm
    mov dx,3DAh
   @l1:
    in al,dx
    and al,08h
    jnz @l1
   @l2:
    in al,dx
    and al,08h
    jz  @l2
  end;

Function RandomSinal: Integer;
  Begin
    if (Random(100) mod 2) = 0 then RandomSinal := 1 else RandomSinal := -1;
  End;

Procedure Desenhar  (x,y,cor : integer);
  Begin
    PutPixel(x,y,cor);
  End;

Procedure Apagar  ( x,y : integer);
  Begin
    Desenhar(x,y,GetBkColor);
  End;

Procedure Mover{ (var Part:array of TPart)};
  var
    j: integer;
  Begin
    for i:= 1 to NumeroDeParticulas do
      with Particula[i] do
        Desenhar(x,y,cor);
    Delay(10+Random(100));
    {vsinc;}
    for i:= 1 to NumeroDeParticulas do
      with Particula[i] do
        begin
         Apagar(x,y);
            x_:=Random(DeslocamentoMaximo)*RandomSinal;
            y_:=Random(DeslocamentoMaximo)*RandomSinal;
            if (x >= GetMaxX) then x_:=-Random(10)-1;
            if (x <= 0) then x_:=Random(10)+1;
            x:=x+x_;
            if (y >= GetMaxY) then y_:=-Random(10)-1;
            if (y <= 0) then y_:=Random(10)+1;
            y:=y+y_;
         end;
  End;
BEGIN
  SetSVGAMode(640,480,8,LfbOrBanked);
  {SetSVGAMode(1024,768,8,LfbOrBanked);}
  for i:= 1 to NumeroDeParticulas+1 do
    begin
      With Particula[i] do
        Begin
          x := GetMaxX div 2;
          y := GetMaxY div 2;
        End;
    end;
  Readkey;
  Repeat
    Mover;
  Until Keypressed;
  closegraph;
END.

