Created
August 28, 2017 11:26
-
-
Save smartperson/08f8f68d845cf10fc626c550841a8eb8 to your computer and use it in GitHub Desktop.
postscript file to generate custom labels for analog meters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%!Postscript File | |
% This file generates meter faces. | |
% Copyright (c) 2004, Jennifer Elaan | |
% Circuit Corner 2004. | |
% Free for any use so long as this copyright notice | |
% remains intact. | |
% ------------------------------------------------------ | |
% These are unit definitions. They define conversion factors for | |
% common units like mils, inches, millimeters, etc. | |
% ------------------------------------------------------ | |
/mil { 0.072 mul } def | |
/in { 72 mul } def | |
/mm { 2.83464567 mul } def | |
% ------------------------------------------------------ | |
% Define all the scales you wish to use. If you | |
% want more scales, add lines like this for scale2, | |
% scale3, etc. | |
% ------------------------------------------------------ | |
/scale1 32 dict def | |
% ------------------------------------------------------ | |
% These parameters define the meter. You should edit | |
% them appropriately for your project. | |
% ------------------------------------------------------ | |
% Width and Height of the actual meter plate itself | |
/meter-width 2.375 in def | |
/meter-height 1.375 in def | |
% Calibration values. The first time you print your meter, | |
% these should match the values for meter-width and | |
% meter-height. Then if the results vary in size, measure | |
% the actual produced width and height and enter them here. | |
% The next time you print, the result will be properly | |
% scaled. | |
/calib-width 5 in def | |
/calib-height 5 in def | |
% Distance of the pivot from the bottom center | |
/pivot-vert -.1875 in def | |
/pivot-horz 0 in def | |
% Mounting holes, distance from bottom and separation | |
/mounting-height 0.125 in def | |
/mounting-distance 1.5 in def | |
% Signature Definition | |
/signature ( ) def | |
/signature-font (Times-Roman) def | |
/signature-fontsize 8 def | |
/signature-vert 1.8 in def | |
/signature-horz 1 in def | |
% ------------------------------------------------------ | |
% These parameters define the meter. You should edit | |
% them appropriately for your project. If you have | |
% multiple scales, make one copy of this section for | |
% each | |
% ------------------------------------------------------ | |
% These parameters define a scale | |
scale1 begin | |
/scale-color 0 0 0 3 array astore def | |
/scale-radius 1.15625 in def | |
/scale-divisions 59 def | |
/scale-linexp 1 def | |
/scale-degrees 90 def | |
/scale-virtoffset 0 in def | |
/scale-labeloffset 0.5 in def | |
/scale-labelfont (Helvetica) def | |
/scale-labelfontsize 12 def | |
/scale-start 0 def | |
/scale-end 59 def | |
/scale-title (seconds) def | |
/scale-titlefont (Helvetica) def | |
/scale-titlefontsize 18 def | |
/scale-titlevert 1.2 in def | |
/scale-titlehorz 0 def | |
/dash-length1 31.25 mil def | |
/dash-length2 62.5 mil def | |
/dash-length3 93.75 mil def | |
/dash-interval1 5 def | |
/dash-interval2 15 def | |
/dash-width1 1 def | |
/dash-width2 2 def | |
/dash-width3 2 def | |
/arc-width 3 def | |
/arc-endlen 250 mil def | |
end | |
% ------------------------------------------------------ | |
% Below this point is the actual program code. | |
% Unless you need to do something really special, you | |
% will likely not need to edit this far down. | |
% ------------------------------------------------------ | |
% Support Routines | |
/realangle { | |
scale-radius scale-degrees 2 div sin mul | |
scale-radius scale-degrees 2 div cos mul scale-virtoffset add | |
atan | |
} def | |
/realradius { | |
scale-radius scale-virtoffset add | |
} def | |
/scratchbuf 20 string def | |
/showcenter { | |
dup stringwidth pop 2 div neg 0 rmoveto show | |
} def | |
% Draw a meter scale | |
% Parameters: scale-radius scale-degrees scale-divisions | |
% scale-linexp scale-min scale-max | |
/drawscale { | |
0 1 scale-divisions { | |
newpath | |
0 scale-virtoffset neg moveto | |
gsave | |
dup | |
scale-linexp exp realangle 2 mul mul | |
scale-divisions scale-linexp exp div | |
realangle sub | |
dup sin realradius mul exch cos realradius mul rmoveto | |
dup | |
scale-linexp exp scale-degrees mul | |
scale-divisions scale-linexp exp div neg | |
scale-degrees 2 div add rotate | |
dup dash-interval2 mod 0 eq { | |
pop | |
dash-width3 setlinewidth | |
0 dash-length3 rlineto | |
} { | |
dash-interval1 mod 0 eq { | |
dash-width2 setlinewidth | |
0 dash-length2 rlineto | |
} { | |
dash-width1 setlinewidth | |
0 dash-length1 rlineto | |
} ifelse | |
} ifelse | |
stroke | |
grestore | |
} for | |
scale-labelfont findfont | |
scale-labelfontsize scalefont | |
setfont | |
0 dash-interval2 scale-divisions { | |
gsave | |
0 scale-virtoffset neg moveto | |
dup | |
scale-linexp exp realangle 2 mul mul | |
scale-divisions scale-linexp exp div | |
realangle sub | |
dup sin realradius mul exch cos realradius mul rmoveto | |
dup | |
scale-linexp exp scale-degrees mul | |
scale-divisions scale-linexp exp div | |
scale-degrees 2 div sub | |
dup sin scale-labeloffset mul exch cos scale-labeloffset mul | |
rmoveto | |
scale-end scale-start sub mul scale-divisions div | |
scratchbuf cvs showcenter | |
grestore | |
} for | |
scale-titlefont findfont | |
scale-titlefontsize scalefont | |
setfont | |
scale-titlehorz scale-titlevert moveto | |
scale-title showcenter | |
} def | |
% Draw the scale arc | |
/drawarc { | |
gsave | |
arc-width setlinewidth | |
newpath | |
0 scale-virtoffset neg moveto | |
realangle sin realradius mul realangle cos realradius mul rmoveto | |
scale-degrees 2 div sin arc-endlen mul | |
scale-degrees 2 div cos arc-endlen mul rmoveto | |
0 scale-virtoffset neg realradius | |
90 realangle sub realangle 90 add | |
arc | |
scale-degrees 2 div sin arc-endlen neg mul | |
scale-degrees 2 div cos arc-endlen mul rlineto | |
stroke | |
grestore | |
} def | |
% Draw a crosshair ( x y -- ) | |
/crosshair { | |
newpath | |
gsave translate | |
0 0 4 0 360 arc | |
-5 0 moveto 5 0 lineto | |
0 -5 moveto 0 5 lineto | |
stroke | |
grestore | |
} def | |
% Draw the meter itself | |
/drawmeter { | |
newpath | |
meter-width 2 div neg pivot-horz add | |
pivot-vert neg moveto | |
meter-width 0 rlineto | |
0 meter-height rlineto | |
meter-width neg 0 rlineto | |
closepath | |
stroke | |
0 0 crosshair | |
mounting-distance 2 div neg mounting-height pivot-vert sub crosshair | |
mounting-distance 2 div mounting-height pivot-vert sub crosshair | |
signature-font findfont | |
signature-fontsize scalefont | |
setfont | |
signature-horz signature-vert pivot-vert sub moveto | |
signature showcenter | |
} def | |
4 in 4 in translate | |
meter-width calib-width div | |
meter-height calib-height div | |
scale | |
meter-height calib-height | |
gsave | |
/scale1 where { | |
scale1 begin scale-color aload pop setrgbcolor | |
drawscale drawarc end | |
} if | |
/scale2 where { | |
scale2 begin scale-color aload pop setrgbcolor | |
drawscale drawarc end | |
} if | |
/scale3 where { | |
scale3 begin scale-color aload pop setrgbcolor | |
drawscale drawarc end | |
} if | |
/scale4 where { | |
scale4 begin scale-color aload pop setrgbcolor | |
drawscale drawarc end | |
} if | |
/scale5 where { | |
scale5 begin scale-color aload pop setrgbcolor | |
drawscale drawarc end | |
} if | |
grestore | |
drawmeter | |
showpage | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment