Guest User

Untitled

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