uses crt,ModeXLib,Tools;
var i,j:word;
    destpal:Array[0..767] of Byte;

Procedure Fade_in(DPal:Array of Byte);
Begin
  For j:=0 to 63 do Begin       {64 passes, in order to fade completely}
    For i:=0 to 767 do          {calculate 768 color values}
      If Palette[i] < DPal[i]   {current value still smaller that destination value ?}
        Then Inc(Palette[i]);   {then increase}
    WaitRetrace;                {synchronization}
    SetPal;                     {set calculated palette}
  End;
End;

begin
  ClrScr;                       {clear screen}
  GetPal;                       {load "Palette" with current DAC-palette}
  Move(Palette,Destpal,768);    {save palette}
  FillChar(Palette,768,0);      {delete old palette}
  SetPal;                       {and set}

  Draw_Ansi('color.ans');       {load wallpaper}

  ReadLn;
  fade_in(Destpal);             {fade to destination pal (original palette)}
  ReadLn;
  TextMode(3);                  {establish normal state}
End.
