{*
 Ukazkovy program pro efekt plasma
 Reseno tabulkou sinu
 Pro int21h napsal BOby (<)2006
*}
program plasma;

uses crt;

const WIDTH=320;
      HEIGHT=200;

var xhodnota,yhodnota,t,x,y:word;{Pomocne a citace}
    sins:array[0..512] of word;{Tabulka sinu}
    definice:array[0..WIDTH-1] of word;

{* Procedury pro praci s modem $13 *}
{*    Muzete nahradit vlastnimi    *}
procedure InitGraph;assembler;
asm
 mov ax,0013h {00=funkce na zmenu modu;13h=320x200x256}
 int 10h
end;
procedure CloseGraph;assembler;
asm
 mov ax,0003h {03h=80x25x16}
 int 10h
end;
procedure setcolor(i,r,g,b:byte);
begin
 {Nastaveni barvy pres port.
  Je to rychlejsi nez pres preruseni}
 port[$3c8]:=i;
 port[$3c9]:=r;
 port[$3c9]:=g;
 port[$3c9]:=b;
end;
procedure putpixel(x,y:word;c:byte);
begin
 {Zapis barvu do obrazove pameti. Proste putpixel}
 mem[$a000:x+y*320]:=c; { $a000=Video pamet pro mod $13}
end;

function radian(uhel:real):real;
begin {Prevede stupne na radiany}
 radian:=uhel*pi/180;
end;

Begin
 InitGraph;

 for t:=0 to 255 do{Nejaka provizorni paleta}
  SetColor(t,t*8,t*2,t);
 t:=0;

 for x:=0 to 512 do {Naplneni pole sinusu}
  {Tady muzete expreimentovat   --v}
  sins[x]:=round(sin(radian(x)/512*360)*256);

 repeat

  t:=t+1; {Pohyb casu}
  for x:=0 to WIDTH-1 Do
   definice[x]:=10*sins[(x*4+t) and 511]+20*sins[(x+t*4) and 511]+30*sins[(x*4+t div 4) and 511];
  for y:=1 to HEIGHT do
   begin
    yhodnota:=30*sins[(y*8+t) and 511]+20*sins[(y+t*8) and 511]+10*sins[(y+t div 8) and 511];
    for x:=0 to WIDTH-1 do
     begin
      xhodnota:=definice[x];
      mem[$a000:y*320+x]:=(xhodnota+yhodnota) div 512;{Je to o dost rychlejsi}
      {putpixel(x,y,(Xanswer+yanswer) div 512);}
     end;
   end;

 until keypressed;
 readkey;
 CloseGraph;
End.
