jcomeau_ictx

sprocket.ps

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