NBPrg40. (*graph.md). P_CREATE.PAS. MiniOS. OpenSource.

NBPrg40. (*graph.md). P_CREATE.PAS. MiniOS. OpenSource.
**************************************

{ Beloshenko Nikita (GNU) 2013 }

(*
        P_CREATE.PAS
*)

Program P_Create;

Uses Graph;

Const

   PathToData_File:String ='P_Create.dat';


Var P_File_Name : String;
         P_StX  : Integer;
         P_StY  : Integer;


Procedure InitGr;
Var
  Gd, Gm : Integer;
Begin
  Gd := detect;
  Gm := 0;
  InitGraph(Gd,Gm,'');
End;

Procedure Draw2Lines;
Begin
  SetColor(1);
  Line(100,100,200,200);
  Line(100,100,250,200);
End;

Procedure DrawNLines_File;
Var
  T     : Text;
  N     : Byte;
  i     : Byte;
  Color : Byte;
  X1,Y1 : Integer;
  X2,Y2 : Integer;
Begin
  Assign(T,PathToData_File);
  Reset(T);
  ReadLn(T,N);
  For i := 1 To N Do
  Begin
     Read(T,Color);
     Read(T,X1);
     Read(T,Y1);
     Read(T,X2);
     Read(T,Y2);
     ReadLn(T);
     SetColor(Color);
     Line(X1,Y1,X2,Y2);
  End;
  Close(T);
End;

Procedure CreateFile_P;
Var
  I,J : Byte;
  T   : Text;
  C   : Byte;
Begin
  if P_File_Name='' then
  begin
    Assign(T,'Out.P');
  end else
  begin
    Assign(T,P_File_Name);
  end;
  ReWrite(T);
  For I := 1 to 16 Do
  Begin
    For J := 1 to 16 Do
    Begin
      C := GetPixel(P_StX + 100+(I-1),
                    P_StY + 100+(J-1));
      Write(T,C,' ');
    End;
    WriteLn(T);
  End;
  Close(T);
End;

Procedure CreateFile_P5;
Var
  T : Text;
  I : Byte;
  J : Byte;
  S : String;
Begin
  Assign(T,'Out.p5');
  ReWrite(T);
  For I := 1 to 5 Do
  Begin
    For J := 1 to 5 Do
    Begin
      Str(I,S);
      P_File_Name := S;
      Str(J,S);
      P_File_Name := P_File_Name + S;
      P_File_Name := 'Out' + P_File_Name + '.p';
      P_StX       := 0 + (I-1) * (16 + 1);
      P_StY       := 0 + (J-1) * (16 + 1);
      CreateFile_P;
      Write(T,(I-1)*5 + (J-1) + 1,' ');
    End;
    WriteLn(T)
  End;
  For I := 1 to 5 Do
  Begin
    For J := 1 to 5 Do
    Begin
      Str(I,S);
      P_File_Name := S;
      Str(J,S);
      P_File_Name := P_File_Name + S;
      P_File_Name := 'Out' + P_File_Name + '.p';
      WriteLn(T,P_File_Name);
    End;
  End;
  Close(T);
End;

Var
  DrawFromFile : Boolean;
Begin
  InitGr;

  DrawFromFile := true;

  P_File_Name := '';
  P_StX       := 0;
  P_StY       := 0;


  If(DrawFromFile) Then
  Begin
    DrawNLines_File; { Draw lines from file. }
  End Else
  Begin
    Draw2Lines;      { Draw lines from this program. }
  End;

  CreateFile_P;
  CreateFile_P5;

  ReadLn;
  CloseGraph;
End.