Anda di halaman 1dari 57

I.

Introduction
Nowadays people make many modern programs and games, which require a modern computer deskside. So we have come up with the program, which allows creating image files with a small size, but at the same time advanced program. We have made this program for work with vector graphics. The Vector graphics (geometric modeling) it is used for making geometric simple objects such as points, lines, polygonal figures and for presentation of the scenes in computer graph. This term is used as contrasted to raster graph, which presents the scenes as matrix of the pixels. Since the time of computer invention have computer graphics appeared, which are presently considered as an integral part in the world technology. In the beginning this was only vector graphics building the scene by means of the so called "vector" - functions, which allow computing the position of the point on the screen or paper. For example, function, in which graph is a circle, is a straight line or more complex curves. With development of the computer technology its become necessary to ensemble ways of building graphic objects. But for the beginning, we must define the term "graphic object". This is the graphic scene or its part. Depending on types of computer graphs this term is defined as pixels or sprites (in raster graph), so and vector objects such as circle, square, line, curve and etc. (in vector graph). For the further consideration the problem of building objects by vector graphs, it is necessary to understand the difference between two main types computer graphs - raster and vector.

Vector graphics
The Vector graphics describes the scenes with usage of direct and crooked lines, named vector, and parameters, describing colors and location. For example, image of the wood sheet is described by points, through which passes the line, creating hereunder sidebar of the sheet. The color of the sheet is assigned by color of the sidebar and area is inwardly this sidebar.

Raster graphics
The Raster graphics describe the scenes using colorful points, named pixels, located on the net. For example, image of the wood sheet is described by concrete location and colors of each point of the net that create the scene approximately like in mosaic. In editing raster graphs you edit pixels, not the lines. The Raster graphics depend on permits because the information, which describes scenes, is attached to the net of the certain size. In editing raster graphs, the quality of its presentation can change. In particular, changing sizes of raster graphs can bring image with bad quality, because pixels will be redistributed on the net.

II. The Exploratory part


1. Economical programming
First, this program creates the vector objects, saved in the manner of text with extension "gmd" (Graph Model Description), also these files can be saved in the manner of drawing in such format, as JPG, BMP, ICO, EMF, WMF. Since file is saved in the manner of text, it takes smaller space. In "gmd" files are written coordinates of points, name, color of lines, color of the filling, thickness of lines and type (None, Line, Polygon, Polyline, PolyBizier, Ellipse, RoundRect, Arc, Chord, FrameRect, FillRect, FloodFill) of each layer. gmd files can be used for creating games, screen savers, etc. The use of "gmd" files are vastly more economical than using the files, saved in the manner of drawing, so program with "gmd" files will use the operative memory and less processor usage. At present there are many programs on creation graphic objects, but there is no program, which could create the objects with a small size and a good quality, but our program saves both criterions of the graphic object. Additionally these files have no analogue. This program was written on programming language Borland Delphi 7.0. The program is very easy in use and it does not require additional installation and its own installation. What do we know, when we hear "economical programming"? Certainly, we know that this program, which occupies small place or uses the system facility of the computer less than always. But to create such program, we need determined raw material, which must correspond to the small requirements for this program.

The majority of programmers create the programs with high requirements and high quality of registration, while this it possibly shorten the requirements, having saved quality of the registration of the program, by means of economical programming. "Smart Modeller" completely approaches under notion "economical programming". "Smart Modeller" creates vector objects with extension "gmd" (Graph Model Descriptions), which are saved in the manner of text and that is much more economical. Coordinate points, names, color of line, color of filling, width of line (None, Line, polygon, polyline, polybizier, ellipse, roundrect, arc, chord, framerect, fillrect and flood fill) and the type of each layer is saved in gmd files. "gmd" files can be used in writing games, logoes, model and etc, we said above about this. Any program which written using "gmd" file, will use OZU and processor less than always, because "gmd" file is saved in the manner of text and coding naturally will be much seldom.

2. About program
The principle working of program
When we open our program "Smart Modeller", we see a window, dividing into three sides: "Tools", "Layers" and "Main Window". On the side "Tools" you choose any figures, which you need and draw on the window "Main Window", on the side "Layers" the computer writes the name of the layers, which are used at present. And in window "Main Window" computer shows the objects, which were drawn by you.

(Full form of the program)

(Form of the example which is identified "Tank") (Form

of the example, which

(Form of the programs


7

"Mascit") Menu "File" New - Create the new document. Open - Open the preserved document. Close - Close the active window. Save - Save the drawn object. Save as - Change location of the object Save as bitmap - save as drawing Exit - Close program "Smart Modeller"

about window )

Menu "Edit" Add layer - Add layer Delete layer - Delete layer Rename layer - Rename layer Editing - Enable to change Moving - Enable to move Rotate - Enable to turn

Menu "View" Layers - On / Off window "Layers" Tools - On / Off window "Tools" Zoom in - Show closer Zoom out - Show further

Menu "Help" About Smart Modeller about program

Tools

Create empty layer Draw pentagon Draw twist line Draw circular tetragon Draw floor of the circle with potting Draw tetragon with potting

Draw line Draw triangle Draw circle Draw floor of the circle Draw tetragon Potting

Color to circumferences

Color of the potting Thickness to circumference s


9

III. Conclusion
The degree of development computer technology allows us to say that computer has become one of important forming lives of the person, also possible to say about programming. nd for quick development of this area, it was necessary to create the program, which simplifies programming. All applications - whether engineering and scientific, business and art/entertainment - are a sphere of using vector graphs. The increasing potential of PC and their huge number - an order of 100 million provides the seductive base for capital investments and growth. Today particularly attractive for investors the companies, specializing in graphic user interfaces, object-oriented programs, virtual reality and software ensuring the parallel processes. The Computer graphics today has industrial basis, priced at 36 mlrd. doll., which provides functioning about 300 thousand specialists. It continues to lead in questions of the provision of our interaction with computer and organizations of the access to information. We are going to the new epoch of the extension authority graphic systems when moving on information superhighway. So in sphere of the programming for achievement of some plank, some level requires something new. Thereby, having created our program, we want to contribute to the development the programming in Kazakhstan and Turkey As it is said in strategic program "KAZAKHSTAN - 2030" for achievement integer, it is necessary to decide the tasks such, as "priority development of the formation, sciences and innovative activity".

10

IV. Application
Listing
unit UMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Menus, CheckLst, ExtCtrls, ExtDlgs, UFormObject, ToolWin, ComCtrls, jpeg, Buttons, ImgList; const n_MAXWIN=20; type TObjectWin = record Name:string; No:integer; end; TFMain = class(TForm) Main: TMainMenu; mnObject: TMenuItem; mnNew: TMenuItem; mnOpen: TMenuItem; mnClose: TMenuItem; N1: TMenuItem; mnSave: TMenuItem; mnSaveas: TMenuItem; mnSaveasbitmap: TMenuItem; N2: TMenuItem; mnExit: TMenuItem; mnEdit: TMenuItem; mnAddlayer: TMenuItem; mnDeletelayer: TMenuItem; mnRenameLayer: TMenuItem; N3: TMenuItem; mnView: TMenuItem; mnLayers: TMenuItem; OpenDialog: TOpenDialog; SaveDialog: TSaveDialog; SavePictureDialog: TSavePictureDialog; mnTools: TMenuItem; mnEditing: TMenuItem; mnMoving: TMenuItem; N4: TMenuItem; mnZoonIn: TMenuItem; mnZoomOut: TMenuItem; 11

mnRotate: TMenuItem; mnHelp: TMenuItem; mnAbout: TMenuItem; Image1: TImage; ToolBar2: TToolBar; SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; SpeedButton3: TSpeedButton; ToolButton1: TToolButton; ToolButton2: TToolButton; tbMoveObj: TToolButton; tbrotate: TToolButton; tbEditObj: TToolButton; ToolButton3: TToolButton; ImageList1: TImageList; procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); procedure mnLayersClick(Sender: TObject); procedure mnNewClick(Sender: TObject); procedure mnSaveClick(Sender: TObject); procedure mnSaveasClick(Sender: TObject); procedure mnOpenClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure mnExitClick(Sender: TObject); procedure SaveDialogCanClose(Sender: TObject; var CanClose: Boolean); procedure mnToolsClick(Sender: TObject); procedure mnCloseClick(Sender: TObject); procedure mnSaveasbitmapClick(Sender: TObject); procedure tbEditObjClick(Sender: TObject); procedure tbMoveObjClick(Sender: TObject); procedure tbRotateClick(Sender: TObject); procedure mnEditingClick(Sender: TObject); procedure mnMovingClick(Sender: TObject); procedure mnZoonInClick(Sender: TObject); procedure mnZoomOutClick(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure mnRotateClick(Sender: TObject); procedure mnAddlayerClick(Sender: TObject); procedure mnDeletelayerClick(Sender: TObject); procedure mnAboutClick(Sender: TObject); procedure tbNewObjClick(Sender: TObject); procedure tbOpenObjClick(Sender: TObject); procedure tbSaveObjClick(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); procedure SpeedButton3Click(Sender: TObject); procedure SpeedButton5Click(Sender: TObject); procedure SpeedButton6Click(Sender: TObject); 12

procedure tbClick(Sender: TObject); procedure tbrotateObjClick(Sender: TObject); procedure ToolButton5Click(Sender: TObject); procedure mnRenameLayerClick(Sender: TObject); private { Private declarations } public { Public declarations } Objects:array[1..n_MAXWIN]of TObjectWin; ObjectCount:integer; ObjectOnDesk:integer; ObjectIndex:integer; procedure CreateNewObject; procedure DestroyObject(Name:TComponentName); function CurrentObj:TFObject; function ObjEnable:boolean; end; var FMain: TFMain; function EnEditing:boolean; function EnMoving:boolean; function EnRotate:boolean; implementation uses ULayers, UGraphDriver, UUnitMode, UAbout; {$R *.dfm} function EnEditing:boolean; begin Result:=FMain.tbEditObj.Marked; end; function EnMoving:boolean; begin Result:=FMain.tbMoveObj.Marked; end;

function EnRotate:boolean; begin Result:=FMain.tbRotate.Marked; end; procedure TFMain.SpeedButton5Click(Sender: TObject); begin tbRotate.Marked:=not tbRotate.Marked; 13

end; procedure TFMain.SpeedButton6Click(Sender: TObject); begin tbEditObj.Marked:=not tbEditObj.Marked; end;

procedure TFMain.CreateNewObject; var I:integer; begin if ObjectCount<n_MAXWIN then begin inc(ObjectCount); inc(ObjectOnDesk); end else begin MessageDlg('Too many windows'+#13+'close some of them',mtError,[mbOk],0); exit; end; For I:= 1 to n_MAXWIN do if Objects[I].No=0 then begin NewObject(I); Objects[I].Name:='Obj'+inttostr(I); Objects[I].No:=I; ObjectIndex:=I; exit; end; Caption:=inttostr(ObjectOnDesk); end; procedure TFMain.DestroyObject(Name: TComponentName); begin try TFObject(Application.FindComponent(Name)).Free; Dec(ObjectOnDesk); except end; end; procedure TFMain.FormCreate(Sender: TObject); begin {Form} Width:=800; Height:=600; Color:=rgb(160,180,180); ObjectCount:=0; end; 14

procedure TFMain.FormShow(Sender: TObject); begin mnNewClick(self); mnTools.Checked:=toolMode.Visible; mnLayers.Checked:=toolLayers.Visible; mnEditingClick(self); mnToolsClick(self); end; procedure TFMain.mnLayersClick(Sender: TObject); begin toolLayers.Visible:=not toolLayers.Visible; mnLayers.Checked:=toolLayers.Visible; toollayers.ObjRefresh; end; procedure TFMain.mnNewClick(Sender: TObject); begin CreateNewObject; CurrentObj.Saved:=true; end; procedure TFMain.mnSaveClick(Sender: TObject); begin if not ObjEnable then exit; SaveDialog.Title:='Save Model'; SaveDialog.DefaultExt:='*.gmd'; SaveDialog.InitialDir:=GetCurrentDir+'\Models'; if CurrentObj.Saved then CurrentObj.Obj.Save(CurrentObj.Obj.FileName) else begin if SaveDialog.Execute then begin CurrentObj.Obj.Save(SaveDialog.FileName); CurrentObj.Caption:=ExtractFileName(SaveDialog.FileName); CurrentObj.Saved:=true; end; end; end; procedure TFMain.mnSaveasClick(Sender: TObject); begin if not ObjEnable then exit; SaveDialog.Title:='Save Model As'; SaveDialog.DefaultExt:='*.gmd'; SaveDialog.InitialDir:=GetCurrentDir+'\Models'; if SaveDialog.Execute then begin CurrentObj.Obj.Save(SaveDialog.FileName); end; 15

end; procedure TFMain.mnOpenClick(Sender: TObject); begin OpenDialog.Title:='Open Model'; OpenDialog.InitialDir:=GetCurrentDir+'\Models'; if OpenDialog.Execute then begin CreateNewObject; CurrentObj.Caption:=ExtractFileName(OpenDialog.FileName); CurrentObj.Obj.Load(OpenDialog.FileName); CurrentObj.Saved:=true; toolLayers.ObjRefresh; end; end; function TFMain.CurrentObj: TFObject; var Win:TComponent; begin Win:= Application.FindComponent(Objects[ObjectIndex].Name); if win<>nil then Result:=TFObject(Win) else Result:=nil; end; function TFMain.ObjEnable: boolean; begin Result:=Application.FindComponent(Objects[ObjectIndex].Name)<>nil; end; procedure TFMain.FormClose(Sender: TObject; var Action: TCloseAction); var R:byte; begin while ObjectOnDesk>0 do begin if CurrentObj.Saved then begin DestroyObject(CurrentObj.Name); end else begin R:=MessageDlg('Save object named '+CurrentObj.Caption,mtConfirmation,mbYesNoCancel,0); IF r=6 THEN begin SaveDialog.Title:='Save Model As'; SaveDialog.DefaultExt:='*.gmd'; SaveDialog.InitialDir:=GetCurrentDir+'\Models'; if SaveDialog.Execute then begin CurrentObj.Obj.Save(SaveDialog.FileName); DestroyObject(CurrentObj.Name); end else begin Action:=caNone; Exit; end; end; if R=7 then begin DestroyObject(CurrentObj.Name); 16

end; IF R=2 then begin Action:=caNone; Exit; end; End; end; end; procedure TFMain.mnExitClick(Sender: TObject); begin close; end; procedure TFMain.SaveDialogCanClose(Sender: TObject; var CanClose: Boolean); var R:byte; begin if pos('.',SaveDialog.FileName)=0 then SaveDialog.FileName:=SaveDialog.FileName+'.gmd'; if FileExists(SaveDialog.FileName) then begin R:=MessageDlg('Model with name '+ExtractFileName(SaveDialog.FileName)+#13+'already exist'+#13+'Do you want replace it?',mtConfirmation,[mbYes,mbNo],0); if R=6 then CanClose:=true else CanClose:=false; end; end; procedure TFMain.mnToolsClick(Sender: TObject); begin toolMode.Visible:=not toolMode.Visible; mnTools.Checked:=toolMode.Visible; end; procedure TFMain.mnCloseClick(Sender: TObject); begin CurrentObj.Close; end; procedure TFMain.mnSaveasbitmapClick(Sender: TObject); var B:TBitmap; C:TPoint2D; begin SavePictureDialog.Title:='Save model As Bitmap'; if SavePictureDialog.Execute then begin B:=TBitmap.Create; B.Width:=round(CurrentObj.Obj.Size.X*2); B.Height:=round(CurrentObj.Obj.Size.Y*2); C:=CurrentObj.Obj.Center; CurrentObj.Obj.Center:=CurrentObj.Obj.Size; CurrentObj.Obj.Draw(B.Canvas); 17

CurrentObj.Obj.Center:=C; B.SaveToFile(SavePictureDialog.FileName); B.Free; end; end; procedure TFMain.tbEditObjClick(Sender: TObject); begin tbEditObj.Marked:=not tbEditObj.Marked; end; procedure TFMain.tbMoveObjClick(Sender: TObject); begin tbMoveObj.Marked:= not tbMoveObj.Marked; end; procedure TFMain.tbRotateClick(Sender: TObject); begin tbRotate.Marked:=not tbRotate.Marked; end; procedure TFMain.mnEditingClick(Sender: TObject); begin tbEditObjClick(self); mnEditing.Checked:=tbEditObj.Marked; toollayers.ObjRefresh; end; procedure TFMain.mnMovingClick(Sender: TObject); begin tbMoveObjClick(self); mnMoving.Checked:=tbMoveObj.Marked; toollayers.ObjRefresh; end; procedure TFMain.mnZoonInClick(Sender: TObject); begin CurrentObj.Obj.Size:=Point2D(CurrentObj.Obj.Size.X+10,CurrentObj.Obj.Size.Y+10); toollayers.ObjRefresh; end; procedure TFMain.mnZoomOutClick(Sender: TObject); begin CurrentObj.Obj.Size:=Point2D(CurrentObj.Obj.Size.X-10,CurrentObj.Obj.Size.Y-10); toollayers.ObjRefresh; end; procedure TFMain.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 18

begin if key=32 then mnNewClick(self); end; procedure TFMain.mnRotateClick(Sender: TObject); begin tbRotateClick(self); mnRotate.Checked:=tbRotate.Marked; toollayers.ObjRefresh; end; procedure TFMain.mnAddlayerClick(Sender: TObject); begin FMain.CurrentObj.NewLayer; toolLayers.ObjRefresh; end; procedure TFMain.mnDeletelayerClick(Sender: TObject); begin FMain.CurrentObj.Obj.DeleteLayer(toolLayers.Layers.ItemIndex); toolLayers.ObjRefresh; end; procedure TFMain.mnAboutClick(Sender: TObject); begin AboutBox.Show; toollayers.ObjRefresh; end; procedure TFMain.tbNewObjClick(Sender: TObject); begin CreateNewObject; end; procedure TFMain.tbOpenObjClick(Sender: TObject); begin OpenDialog.Title:='Open Model'; OpenDialog.InitialDir:=GetCurrentDir+'\Models'; if OpenDialog.Execute then begin CreateNewObject; CurrentObj.Caption:=ExtractFileName(OpenDialog.FileName); CurrentObj.Obj.Load(OpenDialog.FileName); CurrentObj.Saved:=true; toolLayers.ObjRefresh; end; end; procedure TFMain.tbSaveObjClick(Sender: TObject); begin 19

if not ObjEnable then exit; SaveDialog.Title:='Save Model'; SaveDialog.DefaultExt:='*.gmd'; SaveDialog.InitialDir:=GetCurrentDir+'\Models'; if CurrentObj.Saved then CurrentObj.Obj.Save(CurrentObj.Obj.FileName) else begin if SaveDialog.Execute then begin CurrentObj.Obj.Save(SaveDialog.FileName); CurrentObj.Caption:=ExtractFileName(SaveDialog.FileName); CurrentObj.Saved:=true; end; end; end; procedure TFMain.SpeedButton1Click(Sender: TObject); begin CreateNewObject; CurrentObj.Saved:=true; end; procedure TFMain.SpeedButton2Click(Sender: TObject); begin OpenDialog.Title:='Open Model'; OpenDialog.InitialDir:=GetCurrentDir+'\Models'; if OpenDialog.Execute then begin CreateNewObject; CurrentObj.Caption:=ExtractFileName(OpenDialog.FileName); CurrentObj.Obj.Load(OpenDialog.FileName); CurrentObj.Saved:=true; toolLayers.ObjRefresh; end; end; procedure TFMain.SpeedButton3Click(Sender: TObject); begin if not ObjEnable then exit; SaveDialog.Title:='Save Model'; SaveDialog.DefaultExt:='*.gmd'; SaveDialog.InitialDir:=GetCurrentDir+'\Models'; if CurrentObj.Saved then CurrentObj.Obj.Save(CurrentObj.Obj.FileName) else begin if SaveDialog.Execute then begin CurrentObj.Obj.Save(SaveDialog.FileName); CurrentObj.Caption:=ExtractFileName(SaveDialog.FileName); CurrentObj.Saved:=true; end; 20

end; End; procedure TFMain.tbClick(Sender: TObject); begin tbMoveObj.Marked:= not tbMoveObj.Marked; end; procedure TFMain.tbrotateObjClick(Sender: TObject); begin tbRotate.Marked:=not tbRotate.Marked; end; procedure TFMain.ToolButton5Click(Sender: TObject); begin tbEditObj.Marked:=not tbEditObj.Marked; end; procedure TFMain.mnRenameLayerClick(Sender: TObject); var s:string; begin if InputQuery('Rename','Enter New Name',s) then FMain.CurrentObj.Obj.CurName:=s; FMain.CurrentObj.OnActivate(self); toollayers.ObjRefresh; end; end. unit UUnitMode; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ToolWin, ComCtrls, StdCtrls, ImgList, UGraphDriver, ExtCtrls; type TtoolMode = class(TForm) ToolBar: TToolBar; tlLine: TToolButton; tlPolygon: TToolButton; tlPolyline: TToolButton; tlPolyBizier: TToolButton; tlEllipse: TToolButton; tlRoundRect: TToolButton; tlArc: TToolButton; tlChord: TToolButton; tlFrameRect: TToolButton; tlFillRect: TToolButton; 21

tlFloddFill: TToolButton; tlNone: TToolButton; ToolButton1: TToolButton; ImageList: TImageList; pnStyle: TPanel; edWD: TEdit; udWD: TUpDown; pnWD: TPanel; pnColor: TPanel; pnColorCL: TPanel; pnColorBkCl: TPanel; ColorDialog: TColorDialog; procedure FormCreate(Sender: TObject); procedure ButClick(Sender:TObject); procedure tlPolygonMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormResize(Sender: TObject); procedure udWDChanging(Sender: TObject; var AllowChange: Boolean); procedure pnColorCLClick(Sender: TObject); procedure pnColorBkClClick(Sender: TObject); procedure edWDChange(Sender: TObject); private { Private declarations } public { Public declarations } CreateLayer:boolean; procedure PushBut(Index:integer); function CurMode:TGraphUnitMode; function CutWD:Word; function CurCl:TColor; function CurBkCl:TColor; procedure ObjRefresh; end; var toolMode: TtoolMode; implementation uses UMain, ULayers, UFormObject; {$R *.dfm} procedure TtoolMode.ButClick(Sender: TObject); begin if FMain.ObjectOnDesk=0 then exit; if CreateLayer then begin PushBut(TToolButton(sender).Index); 22

FMain.CurrentObj.NewLayer; toolLayers.ObjRefresh; end; Fmain.CurrentObj.Saved:=False; end; function TtoolMode.CurMode: TGraphUnitMode; var I:integer; begin for I:= 0 to ToolBar.ButtonCount-1 do if ToolBar.Buttons[i].Down then begin Result:=IntToMode(I); Exit; end; Result:=umNone; end; procedure TtoolMode.FormCreate(Sender: TObject); begin {Form} Width:=84; Height:=400; Left:=5; top:=80; tlLine.Width:=32; tlLine.Height:=32; pnStyle.Height:=20; pnWD.Height:=pnStyle.Height; pnColor.Height:=pnStyle.Height; pnColorCL.Height:=pnStyle.Height; pnColorBkCl.Height:=pnStyle.Height; end; procedure TtoolMode.ObjRefresh; begin if FMain.CurrentObj<> nil then PushBut(ModeToInt(FMain.CurrentObj.Obj.CurUnit.Mode)) else PushBut(15); end; procedure TtoolMode.PushBut(Index:integer); var I:integer; begin for I:= 0 to ToolBar.ButtonCount-1 do if ToolBar.Buttons[i].Index<>Index then ToolBar.Buttons[i].Down:=false else ToolBar.Buttons[i].Down:=true; end; 23

procedure TtoolMode.tlPolygonMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if ssleft in shift then CreateLayer:=true else begin CreateLayer:=false; PushBut(TToolButton(sender).Index); FMain.CurrentObj.Obj.CurMode:=IntToMode(TToolButton(sender).Index); toolLayers.ObjRefresh; end; end; procedure TtoolMode.FormResize(Sender: TObject); begin edWD.Left:=0; edWD.Top:=pnStyle.Height+ToolBar.Height+pnWD.Height+pnColor.Height+pnColorCL.Height +pnColorBkCl.Height; edWD.Width:=ClientWidth-udWD.Width; udWD.Associate:=edWD; end; function TtoolMode.CutWD: Word; begin Result:=udWD.Position; end; procedure TtoolMode.udWDChanging(Sender: TObject; var AllowChange: Boolean); begin if (FMain.ObjEnable)and(FMain.CurrentObj.Obj.UnitEnable) then begin FMain.CurrentObj.Obj.CurWD:=udWD.Position; AllowChange:=true; end; end; procedure TtoolMode.pnColorCLClick(Sender: TObject); begin if ColorDialog.Execute then pnColorCL.Color:=ColorDialog.Color; if FMain.CurrentObj<>nil then FMain.CurrentObj.Obj.CurCl:=pnColorCL.Color; end; procedure TtoolMode.pnColorBkClClick(Sender: TObject); begin if ColorDialog.Execute then pnColorBkCl.Color:=ColorDialog.Color; if (FMain.CurrentObj<>nil)and(FMain.CurrentObj.Obj.UnitEnable) then FMain.CurrentObj.Obj.CurBkCl:=pnColorBkCl.Color; end; function TtoolMode.CurBkCl: TColor; 24

begin Result:=pnColorBkCl.Color; end; function TtoolMode.CurCl: TColor; begin Result:=pnColorCL.Color; end; procedure TtoolMode.edWDChange(Sender: TObject); begin iF (edWd.text<>'')and(Strtoint(edWD.text)<1000) then if Strtoint(edWD.text)<0 then udWd.Position:=1 else udWD.Position:=StrToInt(edWD.Text); end;

end. unit ULayers; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, CheckLst, Menus, UGraphDriver, UFormObject; type TtoolLayers = class(TForm) Layers: TCheckListBox; Menu: TPopupMenu; mnAddlayer: TMenuItem; mnDeletelayer: TMenuItem; mnRenamelayer: TMenuItem; procedure FormCreate(Sender: TObject); procedure LayersClick(Sender: TObject); procedure LayersDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure LayersDragDrop(Sender, Source: TObject; X, Y: Integer); procedure LayersStartDrag(Sender: TObject; var DragObject: TDragObject); procedure mnRenamelayerClick(Sender: TObject); procedure mnDeletelayerClick(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure mnAddlayerClick(Sender: TObject); private 25

{ Private declarations } It:integer; public { Public declarations } procedure ObjRefresh; function CurObj:TFObject; end; var toolLayers: TtoolLayers; implementation uses UMain, UUnitMode; {$R *.dfm} procedure TtoolLayers.FormCreate(Sender: TObject); begin {Form} Width:=200; Height:=300; Left:=Screen.Width-Width-5; Top:=80; end; procedure TtoolLayers.ObjRefresh; var I,L,C:Integer; begin if (CurObj=nil)or(CurObj.Obj.UnitCount=0) then begin Layers.Clear; exit; end; Layers.Clear; L:=CurObj.Obj.UnitCount; C:=CurObj.Obj.CurIndex; For I:= 0 to L-1 do begin CurObj.Obj.CurIndex:=I; Layers.Items.Add(CurObj.Obj.CurUnit.Name); Layers.Checked[I]:=CurObj.Obj.CurUnit.En; end; CurObj.Obj.CurIndex:=C; Layers.ItemIndex:=C; toolMode.ObjRefresh; end;

26

procedure TtoolLayers.LayersClick(Sender: TObject); begin if (CurObj<>nil)or(CurObj.Obj.UnitCount=0) then begin CurObj.obj.CurIndex:=Layers.ItemIndex; CurObj.obj.UnitEn[Layers.ItemIndex]:=Layers.Checked[Layers.ItemIndex]; toolMode.ObjRefresh; CurObj.Motor.ReDraw; toolMode.pnColorCL.Color:=CurObj.obj.CurCl; toolMode.pnColorBkCl.Color:=CurObj.obj.CurBkCl; toolMode.udWD.Position:=CurObj.obj.CurWD; end; end;

function TtoolLayers.CurObj: TFObject; begin try Result:=TFObject(Application.FindComponent(FMain.Objects[FMain.ObjectIndex].Name)); except Result:=nil; end; end; procedure TtoolLayers.LayersDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin if Layers.ItemAtPos(point(X,Y),true)>=0 then begin Accept:=true; Layers.ItemIndex:=Layers.ItemAtPos(point(X,Y),true); end else Accept:=false; end; procedure TtoolLayers.LayersDragDrop(Sender, Source: TObject; X, Y: Integer); begin FMain.CurrentObj.Obj.ReplaceLayers(It,Layers.ItemIndex); ObjRefresh; end; procedure TtoolLayers.LayersStartDrag(Sender: TObject; var DragObject: TDragObject); begin Caption:=IntToStr(Layers.ItemIndex); It:=Layers.ItemIndex; end; procedure TtoolLayers.mnRenamelayerClick(Sender: TObject); 27

var s:string; begin if InputQuery('Rename','Enter New Name',s) then FMain.CurrentObj.Obj.CurName:=s; FMain.CurrentObj.OnActivate(self); toollayers.ObjRefresh; end; procedure TtoolLayers.mnDeletelayerClick(Sender: TObject); begin FMain.CurrentObj.Obj.DeleteLayer(Layers.ItemIndex); ObjRefresh; end; procedure TtoolLayers.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key= 117 THEN Next; end; procedure TtoolLayers.mnAddlayerClick(Sender: TObject); begin FMain.CurrentObj.NewLayer; toolLayers.ObjRefresh; end; end. unit UFormObject; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, UGraphDriver, StdCtrls, ComCtrls; type TFObject = class(TForm) Status: TStatusBar; procedure FormCreate(Sender: TObject); procedure FormResize(Sender: TObject); procedure FormPaint(Sender: TObject); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); procedure FormActivate(Sender: TObject); 28

procedure StatusClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } procedure MotorBack(DC:TCanvas; ID:TID_Process); public { Public declarations } ObjectNo:integer; Obj:TGraphObject; Motor:TGraphDriver; MP,CP:TPoint; AD:TPointAD; Dot:byte; Saved,Saveing:boolean; procedure NewLayer; end; procedure NewObject(Index:integer); implementation uses ULayers, UMain, UUnitMode; {$R *.dfm} procedure NewObject(Index:integer); begin with TFObject.Create(Application) do begin Name:='Obj'+inttostr(Index); ObjectNo :=Index; Caption:='Untitled Model '+inttostr(Index); Show; end; end; procedure TFObject.FormCreate(Sender: TObject); begin {Form} Width:=700; Height:=500; top:=3; left:=100; {Motor} Motor:=TGraphDriver.Create(self); Motor.DisplayHandle:=self.Handle; Motor.AddProcess(MotorBack); Motor.BackColor:=clCream; 29

{Obj} Obj:=TGraphObject.Create(self); Obj.Size:=FloatPoint(point(200,200)); Obj.Center:=FloatPoint( Point(ClientWidth div 2,ClientHeight div 2)); end; procedure TFObject.MotorBack(DC: TCanvas; ID: TID_Process); var C:TPoint; begin with DC do begin {Shared*********************************************************************} Brush.Color:=clWhite; Pen.Color:=clLtGray; Pen.Width:=1; Rectangle(Obj.ClipRect); MoveTo(0,round(obj.Center.Y)); LineTo(Width,round(obj.Center.Y)); MoveTo(round(obj.Center.X),0); LineTo(round(obj.Center.X),Height); // Ellipse(mp.X-5,mp.Y-5,mp.X+5,mp.Y+5); Obj.Draw(DC); {Centered*******************************************************************} {Editing komutu islevini yapyor*******************************************} if EnEditing then if obj.UnitCount<>0 then begin Pen.Width:=1; Brush.Style:=bsClear; Pen.Color:=clNavy; C:=RoundPoint(MoveKAng(Obj.Center,Obj.CurUnit.C.A,Obj.CurUnit.C.D,Obj.Size)); DC.Rectangle(C.X-obj.Delta,C.Y-obj.Delta,C.X+obj.Delta,C.Y+obj.Delta); Pen.Color:=clLtGray; if Obj.CurUnit.Mode=umPolyBizier then begin Pen.Color:=clLtGray; C:=RoundPoint(MoveKAng(AddPoints(Obj.Center,Move2D(Obj.CurC.A,obj.CurC.D,Obj.Siz e)),Obj.CurUnit.p1.A+Obj.CurUnit.p.A,Obj.CurUnit.p1.D+Obj.CurUnit.p.D,Obj.Size)); MoveTo(C.X,C.Y); C:=RoundPoint(MoveKAng(AddPoints(Obj.Center,Move2D(Obj.CurC.A,obj.CurC.D,Obj.Siz e)),Obj.CurUnit.p2.A+Obj.CurUnit.p.A,Obj.CurUnit.p2.D+Obj.CurUnit.p.D,Obj.Size)); LineTo(C.X,C.Y); C:=RoundPoint(MoveKAng(AddPoints(Obj.Center,Move2D(Obj.CurC.A,obj.CurC.D,Obj.Siz e)),Obj.CurUnit.p4.A+Obj.CurUnit.p.A,Obj.CurUnit.p4.D+Obj.CurUnit.p.D,Obj.Size)); 30

MoveTo(C.X,C.Y); C:=RoundPoint(MoveKAng(AddPoints(Obj.Center,Move2D(Obj.CurC.A,obj.CurC.D,Obj.Siz e)),Obj.CurUnit.p3.A+Obj.CurUnit.p.A,Obj.CurUnit.p3.D+Obj.CurUnit.p.D,Obj.Size)); LineTo(C.X,C.Y); end; Pen.Color:=clBlack; Pen.Mode:=pmNot; C:=RoundPoint(MoveKAng(AddPoints(Obj.Center,Move2D(Obj.CurC.A,obj.CurC.D,Obj.Size )),Obj.CurUnit.p1.A+Obj.CurUnit.p.A,Obj.CurUnit.p1.D+Obj.CurUnit.p.D,Obj.Size)); DC.Ellipse(C.X-obj.Delta,C.Y-obj.Delta,C.X+obj.Delta,C.Y+obj.Delta); C:=RoundPoint(MoveKAng(AddPoints(Obj.Center,Move2D(Obj.CurC.A,obj.CurC.D,Obj.Size )),Obj.CurUnit.p2.A+Obj.CurUnit.p.A,Obj.CurUnit.p2.D+Obj.CurUnit.p.D,Obj.Size)); DC.Ellipse(C.X-obj.Delta,C.Y-obj.Delta,C.X+obj.Delta,C.Y+obj.Delta); if Obj.CurUnit.Mode in [umPolygon,umPolyline,umPolyBizier,umChord,umArc] then begin C:=RoundPoint(MoveKAng(AddPoints(Obj.Center,Move2D(Obj.CurC.A,obj.CurC.D,Obj.Size )),Obj.CurUnit.p3.A+Obj.CurUnit.p.A,Obj.CurUnit.p3.D+Obj.CurUnit.p.D,Obj.Size)); DC.Ellipse(C.X-obj.Delta,C.Y-obj.Delta,C.X+obj.Delta,C.Y+obj.Delta); C:=RoundPoint(MoveKAng(AddPoints(Obj.Center,Move2D(Obj.CurC.A,obj.CurC.D,Obj.Size )),Obj.CurUnit.p4.A+Obj.CurUnit.p.A,Obj.CurUnit.p4.D+Obj.CurUnit.p.D,Obj.Size)); DC.Ellipse(C.X-obj.Delta,C.Y-obj.Delta,C.X+obj.Delta,C.Y+obj.Delta); end; Pen.Mode:=pmCopy; end; {TextOut********************************************************************} SetBkMode(DC.Handle,TRANSPARENT); DC.Font.Color:=rgb(120,160,160); TextOut(20,20,inttostr(MP.X)+' '+inttostr(mp.Y)); Brush.Color:=Motor.BackColor; end; end; procedure TFObject.FormResize(Sender: TObject); begin if Motor<>nil then begin Motor.BMP.Width:=ClientWidth; Motor.BMP.Height:=ClientHeight; end; end; procedure TFObject.FormPaint(Sender: TObject); begin Motor.ReDraw; end; 31

procedure TFObject.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin MP:=Point(X,Y); if not Obj.UnitEnable then exit; {Editing komutu islevini yapyor*************************************************************} if EnEditing then begin if ssleft in shift then begin // C:=MoveKAng(AddPoints(FCenter,Move2D(CurC.A,CurC.D,FSize)),CurUnit.p2.A,CurUnit.p2. D,FSize); AD:=PointAD(RelAngle2D(AddPoints(Obj.Center,Move2D(obj.CurC.A,obj.CurC.D,obj.Size)), FloatPoint(point(X,Y))),RelDistK(AddPoints(Obj.Center,Move2D(obj.CurC.A,obj.CurC.D,obj.Si ze)),FloatPoint(point(X,Y)),Obj.Size.X)); AD.A:=AD.A-Obj.CurP.A; case Dot of 1:Obj.CurP1:=AD; 2:Obj.CurP2:=AD; 3:Obj.CurP3:=AD; 4:Obj.CurP4:=AD; else begin if Obj.EntryCenter(MP) then obj.CurC:=PointAD(RelAngle2D(Obj.Center,FloatPoint(point(X,Y))),RelDistK(Obj.Center,Fl oatPoint(point(X,Y)),Obj.Size.X)); end; end; // if dot=0 then if EnMoving then Obj.Center:=AddPoints(Obj.Center,Point2D(MP.X-X,Mp.YY)); end else begin dot:=Obj.Entry(point(X,Y)); end; end; {Centering*******************************************************************} {Moving komutu islevini yapyor**********************************************} if (ssRight in shift)and(Obj.Entry(point(X,Y))=0) then begin Obj.Center:=AddPoints(FloatPoint(CP),Point2D(X,Y)); end; {Rotate komutu islevini yapyor**********************************************} if EnRotate then begin if (ssleft in shift)and(Obj.Entry(point(X,Y))=0) then 32

Obj.CurP:=PointAD(RelAngle2D(AddPoints(Obj.Center,Move2D(Obj.curc.A,Obj.curc.D,Obj.S ize)),Point2D(X,Y)),0); end; end; procedure TFObject.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key = 107 then FMain.mnZoonInClick(self); if key = 109 then FMain.mnZoomOutClick(self); end; procedure TFObject.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); begin if WheelDelta<0 then Obj.Size:=Point2D(Obj.Size.X-1,Obj.Size.Y-1) else Obj.Size:=Point2D(Obj.Size.X+1,Obj.Size.Y+1); end; procedure TFObject.FormActivate(Sender: TObject); var Win:TComponent; begin try Win:=Application.FindComponent(FMain.Objects[FMain.ObjectIndex].Name); if Win<>nil then TFObject(Win).Motor.playing:=false; except end; FMain.ObjectIndex:=ObjectNo; Motor.Playing:=true; toolLayers.ObjRefresh; toolMode.ObjRefresh; end; procedure TFObject.StatusClick(Sender: TObject); begin Obj.CurIndex:=Obj.CurIndex-1; end; procedure TFObject.FormClose(Sender: TObject; var Action: TCloseAction); var R:byte; begin if Saved then begin FMain.DestroyObject(Name); end else begin R:=MessageDlg('Save Model Named '+Caption,mtConfirmation,mbYesNoCancel,0); IF r=6 THEN begin FMain.SaveDialog.Title:='Save Model As'; FMain.SaveDialog.DefaultExt:='*.gmd'; 33

FMain.SaveDialog.InitialDir:=GetCurrentDir+'\Models'; if FMain.SaveDialog.Execute then begin Obj.Save(FMain.SaveDialog.FileName); FMain.DestroyObject(Name); end else begin Action:=caNone; Exit; end; end; if R=7 then begin FMain.DestroyObject(Name); end; IF R=2 then begin Action:=caNone; Exit; end; end; toolLayers.ObjRefresh; toolMode.ObjRefresh; end; procedure TFObject.NewLayer; var X,Y:integer; begin X:=round(obj.Center.X); Y:=round(obj.Center.Y); obj.AddLayer(CreateUnit('Layer '+inttostr(FMain.CurrentObj.Obj.UnitCount+1), PointAD(RelAngle2D(Obj.Center,FloatPoint(point(0,0))),RelDistK(Obj.Center,FloatPoint(point(0 ,0)),Obj.Size.X)), PointAD(RelAngle2D(Obj.Center,FloatPoint(point(X-50,Y50))),RelDistK(Obj.Center,FloatPoint(point(X-50,Y-50)),Obj.Size.X)), PointAD(RelAngle2D(Obj.Center,FloatPoint(point(X-20,Y20))),RelDistK(Obj.Center,FloatPoint(point(X-20,Y-20)),Obj.Size.X)), PointAD(RelAngle2D(Obj.Center,FloatPoint(point(X+20,Y+20))),RelDistK(Obj.Center,FloatPoin t(point(X+20,Y+20)),Obj.Size.X)), PointAD(RelAngle2D(Obj.Center,FloatPoint(point(X+50,Y+50))),RelDistK(Obj.Center,FloatPoin t(point(X+50,Y+50)),Obj.Size.X)), toolMode.CurMode,toolMode.CurCl,toolMode.CurBkCl,toolMode.CutWD)); end; procedure TFObject.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin CP:=RoundPoint(SubPoints(Obj.Center,Point2D(X,Y))); end; end.

34

unit UAbout; interface uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, Buttons, ExtCtrls, jpeg; type TAboutBox = class(TForm) Label1: TLabel; Label3: TLabel; Label2: TLabel; Label4: TLabel; procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private { Private declarations } public { Public declarations } end; var AboutBox: TAboutBox; implementation uses UMain, UFormObject, UUnitMode; {$R *.dfm} procedure TAboutBox.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=27 then begin Aboutbox.Hide; Fmain.show; end; end; end. unit UGraphDriver; interface uses Windows, {SysUtils,} Classes, Graphics, Controls, ExtCtrls, Dialogs; const n_MAXPROC = 50; 35

type TID_Process =0..n_MAXPROC; TGraphProcess = procedure (DC:TCanvas;ID: TID_Process) of object; TGraphDriver = class(TComponent) private DC:TCanvas; FBkCl: TColor; FTimer:TTimer; FCount: TID_Process; FOnBeforeDraw: TGraphProcess; FOnafterDraw: TGraphProcess; FDisplayRect: TRect; FDisplayHwnd: THandle; function GetHt: integer; function GetWD: integer; procedure SetHt(const Value: integer); procedure SetWD(const Value: integer); procedure SetDisplayHwnd(const Value: THandle); protected FProcesses:array[0..n_MAXPROC]of TGraphProcess; function GetProcesses(Index: TID_Process): TGraphProcess; virtual; function GetPlay: boolean; virtual; procedure SetPlay(const Value: boolean); virtual; procedure SetDisplayRect(const Value: TRect); virtual; procedure DrawProcesses(Sender:TObject); virtual; public BMP:TBitmap; constructor Create(AOwner: TComponent); override; destructor Destroy; override; function AddProcess(Process:TGraphProcess):TID_Process; virtual; function DeleteProcess(Process:TGraphProcess):boolean; overload; virtual; function DeleteProcess(ID_Process:TID_Process):boolean; overload; virtual; procedure ReDraw; property Processes[Index:TID_Process]:TGraphProcess read GetProcesses; property ProcessCount:TID_Process read FCount; property BackColor:TColor read FBkCl write FBkCl; property Playing:boolean read GetPlay write SetPlay; property OnBeforeDraw:TGraphProcess read FOnBeforeDraw write FOnBeforeDraw; property OnAfterDraw:TGraphProcess read FOnafterDraw write FOnafterDraw; property DisplayHandle:THandle read FDisplayHwnd write SetDisplayHwnd; property DisplayRect:TRect read FDisplayRect write SetDisplayRect; property Width:integer read GetWD write SetWD; property Height:integer read GetHt write SetHt; end;

36

{ModelmakeringUnit} TPoint2D = record X, Y: Real; end; TPoint3D = record X, Y, Z: Real; end; TPointAD = record A,D:real; end; TGraphUnitMode = (umNone,umLine,umPolygon,umPolyline,umPolyBizier,umEllipse,umRoundRect,umArc,umChor d,umFrameRect,umFillRect,umFloodFill); TGraphUnit = record p1,p2,p3,p4,P,C:TPointAD; Mode:TGraphUnitMode; Cl,BkCL:TColor; WD:word; En:boolean; Name:string[30]; end; TGraphObject = class(TComponent) private FSize: TPoint2D; FCenter: TPoint2D; FCurIndex: integer; FDelta: byte; FFileName: string; FAngle: TPointAD; function GetCount: integer; procedure SetCount(const Value: integer); procedure SetSize(const Value: TPoint2D); procedure SetCenter(const Value: TPoint2D); function GetCurUn:TGraphUnit; function GetRect: TRect; procedure SetCurUn(const Value: TGraphUnit); function GetUnitEn(Index: integer): boolean; procedure SetUnitEn(Index: integer; const Value: boolean); function GetCurP1: TPointAD; procedure SetCurP1(const Value: TPointAD); function GetCurP2: TPointAD; procedure SetCurP2(const Value: TPointAD); function GetCurP3: TPointAD; procedure SetCurP3(const Value: TPointAD); function GetCurP4: TPointAD; 37

procedure SetCurP4(const Value: TPointAD); function GetMode: TGraphUnitMode; procedure SetMode(const Value: TGraphUnitMode); function GetWD: Word; procedure SetWD(const Value: Word); function GetBkCl: TColor; function GetCl: TColor; procedure SetBkCl(const Value: TColor); procedure SetCl(const Value: TColor); function Getname: string; procedure setUnName(const Value: string); function GetP: TPointAD; procedure SetP(const Value: TPointAD); function GetC: TPointAD; procedure SetC(const Value: TPointAD); protected Units:array of TGraphUnit; FFile:file of TGraphUnit; procedure DrawUnit(DC:TCanvas;Un:TGraphUnit); public procedure Load(FileName:TCaption); procedure Save(FileName:TCaption); procedure Draw(DC:TCanvas); function AddLayer(Un:TGraphUnit):Integer; function DeleteLayer(Index:integer):boolean; function ReplaceLayers(L1,L2:integer):boolean; function Entry(P:TPoint):byte; function EntryCenter(var P:TPoint):boolean; function UnitEnable:boolean; property FileName:string read FFileName; property UnitCount:integer read GetCount write SetCount; property CurIndex:integer read FCurIndex write FCurIndex; property CurUnit:TGraphUnit read GetCurUn write SetCurUn; property CurP:TPointAD read GetP write SetP; property CurC:TPointAD read GetC write SetC; property CurP1:TPointAD read GetCurP1 write SetCurP1; property CurP2:TPointAD read GetCurP2 write SetCurP2; property CurP3:TPointAD read GetCurP3 write SetCurP3; property CurP4:TPointAD read GetCurP4 write SetCurP4; property CurMode:TGraphUnitMode read GetMode write SetMode; property CurWD:Word read GetWD write SetWD; property CurCl:TColor read GetCl write SetCl; property CurBkCl:TColor read GetBkCl write SetBkCl; property CurName:string read Getname write setUnName; property UnitEn[Index:integer]:boolean read GetUnitEn write SetUnitEn; property Size:TPoint2D read FSize write SetSize; property Center:TPoint2D read FCenter write SetCenter; property Angle:TPointAD read FAngle write FAngle; 38

property ClipRect:TRect read GetRect; property Delta:byte read FDelta write FDelta; constructor Create(AOwner: TComponent); override; end; function CreateUnit(Name:string;P,P1,P2,P3,P4:TPointAD; Mode:TGraphUnitMode;Cl,BkCl:TColor;WD:byte):TGraphUnit; function Point2D(X, Y: Real): TPoint2D; function PointAD(A, D: Real): TPointAD; function RoundPoint(P: TPoint2D): TPoint; function FloatPoint(P: TPoint): TPoint2D; function Point3D(X, Y, Z: Real): TPoint3D; function Angle2D(P: TPoint2D): Real; function Dist2D(P: TPoint2D): Real; function Dist3D(P: TPoint3D): Real; function RelAngle2D(PA, PB: TPoint2D): Real; //function RelDist2D(PA, PB: TPoint2D): Real; function RelDistK(PA, PB: TPoint2D; Radius:real): Real; function RelDist3D(PA, PB: TPoint3D): Real; procedure Rotate2D(var P: TPoint2D; Angle2D: Real); procedure RelRotate2D(var P: TPoint2D; PCentr: TPoint2D; Angle2D: Real); function Move2D(Angle2D, Distance: Real; Size:TPoint2D):TPoint2D; function MoveAng(P: TPoint2D; Angle2D, Distance: Real):TPoint2D; function MoveKAng(P: TPoint2D; Angle2D, Distance: Real; Size:TPoint2D):TPoint2D; function Between(PA, PB: TPoint2D; Preference: Real): TPoint2D; function DistLine(A, B, C: Real; P: TPoint2D): Real; function Dist2P(P, P1, P2: TPoint2D): Real; function DistD1P(DX, DY: Real; P1, P: TPoint2D): Real; function NearLine2P(P, P1, P2: TPoint2D; D: Real): Boolean; function AddPoints(P1, P2: TPoint2D): TPoint2D; overload; function AddPoints(P1, P2: TPoint): TPoint; overload; function AddPointsAD(P1, P2: TPointAD): TPointAD; function SubPoints(P1, P2: TPoint2D): TPoint2D; overload; function SubPoints(P1, P2: TPoint): TPoint; overload; function Invert(Col: TColor): TColor; function Dark(Col: TColor; Percentage: Byte): TColor; function Light(Col: TColor; Percentage: Byte): TColor; function Mix(Col1, Col2: TColor; Percentage: Byte): TColor; function MMix(Cols: array of TColor): TColor; function Log(Base, Value: Real): Real; function Modulator(Val, Max: Real): Real; function M(I, J: Integer): Integer; function Tan(Angle2D: Real): Real; function Exp2(Exponent: Byte): Word; function ModeToInt(Un:TGraphUnitMode):byte; function IntToMode(Int:byte):TGraphUnitMode; 39

implementation uses Types, SysUtils;

function ModeToInt(Un:TGraphUnitMode):byte; begin case Un of umNone:Result:=0; umLine:Result:=1; umPolygon:Result:=2; umPolyline:Result:=3; umPolyBizier:Result:=4; umEllipse:Result:=5; umRoundRect:Result:=6; umArc:Result:=7; umChord:Result:=8; umFrameRect:Result:=9; umFillRect:Result:=10; umFloodFill:Result:=11; else Result:=127; end; end; function IntToMode(Int:byte):TGraphUnitMode; begin case Int of 0:Result:=umNone; 1:Result:=umLine; 2:Result:=umPolygon; 3:Result:=umPolyline; 4:Result:=umPolyBizier; 5:Result:=umEllipse; 6:Result:=umRoundRect; 7:Result:=umArc; 8:Result:=umChord; 9:Result:=umFrameRect; 10:Result:=umFillRect; 11:Result:=umFloodFill; else Result:=umNone; end; end; { TGraphDriver } function TGraphDriver.AddProcess(Process:TGraphProcess):TID_Process; var I:TID_Process; begin 40

for I:=0 to n_MAXPROC do begin if not Assigned(FProcesses[i]) then begin FProcesses[i]:=Process; Result:=I; Exit; end; Result:=0; end; end; constructor TGraphDriver.Create(AOwner: TComponent); begin inherited; bmp:=TBitmap.Create; DC:=TCanvas.Create; FTimer:=TTimer.Create(SELF); FTimer.Interval:=20; FTimer.Enabled:=FALSE; FTimer.OnTimer:=DrawProcesses; FCount:=0; FBkCl:=clblack; end; function TGraphDriver.DeleteProcess(Process: TGraphProcess): boolean; var I:TID_Process; begin for I:= 0 to n_MAXPROC do begin if @FProcesses[I]=@Process then begin FProcesses[I]:=nil; Result:=true; exit; end; Result:=false; end; end; function TGraphDriver.DeleteProcess(ID_Process: TID_Process): boolean; begin if Assigned(FProcesses[ID_Process]) then begin FProcesses[ID_Process]:=nil; Result:=true; end else begin Result:=false; end; end; 41

destructor TGraphDriver.Destroy; begin BMp.Free; if DC.HandleAllocated then ReleaseDC(FDisplayHwnd,DC.Handle); DC.Free; inherited; end; procedure TGraphDriver.DrawProcesses(Sender: TObject); var I:TID_Process; begin {Before Draw Processes} if Assigned(FOnBeforeDraw) then begin FOnBeforeDraw(BMP.Canvas,n_MAXPROC); end else begin BMP.Canvas.Brush.Color:=FBkCl; BMP.Canvas.FillRect(BMP.Canvas.ClipRect); end; {Draw Processes} For I:=0 To n_MAXPROC do begin if Assigned(Processes[I]) then FProcesses[I](BMP.Canvas,I); end; {After Draw Processes} if Assigned(FOnAfterDraw) then begin FOnafterDraw(BMP.Canvas,n_MAXPROC); end; ReDraw; end; function TGraphDriver.GetHt: integer; begin Result:=BMp.Height; end; function TGraphDriver.GetPlay: boolean; begin Result:=FTimer.Enabled; end; function TGraphDriver.GetProcesses(Index: TID_Process): TGraphProcess; begin Result:=FProcesses[Index]; end; 42

function TGraphDriver.GetWD: integer; begin Result:=BMp.Width; end; procedure TGraphDriver.ReDraw; begin DC.Draw(FDisplayRect.Left,FDisplayRect.Top,BMP); end; procedure TGraphDriver.SetDisplayHwnd(const Value: THandle); var R:Trect; begin FDisplayHwnd := Value; DC.Handle:=GetDC(Value); GetWindowRect(Value,R); BMP.Width:=R.Right-R.Left; BMP.Height:=R.Bottom-R.Top; FDisplayRect:=DC.ClipRect; end; procedure TGraphDriver.SetDisplayRect(const Value: TRect); begin FDisplayRect := Value; if BMP<>nil then begin BMP.Width:=(Value.Right-Value.Left); BMP.Height:=(Value.Bottom-Value.Top); end; end; procedure TGraphDriver.SetHt(const Value: integer); begin Bmp.Height:=Value; end; procedure TGraphDriver.SetPlay(const Value: boolean); begin FTimer.Enabled:=Value; end;

procedure TGraphDriver.SetWD(const Value: integer); begin bmp.Width:=Value; end; 43

{ TGraphObject } function CreateUnit(Name:string;P,P1,P2,P3,P4:TPointAD; Mode:TGraphUnitMode;Cl,BkCl:TColor;WD:byte):TGraphUnit; begin Result.P:=PointAD(0,0); Result.C:=PointAD(0,0); Result.p1:=P1; Result.p2:=P2; Result.p3:=P3; Result.p4:=P4; Result.Mode:=Mode; Result.Cl:=Cl; Result.BkCL:=BkCl; Result.WD:=WD; Result.En:=true; Result.Name:=Name; end; function TGraphObject.AddLayer(Un: TGraphUnit): Integer; begin FCurIndex:=length(Units); setlength(Units,FCurIndex+1); Units[CurIndex]:=Un; Result:=CurIndex; end; constructor TGraphObject.Create(AOwner: TComponent); begin inherited; FDelta:=5; FAngle.A:=0; FAngle.D:=0; end; function TGraphObject.ReplaceLayers(L1, L2: integer): boolean; var Un:TGraphUnit; begin if (UnitCount=0)or(L1>UnitCount)or(L2>UnitCount) then exit; Un:=Units[L1]; Units[L1]:=Units[L2]; Units[L2]:=Un; Result:=true; end; function TGraphObject.DeleteLayer(Index: integer): boolean; var I:integer; begin if UnitCount>0 then 44

for I:= Index+1 to UnitCount-1 do begin Units[i-1]:=Units[i]; end; SetLength(Units,UnitCount-1); Result:=true; end; procedure TGraphObject.Draw(DC: TCanvas); var I,L:Integer; begin L:=UnitCount; if L=0 then exit; For I:= 0 to L-1 do begin if Units[I].En then DrawUnit(DC,Units[I]); end; end; procedure TGraphObject.DrawUnit(DC: TCanvas; Un: TGraphUnit); var P1,P2,P3,P4:TPoint; C:TPoint2D; TP:TPointAD; begin C:=addpoints(FCenter,Move2d(Un.C.A+FAngle.A,Un.C.D-FAngle.D,FSize)); TP.A:=Un.P.A+FAngle.A; TP.D:=un.P.D+FAngle.D; P1:=RoundPoint(MoveKAng(C,Un.p1.A+TP.A,Un.p1.D+TP.D,FSize)); P2:=RoundPoint(MoveKAng(C,Un.p2.A+TP.A,Un.p2.D+TP.D,FSize)); P3:=RoundPoint(MoveKAng(C,Un.p3.A+TP.A,Un.p3.D+TP.D,FSize)); P4:=RoundPoint(MoveKAng(C,Un.p4.A+TP.A,Un.p4.D+TP.D,FSize)); { P1:=RoundPoint(MoveKAng(addpoints(FCenter,Move2d(Un.C.A+FAngle.A,Un.C.D+FAngle.D, FSize)),Un.p1.A+Un.P.A+FAngle.A,Un.p1.D+un.P.D+FAngle.D,FSize)); P2:=RoundPoint(MoveKAng(addpoints(FCenter,Move2d(Un.C.A+FAngle.A,Un.C.D+FAngle.D, FSize)),Un.p2.A+Un.P.A+FAngle.A,Un.p2.D+un.P.D+FAngle.D,FSize)); P3:=RoundPoint(MoveKAng(addpoints(FCenter,Move2d(Un.C.A+FAngle.A,Un.C.D+FAngle.D, FSize)),Un.p3.A+Un.P.A+FAngle.A,Un.p3.D+un.P.D+FAngle.D,FSize)); P4:=RoundPoint(MoveKAng(addpoints(FCenter,Move2d(Un.C.A+FAngle.A,Un.C.D+FAngle.D, FSize)),Un.p4.A+Un.P.A+FAngle.A,Un.p4.D+un.P.D+FAngle.D,FSize));} WITH DC DO BEGIN Pen.Width:=un.WD; Pen.Color:=un.Cl; Brush.Color:=un.BkCL; case un.Mode of umNone:exit; umLine:begin MoveTo(P1.X,P1.Y); LineTo(P2.X,P2.Y); end; umPolygon:begin 45

Polygon([P1,P2,P3,P4]); end; umPolyline:begin Polyline([P1,P2,P3,P4]); end; umPolyBizier:begin PolyBezier([P1,P2,P3,P4]); end; umEllipse:begin Ellipse(P1.X,P1.Y,P2.X,P2.Y); end; umRoundRect:begin RoundRect(P1.X,P1.Y,P2.X,P2.Y,P3.X,P3.Y); end; umArc:begin Arc(P1.X,P1.Y,P2.X,P2.Y,P3.X,P3.Y,P4.X,P4.Y); end; umChord:begin Chord(P1.X,P1.Y,P2.X,P2.Y,P3.X,P3.Y,P4.X,P4.Y); end; umFrameRect:begin FrameRect(rect(P1.X,P1.Y,P2.X,P2.Y)); end; umFillRect:begin FillRect(rect(P1.X,P1.Y,P2.X,P2.Y)); end; umFloodFill:begin FloodFill(P1.X,P1.Y,un.Cl,fsBorder); end; end; END; end; function TGraphObject.Entry(P: TPoint): byte; var C:TPoint2D; begin if UnitCount=0 then begin Result:=0; exit; end; C:=MoveKAng(AddPoints(FCenter,Move2D(CurC.A,CurC.D,FSize)),CurUnit.p1.A+CurP.A,C urUnit.p1.D+CurP.D,FSize); if (P.X>C.X-FDelta)and(P.X<C.X+FDelta)and(P.Y>C.Y-FDelta)and(P.Y<C.Y+FDelta)then Result:=1 else begin C:=MoveKAng(AddPoints(FCenter,Move2D(CurC.A,CurC.D,FSize)),CurUnit.p2.A+CurP.A, CurUnit.p2.D+CurP.D,FSize); if (P.X>C.X-FDelta)and(P.X<C.X+FDelta)and(P.Y>C.Y-FDelta)and(P.Y<C.Y+FDelta)then Result:=2 else begin 46

C:=MoveKAng(AddPoints(FCenter,Move2D(CurC.A,CurC.D,FSize)),CurUnit.p3.A+CurP.A, CurUnit.p3.D+CurP.D,FSize); if (P.X>C.X-FDelta)and(P.X<C.X+FDelta)and(P.Y>C.Y-FDelta)and(P.Y<C.Y+FDelta)then Result:=3 else begin C:=MoveKAng(AddPoints(FCenter,Move2D(CurC.A,CurC.D,FSize)),CurUnit.p4.A+CurP. A,CurUnit.p4.D+CurP.D,FSize); if (P.X>C.X-FDelta)and(P.X<C.X+FDelta)and(P.Y>C.Y-FDelta)and(P.Y<C.Y+FDelta)then Result:=4 else Result:=0; end; end; end; end; function TGraphObject.EntryCenter(var P: TPoint):boolean; var C:TPoint2D; begin if UnitEnable then begin C:=MoveKAng(FCenter,CurUnit.C.A,CurUnit.C.D,FSize); if (P.X>C.X-FDelta)and(P.X<C.X+FDelta)and(P.Y>C.Y-FDelta)and(P.Y<C.Y+FDelta)then Result:=true else Result:=false; end else Result:=false; P:=roundpoint(C); end; function TGraphObject.GetCount: integer; begin Result:=length(Units); end; function TGraphObject.GetCurUn:TGraphUnit; begin if UnitCount<>0 then Result:=Units[FCurIndex]; end; function TGraphObject.GetRect: TRect; begin Result.Left:=round(FCenter.X-FSize.X); Result.Right:=round(FCenter.X+FSize.X); Result.Top:=round(FCenter.Y-FSize.Y); Result.Bottom:=round(FCenter.Y+FSize.Y); end; function TGraphObject.GetUnitEn(Index: integer): boolean; begin Result:=Units[Index].En; end; procedure TGraphObject.SetUnitEn(Index: integer; const Value: boolean); 47

begin Units[index].En:=Value; end; procedure TGraphObject.Load(FileName: TCaption); var I,L:integer; Un:TGraphUnit; begin try AssignFile(FFile,FileName); FFileName:=FileName; reset(FFile); L:=filesize(FFile); SetLength(Units,L); for I:=0 to L-1 do begin read(FFile,Un); Units[I]:=Un; end; CloseFile(FFile); except FileName:=''; end; end; procedure TGraphObject.Save(FileName: TCaption); var I:integer; Un:TGraphUnit; begin try AssignFile(FFile,FileName); Rewrite(FFile); for I:= 0 to UnitCount-1 do begin Un:=Units[I]; write(FFile,Un); end; except end; CloseFile(FFile); end; function TGraphObject.UnitEnable: boolean; begin Result:=UnitCount>0; end; procedure TGraphObject.SetCenter(const Value: TPoint2D); begin FCenter := Value; end; 48

procedure TGraphObject.SetCount(const Value: integer); begin setlength(Units,Value); end; procedure TGraphObject.SetCurUn(const Value: TGraphUnit); begin Units[FCurIndex]:=Value; end; procedure TGraphObject.SetSize(const Value: TPoint2D); begin FSize := Value; end; function TGraphObject.GetCurP1: TPointAD; begin Result:=Units[FCurIndex].P1; end; procedure TGraphObject.SetCurP1(const Value: TPointAD); begin Units[FCurIndex].p1:=Value; end; function TGraphObject.GetCurP2: TPointAD; begin Result:=Units[FCurIndex].P2; end; procedure TGraphObject.SetCurP2(const Value: TPointAD); begin Units[FCurIndex].p2:=Value; end; function TGraphObject.GetCurP3: TPointAD; begin Result:=Units[FCurIndex].P3; end; procedure TGraphObject.SetCurP3(const Value: TPointAD); begin Units[FCurIndex].p3:=Value; end; function TGraphObject.GetCurP4: TPointAD; begin Result:=Units[FCurIndex].P4; end; 49

procedure TGraphObject.SetCurP4(const Value: TPointAD); begin Units[FCurIndex].p4:=Value; end; function TGraphObject.GetMode: TGraphUnitMode; begin Result:=Units[FCurIndex].Mode; end; procedure TGraphObject.SetMode(const Value: TGraphUnitMode); begin if UnitCount>0 then Units[FCurIndex].Mode:=Value; end; function TGraphObject.GetWD: Word; begin Result:=Units[CurIndex].WD; end; procedure TGraphObject.SetWD(const Value: Word); begin Units[CurIndex].WD:=Value; end; function TGraphObject.GetBkCl: TColor; begin Result:=Units[Curindex].BkCL; end; function TGraphObject.GetCl: TColor; begin Result:=Units[Curindex].CL; end; procedure TGraphObject.SetBkCl(const Value: TColor); begin Units[Curindex].BkCL:=Value; end; procedure TGraphObject.SetCl(const Value: TColor); begin Units[Curindex].CL:=Value; end; function TGraphObject.Getname: string; begin 50

Result:=Units[CurIndex].Name; end; procedure TGraphObject.setUnName(const Value: string); begin Units[CurIndex].Name:=Value; end; function TGraphObject.GetP: TPointAD; begin Result:=Units[FCurIndex].P; end; procedure TGraphObject.SetP(const Value: TPointAD); begin Units[Curindex].P:=Value; end; function TGraphObject.GetC: TPointAD; begin Result:=Units[CurIndex].C; end; procedure TGraphObject.SetC(const Value: TPointAD); begin Units[CurIndex].C:=Value; end; {****************************************************************************** *} {*********FUNCTION' lar*********************************************************} {*********FUNCTION' lar*********************************************************} {****************************************************************************** *} function Point2D(X, Y: Real): TPoint2D; begin Point2D.X := X; Point2D.Y := Y; end; function PointAD(A, D: Real): TPointAD; begin Result.A:=A; Result.D:=D; end; function RoundPoint(P: TPoint2D): TPoint; begin 51

RoundPoint.X := Round(P.X); RoundPoint.Y := Round(P.Y); end; function FloatPoint(P: TPoint): TPoint2D; begin FloatPoint.X := P.X; FloatPoint.Y := P.Y; end; function Point3D(X, Y, Z: Real): TPoint3D; begin Point3D.X := X; Point3D.Y := Y; Point3D.Z := Z; end; function Angle2D(P: TPoint2D): Real; begin if P.X = 0 then begin if P.Y > 0 then Result := Pi / 2; if P.Y = 0 then Result := 0; if P.Y < 0 then Result := Pi / -2; end else Result := Arctan(P.Y / P.X); if P.X < 0 then begin if P.Y < 0 then Result := Result + Pi; if P.Y >= 0 then Result := Result - Pi; end; If Result < 0 then Result := Result + 2 * Pi; end; function Dist2D(P: TPoint2D): Real; begin Result := Sqrt(P.X * P.X + P.Y * P.Y); end; function Dist3D(P: TPoint3D): Real; 52

begin Dist3d := Sqrt(P.X * P.X + P.Y * P.Y + P.Z * P.Z); end; function RelAngle2D(PA, PB: TPoint2D): Real; begin RelAngle2D := Angle2D(Point2D(PB.X - PA.X, PB.Y - PA.Y)); end; function RelDist2D(PA, PB: TPoint2D): Real; begin Result := Dist2D(Point2D(PB.X - PA.X, PB.Y - PA.Y)); end; function RelDistK(PA, PB: TPoint2D;Radius:real): Real; begin Result := Dist2D(Point2D(PB.X - PA.X, PB.Y - PA.Y))/Radius; end; function RelDist3D(PA, PB: TPoint3D): Real; begin RelDist3D := Dist3D(Point3D(PB.X - PA.X, PB.Y - PA.Y, PB.Z - PA.Z)); end; procedure Rotate2D(var P: TPoint2D; Angle2D: Real); var Temp: TPoint2D; begin Temp.X := P.X * Cos(Angle2D) - P.Y * Sin(Angle2D); Temp.Y := P.X * Sin(Angle2D) + P.Y * Cos(Angle2D); P := Temp; end; procedure RelRotate2D(var P: TPoint2D; PCentr: TPoint2D; Angle2D: Real); var Temp: TPoint2D; begin Temp := SubPoints(P, PCentr); Rotate2D(Temp, Angle2D); P := AddPoints(Temp, PCentr); end; 53

function Move2D(Angle2D, Distance: Real; Size:TPoint2D):TPoint2D; var Temp: TPoint2D; begin Temp.X := (Cos(Angle2D) * Distance*Size.X); Temp.Y := (Sin(Angle2D) * Distance*Size.Y); Result := Temp; end; function MoveAng(P: TPoint2D; Angle2D, Distance: Real):TPoint2D; var Temp: TPoint2D; begin Temp.X := P.X + (Cos(Angle2D) * Distance); Temp.Y := P.Y + (Sin(Angle2D) * Distance); Result := Temp; end; function MoveKAng(P: TPoint2D; Angle2D, Distance: Real; Size:TPoint2D):TPoint2D; var Temp: TPoint2D; begin Temp.X := P.X + (Cos(Angle2D) * Size.X*Distance); Temp.Y := P.Y + (Sin(Angle2D) * Size.Y*Distance); Result := Temp; end; function Between(PA, PB: TPoint2D; Preference: Real): TPoint2D; begin Between.X := PA.X * Preference + PB.X * (1 - Preference); Between.Y := PA.Y * Preference + PB.Y * (1 - Preference); end; function DistLine(A, B, C: Real; P: TPoint2D): Real; begin Result := (A * P.X + B * P.Y + C) / Sqrt(Sqr(A) + Sqr(B)); end; function Dist2P(P, P1, P2: TPoint2D): Real; begin Result := DistLine(P1.Y - P2.Y, P2.X - P1.X, -P1.Y * P2.X + P1.X * P2.Y, P); end; 54

function DistD1P(DX, DY: Real; P1, P: TPoint2D): Real; begin Result := DistLine(DY, -DX, -DY * P1.X + DX * P1.Y, P); end; function NearLine2P(P, P1, P2: TPoint2D; D: Real): Boolean; begin Result := False; if DistD1P(-(P2.Y - P1.Y), P2.X - P1.X, P1, P) * DistD1P(-(P2.Y - P1.Y), P2.X - P1.X, P2, P) <= 0 then if Abs(Dist2P(P, P1, P2)) < D then Result := True; end; function AddPoints(P1, P2: TPoint2D): TPoint2D;overload; begin AddPoints := Point2D(P1.X + P2.X, P1.Y + P2.Y); end; function AddPoints(P1, P2: TPoint): TPoint;overload; begin Result:=Point(P1.X+P2.X,P1.Y+P2.Y); end; function AddPointsAD(P1, P2: TPointAD): TPointAD; begin Result:=PointAD(P1.A+P2.A,P1.D+P2.D); end; function SubPoints(P1, P2: TPoint2D): TPoint2D;overload; begin SubPoints := Point2D(P1.X - P2.X, P1.Y - P2.Y); end; function SubPoints(P1, P2: TPoint): TPoint;overload; begin Result:=Point(P1.X-P2.X,P1.Y-P2.Y); end; function Invert(Col: TColor): TColor; begin Invert := not Col; end; function Dark(Col: TColor; Percentage: Byte): TColor; var R, G, B: Byte; 55

begin R := GetRValue(Col); G := GetGValue(Col); B := GetBValue(Col); R := Round(R * Percentage / 100); G := Round(G * Percentage / 100); B := Round(B * Percentage / 100); Dark := RGB(R, G, B); end; function Light(Col: TColor; Percentage: Byte): TColor; var R, G, B: Byte; begin R := GetRValue(Col); G := GetGValue(Col); B := GetBValue(Col); R := Round(R * Percentage / 100) + Round(255 - Percentage / 100 * 255); G := Round(G * Percentage / 100) + Round(255 - Percentage / 100 * 255); B := Round(B * Percentage / 100) + Round(255 - Percentage / 100 * 255); Light := RGB(R, G, B); end; function Mix(Col1, Col2: TColor; Percentage: Byte): TColor; var R, G, B: Byte; begin R := Round((GetRValue(Col1) * Percentage / 100) + (GetRValue(Col2) * (100 - Percentage) / 100)); G := Round((GetGValue(Col1) * Percentage / 100) + (GetGValue(Col2) * (100 - Percentage) / 100)); B := Round((GetBValue(Col1) * Percentage / 100) + (GetBValue(Col2) * (100 - Percentage) / 100)); Mix := RGB(R, G, B); end; function MMix(Cols: array of TColor): TColor; var I, R, G, B, Length: Integer; begin Length := High(Cols) - Low(Cols) + 1; R := 0; G := 0; B := 0; for I := Low(Cols) to High(Cols) do begin R := R + GetRValue(Cols[I]); G := G + GetGValue(Cols[I]); 56

B := B + GetBValue(Cols[I]); end; R := R div Length; G := G div Length; B := B div Length; MMix := RGB(R, G, B); end; function Log(Base, Value: Real): Real; begin Log := Ln(Value) / Ln(Base); end; function Power(Base, Exponent: Real): Real; begin Power := Ln(Base) * Exp(Exponent); end; function Modulator(Val, Max: Real): Real; begin Modulator := (Val / Max - Round(Val / Max)) * Max; end; function M(I, J: Integer): Integer; begin M := ((I mod J) + J) mod J; end; function Tan(Angle2D: Real): Real; begin Tan := Sin(Angle2D) / Cos(Angle2D); end; procedure Limit(var Value: Integer; Min, Max: Integer); begin if Value < Min then Value := Min; if Value > Max then Value := Max; end; function Exp2(Exponent: Byte): Word; var Temp, I: Word; begin Temp := 1; for I := 1 to Exponent do 57

Temp := Temp * 2; Result := Temp; end; end.

V. List of the used literature

1.
1. 2. 3. 4. 5.

Literature:
Programming in Delphi 7 (Yakovlevich A.A.) Delphi UNLEASHED (Charles Calvert) Informatics (Henner E.K) Publish/,, ( Publishers "Opened Systems") Algorithms and structure data (Niclaus Virt)
58

6. 7.

Level Graphics. Raster and vector graphics (Karabin P.) Vector Graphics (Kovtanyuk U.)

2.
1. 2. 3. 4. 5. 6. 7. 8.

Electronic sources:
http://algolist.manual.ru http://osp.asu.pstu.ac.ru/publish/1997/04/34.htm http://win-www.klax.tula.ru/~level/graphics/predgrph.html http://secrail.h1.ru/progdoc/pgpvsgpg.htm http://www.geocities.com/werebad/art1999/models.htm http://abc.ru/graph/155a http://imped.vgts.ru/polygraph/vektor.html http://www.ascon.ru/kompas/vect.html

59