home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-14 | 1.9 KB | 85 lines | [TEXT/MWPS] |
- program HexGrid;
-
- {$IFC UNDEFINED THINK_PASCAL}
- uses Types, QuickDraw, Fonts, Events, Packages, Menus, Dialogs, Windows,{}
- OSUtils, ToolUtils;
- {$ENDC}
-
-
- const
- (*Size of the array*)
- kArraySizeH = 10;
- kArraySizeV = 8;
-
- var
- (* Pictures*)
- hexTile: PicHandle;
-
- const
- (* Define constants that match our hexes *)
- kHorizontalSpacing = 32;
- kVerticalSpacing = 26;
-
- (* Draw a tile *)
-
- procedure DrawHexTile (h: Integer; v: Integer);
- var
- tileRectangle: Rect;
- (* Use the picture frame *)
- begin
- tileRectangle := hexTile^^.picFrame;
- (* Move it to 0,0 *)
- OffsetRect(tileRectangle, -tileRectangle.left, -tileRectangle.top);
- (* Offset to the proper position *)
- (* For every other line, offset a bit extra *)
- if BitAnd(v, 1) = 0 then
- OffsetRect(tileRectangle, kHorizontalSpacing * h, kVerticalSpacing * v)
- else
- OffsetRect(tileRectangle, kHorizontalSpacing * h + kHorizontalSpacing div 2, kVerticalSpacing * v);
- (* Draw it *)
- DrawPicture(hexTile, tileRectangle);
- end; (*DrawHexTile*)
-
-
- (* Standard inits *)
-
- procedure InitToolbox;
- begin
- {$IFC UNDEFINED THINK_PASCAL}
- InitGraf(@qd.thePort);
- InitFonts;
- FlushEvents(everyEvent, 0);
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- {$ENDC}
- InitCursor;
- end;
-
- (****************** Main program ******************)
-
- var
- myWindow: WindowPtr;
- windowRectangle: Rect;
- h, v: Integer;
-
- begin
- InitToolbox;
-
- (*Set up the window*)
- SetRect(windowRectangle, 50, 50, 50 + kArraySizeH * kHorizontalSpacing + kHorizontalSpacing div 2, 50 + kArraySizeV * kVerticalSpacing + kVerticalSpacing div 3);
- myWindow := NewCWindow(nil, windowRectangle, 'Hex grid demo', true, 0, WindowPtr(-1), false, 0);
- SetPort(myWindow);
-
- (*Load the picture*)
- hexTile := GetPicture(128); (*PICT resource #128.*)
-
- (*Draw all tiles!*)
- for h := 0 to kArraySizeH - 1 do
- for v := 0 to kArraySizeV - 1 do
- DrawHexTile(h, v);
-
- while not Button do
- ;
- end. (*TextGrid*)