program skysun2;

uses crush13h,crt;

Const
        ZInc = 25;
        ZOfs = 256;
        ZScale = 256;
        Sc = 0.7;


type verts= record
                   x,y,z:real;
                   color:integer;
            end;
     iverts= record
                   x,y,z:real;
                   image:pointer;
            end;
     lines= record
                   v1,v2:word;
                   color:integer;
            end;

Var     Vert : Array[0..100] Of verts;
        iVert : Array[0..100] Of iverts;
        VLine : Array[0..100] Of lines;
        Vertn,iVertn,linen,n:word;
        Ch : Char;
        a:integer;
        ang: real;
        mflare,rflare,bflare,sflare,lsflare:pointer;

Procedure PutImage_bob(X,Y,C:Integer;Var Img:Pointer;Where:Word);
const minx=0;
      maxx=319;
      miny=0;
      maxy=199;
Var Dx,Dy:Word;
    A,B:integer;
    Segm,Offs:Word;
    c1,c2,c3:integer;
Begin
     Segm:=Seg(Img^);
     Offs:=Ofs(Img^);
     Move(Mem[Segm:Offs],Dx,2);
     Move(Mem[Segm:Offs+2],Dy,2);
     Offs:=Offs+4;
     for a:=y to y+dy-1 do
     Begin
          for b:=x to x+dx-1 do
          Begin

               if Mem[Segm:Offs]<>c then
               if b>minx then if b<maxx then if a>miny then if a<maxy then
                  begin
                       c1:=getpixel(B,A,where);
                       c2:=mem[segm:offs];
                       c3:=c2+c1;

                       if c3>255 then c3:=255;
                       if c3<0 then c3:=0;
                       PutPixel(B,A,c3,Where);
                  end;
               Inc(Offs);
          End;
     End;
End;


Procedure Drawimages (where:word);
Var SX, SY, n : Word;
Begin
     n := 0;
     Repeat
           With iVert[n] Do
                 Begin
                         SX := Round((ZScale*X)/(Z-ZOfs));
                         SY := Round((ZScale*Y)/(Z-ZOfs));
                           putimage_bob (160+SX-37, 100+SY-32, 1,image, where);


                 End;
           n := n + 1;
     Until n = iVertn;
End;

Procedure Rotate(Var X, Y, ang : Real);
Var XX, YY : Real;
Begin
           XX := X*Cos(ang)+Y*Sin(ang);
      YY := Y*Cos(ang)-X*Sin(ang);
      X := XX;
      Y := YY;
End;

Begin
     video_mode( $13);
     initvirt;
     loadpcx ('c:\ps\neopaint\pcx\sflare.pcx',vp[2]);
     getimage (3,18,80,81,mflare,vp[2]);
     getimage (14,111,92,174,rflare,vp[2]);
     getimage (130,17,208,80,bflare,vp[2]);
     getimage (222,16,300,79,sflare,vp[2]);
     getimage (112,113,190,176,lsflare,vp[2]);
      With iVert[0] Do
           Begin
              X := -40;
              Y := -40;
              Z := -40;
                   X := X * Sc;
                   Y := Y * Sc;
                   Z := Z * Sc;
                   image:=mflare;
           end;
      With iVert[1] Do
           begin
              X := 70;
              Y := 70;
              Z := 70;
                   X := X * Sc;
                   Y := Y * Sc;
                   Z := Z * Sc;
                   image:=rflare;
           end;
      With iVert[2] Do
           begin
              X := 120;
              Y := 120;
              Z := 120;
                   X := X * Sc;
                   Y := Y * Sc;
                   Z := Z * Sc;
                   image:=bflare;
           end;
      With iVert[3] Do
           begin
              X := 160;
              Y := 160;
              Z := 160;
                   X := X * Sc;
                   Y := Y * Sc;
                   Z := Z * Sc;
                   image:=sflare;
           End;
      With iVert[4] Do
           begin
              X := 10;
              Y := 10;
              Z := 10;
                   X := X * Sc;
                   Y := Y * Sc;
                   Z := Z * Sc;
                   image:=lsflare;
           End;
   ivertn:=5;

   ang:= Pi/72;


   Repeat
              cls (1,vp[1]);
              drawimages(vp[1]);


              waitvbl;

              move (mem[vp[1]:0],mem[vga:0],64000);

              for a:=0 to ivertn do
              begin
                   With iVert[a] Do Rotate(X, Z, ang);
              end;

   Until KeyPressed;

   Repeat Ch := ReadKey Until Not KeyPressed;
   n := 150;
   Repeat
      cls (1,vp[1]);
      drawimages(vp[1]);
      move (mem[vp[1]:0],mem[vga:0],64000);

      for a:=0 to ivertn do
              begin
                   With iVert[a] Do
                        begin
                             X := X * 0.95;
                             Y := Y * 0.95;
                        end;
                   With iVert[a] Do Rotate(Y, X, ang);
                   With iVert[a] Do Rotate(Z, X, ang);
              end;

      n := n - 1;
   Until (n = 0) Or KeyPressed;
   If KeyPressed Then Repeat Ch := ReadKey Until Not KeyPressed;

   Video_Mode( 03);
End.

begin
end.