Advertisement
Guest User

Encoder PostScript PS

a guest
Jan 28th, 2012
1,702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. %!PS-Adobe-2.0
  2. %%Title: Postscript Quadrature Encoder Disk
  3. %%Creator: (C) Ricardo Seixas - [email protected]
  4. %%CreationDate: May 12 2000
  5.  
  6. %%Title: Quadrature Encoder Disk
  7. %----------------------------------------------------------
  8. %%Changed to create the A & B for a quadrature encoder
  9. %%By Douwe Jippes - [email protected]
  10. %%Date Sept 10 2006
  11. %%EndComments
  12. %%Changed to create "trace_width_a & b in the middle of the line.
  13. %%Date Sept 14 2006
  14. %%Major Change to orginate all lines from the centre.
  15. %%Thanks to the great help from "Teun" [email protected]
  16. %%Date sept 16 2006
  17. %-----------------------------------------------------------
  18. % You can freely distribute and use this file as long as you maintain the original copyright
  19. % This file is provided as is and there's NO WARRANTY
  20. % Use it at your own risk
  21.  
  22. /bd {bind def} bind def
  23. /ed {exch def} bd
  24. /df {def} bd
  25.  
  26. /mm {2.8346 mul} bd
  27. /pi 3.1415926536 df
  28.  
  29. %Here you can change the encoder characteristics
  30.  
  31. /offset -2.66666 df % rotational offset per ring (per encoder)
  32.  
  33. /slots 1 df
  34. /nrOfRings 10 df
  35.  
  36. /diameter_step 10 df
  37. /external_diameter 55 mm df
  38. /internal_diameter external_diameter diameter_step nrOfRings mul sub df
  39.  
  40. /text ( HI5-HI6_simulator [email protected] ) df % don't remove the parentheses when you change text!!!
  41. /text_diameter internal_diameter 1 mm sub df
  42. %/text_diameter 20 mm df
  43. /font_size internal_diameter 10 div df
  44. %/font_size 6 df
  45. /font_type (Courier) df
  46. %
  47. %Look at the end of the file for positioning
  48.  
  49. /center_hole {
  50. gsave % to restore linewidth
  51. % change by tune: setlinewidth is needed only once
  52. 0.2 setlinewidth
  53. %Cross
  54. -7 mm 0 moveto 14 mm 0 rlineto stroke
  55. 0 -7 mm moveto 0 14 mm rlineto stroke
  56.  
  57. %Bulls Eye 8 mm
  58. 0 0 8 mm 2 div
  59. 0 360 arc stroke
  60.  
  61. %Bulls Eye 14 mm
  62. 0 0 16 mm 2 div
  63. 0 360 arc stroke
  64. grestore
  65. } bd
  66.  
  67. %Don't mess around here unless you know what you're doing
  68. /iR internal_diameter 2 div df
  69. /sR diameter_step 2 div df
  70.  
  71. /DrawSegments { % Ri Ro nrOfSlots -> _
  72. %/--in-- pstack ==
  73. gsave
  74. 360 1 index 2 mul div exch % Ri Ro angle nrOfSlots -> _
  75. { % repeat
  76. % fill one slice of a ring from zero to angle degrees
  77. % with origin (0, 0), inner radius Ri and outer radius Ro
  78. % and rotate the user space 2*angle degrees
  79. % Ri Ro angle -> Ri Ro angle
  80. 2 index 0 moveto
  81. 0 0 3 index 0 4 index arc
  82. 0 0 4 index 3 index 0 arcn
  83. fill
  84. %/--i-- pstack ==
  85. dup 2 mul rotate
  86. } repeat
  87. grestore
  88. pop pop pop
  89. } bd
  90.  
  91. /DrawDiscs { % nrOfRings nrOfSlots Ri Rstep ->
  92. % example to debug stack:
  93. %/--ins-- pstack ==
  94. 3 dict begin % local dict
  95. /sR ed % R step
  96. /iR ed % R inner
  97. /#S ed % nrOfSlots % nrOfRings
  98. gsave
  99. 0.05 setlinewidth
  100. % draw inner circle
  101. { % repeat
  102. 360 #S offset mul div rotate % shift outer segments by 1/4 segment
  103. 0 0 iR 0 360 arc stroke
  104. /#S 2 #S mul def %twice as many segments each ring
  105. iR iR sR add #S DrawSegments
  106. /iR iR sR add df
  107. % rotate angle degrees for next ring
  108. } repeat
  109. % draw outer circle
  110. 0 0 iR 0 360 arc stroke
  111. grestore
  112. end % local dict
  113. %/--outs--- pstack ==
  114. center_hole
  115. } bd
  116.  
  117. % Text routine borrowed from Adobe Blue Book Program 10, on page 167
  118. /insidecircletext
  119. { circtextdict begin
  120. /radius exch def /centerangle exch def
  121. /ptsize exch def /str exch def
  122.  
  123. /xradius radius ptsize 3 div sub def
  124. gsave
  125. centerangle str findhalfangle sub rotate
  126. str
  127. { /charcode exch def
  128. ( ) dup 0 charcode put insideplacechar
  129. } forall
  130. grestore
  131. end
  132. } def
  133.  
  134. /circtextdict 16 dict def
  135. circtextdict begin
  136. /findhalfangle
  137. { stringwidth pop 2 div
  138. 2 xradius mul pi mul div 360 mul
  139. } def
  140.  
  141. /insideplacechar
  142. { /char exch def
  143. /halfangle char findhalfangle def
  144. gsave
  145. halfangle rotate
  146. radius 0 translate
  147. 90 rotate
  148. char stringwidth pop 2 div neg 0 moveto
  149. char show
  150. grestore
  151. halfangle 2 mul rotate
  152. } def
  153. end
  154.  
  155. /font_type findfont font_size scalefont setfont
  156. /Encoder_Text {
  157. text 18 -90 text_diameter 2 div insidecircletext
  158. } def
  159.  
  160. /Draw_Encoder {
  161. % nrOfRings nrOfSlots Ri Rstep ->
  162. nrOfRings slots iR sR DrawDiscs
  163. %Comment next line to remove text
  164. Encoder_Text
  165. } def
  166.  
  167. %manual placement, you can put more than one encoder on the same sheet
  168. %30 mm 30 mm translate Draw_Encoder
  169. %52 mm 0 mm translate Draw_Encoder
  170.  
  171. % Fil a sheet with discs
  172. %
  173. /pageSizeX 216 mm df % letter
  174. /pageSizeY 280 mm df % letter
  175. /topMargin 15 mm df
  176. /bottomMargin 15 mm df
  177. /leftMargin 10 mm df
  178. /rightMargin 10 mm df
  179. /spaceX 10 mm df % horizontal space between images
  180. /spaceY 10 mm df % vertical space between images
  181. /dX external_diameter spaceX add df
  182. /dY external_diameter spaceY add df
  183.  
  184. /#x
  185. pageSizeX leftMargin sub rightMargin sub spaceX add
  186. external_diameter spaceX add
  187. div cvi
  188. df
  189.  
  190. /#y
  191. pageSizeY bottomMargin sub topMargin sub spaceY add
  192. external_diameter spaceY add
  193. div cvi
  194. df
  195.  
  196. bottomMargin leftMargin translate
  197. external_diameter 2 div dup translate
  198.  
  199. #y { %repeat
  200. gsave
  201. #x { %repeat
  202. nrOfRings slots iR sR DrawDiscs
  203. dX 0 translate
  204. %/offset offset 0.1 add def
  205. } repeat
  206. grestore
  207. 0 dY translate
  208. } repeat
  209. showpage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement