Program Tunel;

{Tunel v1.0 by Crush,D UNT}

uses crt,crush13h;

Const ncolors=3;

Type RgbItem=Record
                   R,G,B:Byte;
             End;

     RgbList=Array[0..255] of RgbItem;

var  a:integer;
     color: array [1..ncolors] of integer;
     temp:rgblist;

procedure swapcolors (a,b:integer; where:word);
var x,y,c:integer;
begin
     for x:=0 to 319 do
         begin
         for y:=0 to 199 do
             begin
                  c:= getpixel (x,y,where);
                  if c=a
                  then putpixel (x,y,b,where)
                  else if c=b then putpixel (x,y,a,where);
             end;
         end;
end;

procedure fadeto (x,y,z:byte;h:integer);
var r,g,b:byte;
begin
     delay (h);
     for a:=0 to 255 do
     begin
          getcolor (a,r,g,b);
          if r>x then r:=r-1;
          if r<x then r:=r+1;
          if g>y then g:=g-1;
          if g<y then g:=g+1;
          if b>z then b:=b-1;
          if b<z then b:=b+1;
          setcolor (a,r,g,b);
          end;
end;

procedure fadefrom (temp:rgblist;h:integer);
var r,g,b:byte;
begin
     delay (h);
     for a:=0 to 255 do
     begin
          getcolor (a,r,g,b);
          if r>temp[a].r then r:=r-1;
          if r<temp[a].r then r:=r+1;
          if g>temp[a].g then g:=g-1;
          if g<temp[a].g then g:=g+1;
          if b>temp[a].b then b:=b-1;
          if b<temp[a].b then b:=b+1;
          setcolor (a,r,g,b);
     end;
end;

procedure palrotation;
var r,g,b,d,e,f:byte;
begin
     getcolor ( color[ncolors],d,e,f );
     for a:=ncolors-1 downto 1 do
         begin
              getcolor (color[a],r,g,b);
              setcolor (color[a+1],r,g,b);
         end;
     setcolor (color[1],d,e,f);
end;

procedure savepal;
begin
     for a:=0 to 255 do getcolor (a,temp[a].r,temp[a].g,temp[a].b);
end;

procedure restorepal;
begin
     for a:=0 to 255 do setcolor (a,temp[a].r,temp[a].g,temp[a].b);
end;



begin

     video_mode ( $13);
     initvirt;


     loadpcx ('tunel3.pcx',vp[1]);
     swapcolors (0,1,vp[1]);
     color[1]:=1;
     color[2]:=6;
     color[3]:=13;

     copypage (vp[1],vga,0);

     repeat

         palrotation;

     until keypressed;
     readkey;

     closevirt;
     video_mode ( 03);

end.