-
Notifications
You must be signed in to change notification settings - Fork 5
/
hexpaper.ps
152 lines (111 loc) · 4.27 KB
/
hexpaper.ps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
%!PS-Adobe-1.0
% hexpaper.ps - Version 1.0 : Hexagon mapping paper in PostScript
%
% Copyright 1994 by Daniel C. Nygren
% Current e-mail: [email protected]
%
% Permission to use and modify this software for any purpose other than
% commercial use or its incorporation into a commercial product is
% hereby granted without fee. Permission to copy and distribute this software
% only for non-commercial use is also granted without fee, provided that
% the above copyright notice and this entire permission notice appear in
% all copies, and any supporting documentation. The author makes no
% representations about the suitability of this software for any purpose.
% It is provided "as is" without express or implied warranty.
% This program prints out hexagon mapping paper on a PostScript printer.
% The size of the hexes is adjustable via the side_size variable. The darkness
% of the lines can be changed with the setgray operator and the line thickness
% can also be set differently with the setlinewidth operator.
% --- Defines ---
/#copies 2 def %Enter number of copies to print out
/side_size {0.48} def %Enter length of a hexagon side in inches
/paper_width {8.5} def %Enter paper width in inches
/paper_height {11} def %Enter paper height in inches
/margin {0.16} def %Enter paper margin in inches
% Calculate a hexagon's height and width given a side's size
/hex_height {2 side_size mul 60 sin mul} bind def
/hex_width {2 side_size mul 60 cos mul side_size add} bind def
% Calculate how many hexes will fit across the paper's width
% Subtract a hex_width from the available space because we need to
% add one last_hex_bottom at the end of each row of hex_bottoms
/this_many_hexes_wide {paper_width margin 2 mul sub hex_width sub hex_width side_size add div floor} bind def
% Calculate how many hexes will fit across the paper's height
/this_many_hexes_high {paper_height margin 2 mul sub hex_height div floor} bind def
/inch {72 mul} bind def
% --- Lines ---
/line {side_size inch 0 inch rlineto} def
/no_line {side_size inch 0 inch rmoveto} def
/hex_bottom { % %%%%%%
-60 rotate % %
line %%%%%%
60 rotate
line
60 rotate
line
-60 rotate
line
} bind def
/last_hex_bottom { % %
-60 rotate % %
line %%%%%%
60 rotate
line
60 rotate
line
-60 rotate
} bind def
/hex_top { %%%%%%
60 rotate % %
line % %------
-60 rotate
line
-60 rotate
line
60 rotate
no_line
} bind def
% --- Start program ---
newpath %Start with a clean slate
0.2 setgray %Play with this to change darkness of lines
0.2 setlinewidth %Play with this to change line thickness
% --- Calculate where to start printing so the hexes are centered ---
% Find out how many hex_bottoms will fit across the paper's width.
this_many_hexes_wide
% Then see how much room they will take up (Don't forget the last hex bottom!)
hex_width side_size add mul hex_width add
% Then subtract from paper width and divide by two to find out where to start
% printing. This x coordinate is left on the stack.
paper_width exch sub 2 div inch
% Find out how many hexes will fit across the paper's height
this_many_hexes_high
% Then see how much room they will take up
hex_height mul
% Then subtract from paper height and divide by two and add hex_height divided
% by two (because we start drawing at the middle of the hex) to find out where
% to start printing This y coordinate is left on the stack.
paper_height exch sub 2 div hex_height 2 div add inch
% Start printing at the calculated spot
moveto
% Construct the rows of hexes by printing a row of hex bottoms
% followed by a row of hex tops. Loop counts must be integers, so
% cvi is used to convert the numbers to integers.
this_many_hexes_high cvi{
currentpoint %Save currentpoint on stack twice:
currentpoint %once for getting back to print the hex tops,
%once for returning to move up one row.
%Make a row of hex_bottoms
this_many_hexes_wide cvi{
hex_bottom
}repeat
last_hex_bottom %Last hex bottom doesn't have a tail sticking out
moveto %Go back to point saved on stack to print hex tops
%Make a row of hex tops
this_many_hexes_wide cvi{
hex_top
}repeat
hex_top %Last hex top to match last hex bottom
moveto %Go back to point saved on stack so we can move up to next row
0 inch hex_height inch rmoveto %Move up to next row
}repeat
stroke
showpage