Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/dpv/cscDPV.m4

raw
1 .PS
2 #.PS 3.5
3 # csc.m4
4 # This file includes AntiqueClock and works for PSTricks, Tikz, and svg
5 gen_init
6 NeedDpicTools
7
8 skale = 0.878
9 circlerad=1.91*skale
10 hubrad=0.10*skale
11 s=0.5*skale
12
13 define(`midnight',`0.1, 0.1, 0.44')
14 define(`white',`1, 1, 1')
15 define(`spokewidth',0.1)
16 define(`spoke',`dnl
17 {line from rvec_(0,hubrad-spokewidth/2) to rvec_(circlerad-0.05,0)}
18 {line from rvec_(0,-(hubrad-spokewidth/2)) to rvec_(circlerad-0.05,0)}')
19 define(`lwid',1)
20 define(`coord',`(s*(`$1'),s*(`$2'))')
21
22 # Circle and spokes
23 CSC: [
24 rgbdraw(midnight,
25 linethick=`0.'eval(lwid*15)/(1pt__)
26 {circle with .c at Here
27 circle invis diam last circle.diam + linethick pt__ at last circle }
28 linethick=spokewidth/(1pt__)
29 for angle = 0 to 330 by 30 do {
30 Point_(angle)
31 {spoke}
32 }
33 )
34
35 # Whiten where the hull will be
36 linethick=`0.'eval(lwid*20)/(1pt__)
37 rgbdraw(white,
38 Point_(-60){line to rvec_(circlerad*0.72,0)}
39 Point_(-90){line to rvec_(circlerad*0.72,0)}
40 Point_(-120){line to rvec_(circlerad*0.72,0)}
41
42 linethick=`0.'eval(lwid*15)/(1pt__)
43 {move to coord(1.8,-2.3)+(0,0.025)
44 spline to Here+coord(-0.8,-0.3) then to Here+coord(-1.8,-0.3) \
45 then to Here+coord(-2.18,-0.27) \
46 then to Here+coord(-3.93,-0.1)}
47 )
48
49 # Sail
50 thinlines_
51 rgbfill(midnight,
52 line from coord(0.44,3.38) to coord(0.44,2.6) \
53 then to coord(2.1,-1.75) \
54 then to coord(1.22,-1.53) \
55 then to coord(0.62,-1.4) \
56 then to coord(0.55,-1.6) \
57 then to coord(-2.2,-1.6) \
58 then to coord(-2.35,-1.5)
59 spline to coord(-2.14,-0.78) \
60 then to coord(-1.74,0.22) \
61 then to coord(-1.42,0.89) \
62 then to coord(-0.92,1.73) \
63 then to coord(0,2.9) \
64 then to coord(0.44,3.38)
65 )
66
67 # Hull
68 rgbfill(midnight,
69 spline from coord(2.1,-1.75) to coord(1.9,-2.2) \
70 then to coord(1.85,-2.3) then to coord(1.8,-2.33) \
71 then to coord(1,-2.5) then to coord(0,-2.6) then to coord(-0.38,-2.57) \
72 then to coord(-2.13,-2.4)
73 line to coord(-2.2,-2.05) then to coord(2.1,-1.75)
74 spline to coord(-1,-2.08) then to coord(0.55,-1.77)
75 )
76 ]
77
78 Clock: [
79 # PSTricks, tikz, or svg only:
80 ifelse(ifpstricks(T)`'ifpgf(T)`'ifsvg(T),T,`
81 #.PS
82 # AntiqueClock.m4
83 #gen_init
84 #NeedDpicTools
85
86 iflatex(`latexcommand({\sf)')
87 ifsvg(svg_font(font-family="sans-serif" font-stretch="condensed")
88 # svg_rot_init(test))
89 svg_rot_init(cscDPV))
90
91 # https://tex.stackexchange.com/questions/236923/generate-analog-clock-with-numbered-face-add-seconds-roman-numerals
92
93 # `hms2deg(hr,min,sec) hr:min:sec to degrees
94 # blank arg1: degrees for minute hand
95 # blank arg1 and arg2: degrees for second hand'
96 define(`hms2deg',`ifelse(`$1',,
97 `ifelse(`$2',,
98 `(90-pmod(ifelse(`$3',,0,`$3'),60)/60*360)',
99 `(90-(pmod(`$2',60)/60 + pmod(ifelse(`$3',,0,`$3'),60)/60/60)*360)')',
100 `(90-(pmod(`$1',12) + pmod(ifelse(`$2',,0,`$2'),60)/60 + dnl
101 pmod(ifelse(`$3',,0,`$3'),60)/3600)/12*360)')')
102
103 # `SecondHand(length,hr,min,sec)'
104 define(`SecondHand',`[ shsf = (`$1')/3.2
105 C: Here
106 { L: rpoint_(to (Rect_(`$1',hms2deg(,,`$4')))) }
107 line thick 8*shsf to rvec_(`$1',0)
108 ]')
109
110 # `AntiqueMinuteHand(length,hr,min,sec)'
111 define(`AntiqueMinuteHand',`[ mhsf = (`$1')/2.84
112 L: rpoint_(to (Rect_(`$1',hms2deg(,`$3',`$4'))))
113 C: circle fill_(0) diam 0.47*mhsf at L.start
114 move to C
115 spline from rvec_(0,0.047*mhsf) \
116 to rvec_(1.65*mhsf,0.11*mhsf) \
117 then to rvec_(`$1',0.018*mhsf) \
118 then to rvec_(`$1',-0.018*mhsf) \
119 then to rvec_(1.65*mhsf,-0.11*mhsf) \
120 then to rvec_(0,-0.047*mhsf) \
121 shaded rgbstring(0,0,0)
122 ]')
123
124 # `AntiqueHourHand(length,hr,min,sec)'
125 define(`AntiqueHourHand',`[ hhsf = (`$1')/2.2
126 L: rpoint_(to (Rect_(`$1',hms2deg(`$2',`$3',`$4'))))
127 C: circle fill_(0) diam 0.6*hhsf at L.start
128 move to C
129 v = 0.25*hhsf
130 { line to rvec_(1.1*hhsf,0) thick 0.15/(1bp__)*hhsf }
131 C1: rvec_(1.25*hhsf,0)
132 d = `$1'-1.25*hhsf
133 q = 1bp__*hhsf
134 r1 = (d^2 + q^2 - v^2)/(v-q)/2
135 tang = atan2((r1+q),d)
136 for i=0 to 3 do {
137 X[i]: C1+vec_(rect_(v, pi_+i/3*( tang-pi_)))
138 Y[i]: C1+vec_(rect_(v,-pi_+i/3*(-tang+pi_)))
139 }
140 n = 3
141 for i=1 to 4 do { aa = -pi_+tang + i/4*(pi_/2-tang)
142 XX: (d,r1+q)+(rect_(r1,aa))
143 n+=1;
144 X[n]: C1+vec_(XX.x, XX.y)
145 Y[n]: C1+vec_(XX.x,-XX.y)
146 }
147 m = n
148 for i= 0 to m do { n+=1; X[n]: Y[m-i] }
149 fitcurve(X,n,shaded rgbstring(0,0,0))
150 ]')
151
152
153 define(`AntiqueClock',`[ # h,m,s,diam
154 # Clock size parameters:
155 hour = ifelse(`$1',,3,`$1')
156 minute = ifelse(`$2',,41,`$2')
157 second = ifelse(`$3',,51,`$3')
158 # outer radius
159 ifelse(`$4',,`skale=0.5; r1=2',`r1=(`$4')/2; skale=r1/4')
160 r2 = r1-0.5*skale
161 r3 = r2-0.14*skale
162 r4 = r3 - 0.35*skale
163 r5 = r4 - 0.17*skale
164 r6 = r5 - 0.63*skale
165 r7 = r6 - 0.17*skale
166 shadelinethick = 1.0
167
168 C: circle thick 0.2 rad r1
169
170 define shadeline {
171 s = 1-($`'1)*2
172 v = r*s
173 h = sqrt(r^2-v^2)
174 t = 1-abs(s)
175 line from (vrot_(-h,v,cost,sint)) to (vrot_(h,v,cost,sint)) \
176 thick shadelinethick outlined rgbstring(t,t,t)
177 }
178
179 r = r1 # Bezel outer
180 nlines = int(2*r/(shadelinethick pt__)*1.1)
181 cost = cosd(10); sint = sind(10);
182 ShadeObject(shadeline,nlines, 0, 0,0,0, 0.5, 1,1,1, 1, 0,0,0 ) at C
183
184 r = r2 # Bezel inner
185 nlines = int(2*r/(shadelinethick pt__)*1.1)
186 cost = cosd(-10); sint = sind(-10);
187 ShadeObject(shadeline,nlines, 0, 0,0,0, 0.25, 0.8,0.8,0.8, 0.5, 1,1,1,
188 0.75, 0.8,0.8,0.8, 1, 0,0,0 ) at C
189
190 # Clock face
191 Face: circle thick 0 fill_(1) rad r3 at C
192 circle rad r4 at C
193 circle rad r5 at C
194 circle rad r6 at C
195 circle rad r7 at C
196
197 # Ad hoc shift of rotated svg text
198 ifsvg(`define adj {+(-cosd($`'1)*textht*0.5*sign(180-($`'1)),\
199 (0.25+0.25*cosd(2*($`'1)))*textht) }',
200 `define adj {}')
201 define adj {}
202
203 # Outer numbers
204 iflatex(`command sprintf("\font\outerfont=cmss12 at %4.2fin",r3-r4)')
205 ifsvg(`textht = (r3-r4)*0.6')
206 for_(-15,15,5,`aa=90-(m4x)*6
207 r_text(eval(-(m4x)*6),eval((m4x+60)%60),
208 at C+(Rect_((r3+r4)/2,aa)) adj(aa))')
209 for_(20,40,5,`aa=450-(m4x)*6
210 r_text(eval(180-m4x*6),m4x,at C+(Rect_((r3+r4)/2,aa)) adj(aa))')
211 # Outer tics
212 for mn = 1 to 60 do { t = 90-mn/60*360
213 line from C+(Rect_(r5,t)) to C+(Rect_(r4,t)) }
214
215 # Inner numbers
216 iflatex(`command sprintf("\font\innerfont=cmss12 at %4.2fin",r5-r6)')
217 ifsvg(`textht = (r5-r6)*0.6')
218 Loopover_(`mx',`aa=180-(m4Lx-1)*30
219 r_text(eval(120-m4Lx*30),iflatex({\innerfont mx},mx),
220 at C+(Rect_((r5+r6)/2,aa)) adj(aa))',
221 IX,X,XI,XII,I,II,III)
222 Loopover_(`mx',`aa=360-m4Lx*30
223 r_text(eval(90-m4Lx*30), iflatex({\innerfont mx},mx),
224 at C+(Rect_((r5+r6)/2,aa)) adj(aa))',
225 IV,V,VI,VII,VIII)
226
227 # Inner tics
228 for mn = 5 to 60 by 5 do { t = 90-mn/60*360
229 line from C+(Rect_(r7,t)) to C+(Rect_(r6,t)) }
230
231 # Hands
232 AntiqueHourHand(r6,hour,minute,second) with .C at C
233 AntiqueMinuteHand(r5,hour,minute,second) with .C at C
234 SecondHand((r3+r4)/2,hour,minute,second) with .C at C
235
236 # Center
237 dot(at C,0.1/4*r1,1)
238 ]') `# AntiqueClock'
239
240 Clock1: AntiqueClock(,,,3.5)
241 # Clock2: AntiqueClock(4,50,07,2) at Clock1.e+(1.5,0)
242
243 iflatex(`latexcommand(}%)')
244 ifsvg(`command "</g>"')
245
246 #.PE
247 ',` "AntiqueClock.m4 requires PSTricks, Tikz-pgf, or svg" ')
248 ] with .sw at last [].se+(0.25,0)
249 .PE