Advertisement
jcomeau_ictx

sprocket.ps

Oct 11th, 2013
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. %!ps-nonconforming
  2. /inch {72 mul} bind def
  3. /half {0.5 mul} bind def
  4. /buffer 20 string def
  5. /cot {dup cos exch sin div} bind def
  6. /comment {pop} bind def
  7. /fraction {div} bind def
  8. /centerpunch { % (radius -) draw cross at currentpoint
  9. gsave 0 1 index half rlineto stroke grestore
  10. gsave 0 1 index half neg rlineto stroke grestore
  11. gsave dup half 0 rlineto stroke grestore
  12. gsave (pops radius) comment half neg 0 rlineto stroke grestore
  13. } def
  14. /init {/Helvetica 10 selectfont
  15. currentpagedevice /PageSize get dup 1 get /pageheight exch def
  16. 0 get /pagewidth exch def
  17. /fontheight {currentfont dup /FontBBox get dup 3 get % top
  18. exch 1 get sub % top - bottom
  19. exch /FontMatrix get 3 get mul} bind def % adjusted by height multiplier
  20. /lineheight {fontheight 1.2 mul} bind def % add 20% for line spacing
  21. /newline {0 lineheight neg rmoveto} bind def
  22. } bind def
  23. % chain info from http://www.gizmology.net/sprockets.htm
  24. % pitch diameter is the diameter of the sprocket at the center of the rollers
  25. % Pitch Diameter = P ÷ sin (180° ÷ N)
  26. /pitchdiameter {(pitch teeth -) comment 180 exch div sin div} def
  27. % outside diameter is the diameter of the sprocket at the ends of the teeth
  28. % Outside Diameter = P × (0.6 + cot ( 180° ÷ N) )
  29. /outerdiameter {(pitch teeth -) comment 180 exch div cot .6 add mul} def
  30. /sprocket {(bore pitch rollerdiameter teeth -) comment
  31. /teeth exch def
  32. /rollerdiameter exch def
  33. /pitch exch def
  34. /bore exch def
  35. /pitchangle 360 teeth div def
  36. /rollerradius rollerdiameter half def
  37. /pitchradius pitch teeth pitchdiameter half def
  38. /outerradius pitch teeth outerdiameter half def
  39. gsave
  40. currentpoint translate newpath
  41. % remember rotation is in Cartesian space, so *counterclockwise*
  42. 0.5 setgray
  43. gsave 0 0 pitchradius 0 360 arc closepath stroke grestore
  44. 0 setgray % black for drilling and cutting
  45. 0 0 moveto bore half (radius) comment centerpunch newpath
  46. gsave 0 0 bore half (radius) comment 0 360 arc closepath stroke grestore
  47. teeth {
  48. gsave
  49. 0 pitchradius moveto currentpoint translate
  50. newpath pitchangle half neg rotate
  51. 0 0 moveto rollerradius centerpunch
  52. % circles for drilling base of teeth and for cutting the rest
  53. newpath % necessary to prevent unwanted radius line
  54. 0 0 rollerradius 180 pitchangle add 0 arc stroke
  55. 0 0 pitch rollerradius sub 0 45 arc stroke
  56. 0 0 pitch rollerradius sub 135 pitchangle add 180 pitchangle add arc stroke
  57. grestore pitchangle rotate
  58. } repeat
  59. grestore
  60. } def
  61. init
  62. pagewidth 1 3 fraction mul pageheight 1 3 fraction mul moveto
  63. 5 16 fraction inch 1 2 fraction inch 5 16 fraction inch 5 sprocket
  64. pagewidth 2 3 fraction mul pageheight 1 3 fraction mul moveto
  65. 5 16 fraction inch 1 2 fraction inch 5 16 fraction inch 6 sprocket
  66. pagewidth 1 3 fraction mul pageheight 2 3 fraction mul moveto
  67. 5 16 fraction inch 1 2 fraction inch 5 16 fraction inch 7 sprocket
  68. pagewidth 2 3 fraction mul pageheight 2 3 fraction mul moveto
  69. 5 16 fraction inch 1 2 fraction inch 5 16 fraction inch 8 sprocket
  70. showpage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement