home *** CD-ROM | disk | FTP | other *** search
- Program Example1;
- {Simple program for Turbo Pascal version 5.0 showing the use of SCR2GIFU.PAS
- unit for screen compression to GIF graphics file which includes the LZW
- routines in CMPRSS.INC. To use the unit, simply include SCR2GIFU in
- your USES statement, then call 'ScreenToGif(FileName:String):Integer' when
- you are ready to send the screen to a GIF file. The following is a simple
- program demonstrating the SCR2GIFU unit. It demonstrates
- automatic selection of a file name 'SCR0000.GIF' through 'SCR9999.GIF',
- display of a test screen, and saving to a GIF file. This program uses the
- TP GRAPH.TPU graphics unit to automatically select a graphics mode.
-
- For details of the SCR2GIFU unit usage, see the header of the
- SCR2GIFU.PAS file.
-
- Written by Rob Crockett [76167,1561] April 1992. The include file
- CMPRSS.INC written by Bob Berry [76555,167] 1988. }
-
- Uses CRT,
- GRAPH,
- SCR2GIFU;
-
- Function FileExists(FileName: String):Boolean;
- Var
- BinFile : File;
- Begin
- Assign(BinFile,FileName);
- {$I-} Reset(BinFile); {$I+}
- If IOResult=0
- Then
- Begin
- Close(BinFile);
- FileExists:=True;
- End
- Else FileExists:=False;
- End; {of FileExists}
-
- Function GetGifFileName: String;
- {Generates numbered GIF file names until a name is found that is
- not in the current directory. Named 'SCR0000.GIF' to 'SCR9999.GIF'.
- Utilizes the 'FileExists' procedure.}
-
- Const
- Preface = 'SCR';
- Suffix = '.GIF';
- Var
- GifFileName,
- FileNumberString: String;
- FileNumber : Integer;
- Begin
- FileNumber:=-1;
- Repeat
- FileNumber:=Succ(FileNumber);
- Str(FileNumber,FileNumberString);
- If (Length(FileNumberString)<4) then
- Repeat
- FileNumberString:='0'+FileNumberString;
- Until (Length(FileNumberString)=4);
- GifFileName:=Preface+FileNumberString+Suffix;
- Until ((Not FileExists(GifFileName)) OR (FileNumber=9999));
- GetGifFileName:=GifFileName;
- End;
-
-
- Procedure DrawFigures;
- {Draws a test graphics screen}
-
- Var
- I,J,
- XCenter,YCenter,
- Width,Height : Integer;
- Radius : Word;
- XString,YString,
- CString : String[3];
- InChar : Char;
- Begin
- XCenter:=GetMaxX DIV 2;
- YCenter:=GetMaxY DIV 2;
- Radius:=GetMaxX DIV 6;
- Height:=TextHeight('T');
- Width:=TextWidth('000');
-
- PutPixel(XCenter,YCenter,LightMagenta);
-
- If GetMaxColor<=15
- Then
- For I:=0 to GetMaxColor do
- Begin
- SetColor(I);
- Str(I,CString);
- OutTextXY(10,10+I*Height,CString);
- End
- Else
- For I:=0 to 22 do
- For J:=0 to 11 do
- Begin
- SetColor(I+J*23);
- Str(I+J*23,CString);
- OutTextXY(10+J*Width,10+I*Height,CString);
- End;
-
- SetColor(Blue);
- Circle(XCenter,YCenter,Radius);
-
- SetColor(Blue);
- Rectangle(0,0,GetMaxX,GetMaxY);
- Rectangle(100,100,115,115);
-
- For I:=1 to 1000 do
- Begin
- PutPixel((GetMaxX div 2)+Random((GetMaxX div 2)-1),
- Random(GetMaxY-1),1+Random(GetMaxColor));
- End;
-
- For I:=1 to 500 do
- Begin
- SetColor(Random(GetMaxColor));
- Line((GetMaxX div 6)*4,(GetMaxY div 4),
- Random(GetMaxX div 2)+(GetMaxX div 2),
- Random(GetMaxY div 3)+1);
- End;
- End;
-
- Procedure StartTone;
- Begin
- Sound(1000);
- Delay(50);
- NoSound;
- End;
-
- Procedure OkTone;
- Begin
- Sound(900);
- Delay(100);
- Sound(1000);
- Delay(100);
- NoSound;
- End;
-
- Procedure NotOkTone;
- Begin
- Sound(50);
- Delay(500);
- NoSound;
- End;
-
-
- {**********MAIN PROGRAM**************************************************}
-
- Var
- GifFileName: String;
- GraphDriver,GraphMode,
- GifCompressError: Integer;
- Begin
- GraphDriver:=Detect; {automatic mode selection}
- InitGraph(GraphDriver,GraphMode,''); {open graphics, GRAPH.TPU...}
- {..in current directory.}
- DrawFigures; {draw some graphics}
- GifFileName:=GetGifFileName; {find name not already used}
- SetColor(1); {set color for graphics write}
- OutTextXY(2,2,GifFileName); {write file name in corner}
- StartTone; {tone at start of save}
- GifCompressError:=ScreenToGif(GifFileName); {save screen to GIF file}
- CloseGraph; {close graphics and exit}
- If GifCompressError=0 {status tones}
- Then OkTone
- Else NotOkTone;
- End.
-