Debian Codegraph @

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

raw
1 .PS
2 # Sevensegment.m4
3 # https://tex.stackexchange.com/questions/644009/seven-segments-anchors-how-to-use-them
4 gen_init
5 divert(-1)
6 `sevensegment(keys)
7 Seven-segment display in a [] block. keys:
8 hght=expr; (default boxht)
9 wdth=expr; (default hght*3.3/5.85)
10 slant=fraction; top is skewed slant fraction of ht
11 segwid=expr; segment width
12 gap=expr; gap between segments
13 bevel=fraction; corner truncation
14 on=attributes; "on" segment attributes
15 off=attributes; "off" segment attributes
16 code=[0-8][.]; displayed number .=decimal point
17 or
18 code=Xddddddd[.] where each d=0 or 1 to define
19 Segment1 to Segment7 off or on
20 Segments are labeled Seg1 Seg2 ... Seg7
21 and the decimal point is Seg8'
22 define(`sevensegment', # hght, wdth, slant, segwid, gap, bevel, on, off, code
23 `[ pushkeys_(`$1',`hght:boxht; wdth:m4`'hght*3.3/5.85; slant:0;
24 segwid:0.75/3.2*m4`'wdth; gap:0.12/3.2*m4`'wdth; bevel:0.4;
25 on:outlined "red" shaded "red":N; off:outlined "lightgray":N;
26 code:00000010:N;')
27 gapch = m4gap/2*sqrt(2)
28 ifinstr(m4code,.,`define(`m4tmp',substr(m4code,0,decr(len(m4code))))dnl
29 pushdef(`dodp',1)poppushdef(`m4code',m4tmp)')dnl
30 ifinstr(m4code,X,`pushdef(`opcode',substr(m4code,1))',
31 `foreach_(`m4cd',`pushdef(`Cd'decr(m4Lx),m4cd)',1111110,0110000,1101101,
32 1111001,0110011,1011011,1011111,1110000,1111111,1111011)dnl
33 pushdef(`opcode',Cd`'m4code)')dnl
34 for_(1,7,1,`pushdef(`attrib'm4x,
35 ifelse(substr(opcode,decr(m4x),1),1,`m4on',`m4off'))')dnl
36 Seg1: m4segment(R,m4bevel,m4bevel,attrib1) \
37 with .S at m4slu(0,m4hght-m4segwid)
38 inner = distance(Seg1.SW,Seg1.SE) + gapch*2
39 Seg2: m4segment(D,0.5,m4bevel,attrib2) with .S at \
40 m4slu(m4wdth/2-m4segwid,m4hght-m4segwid-inner/2)
41 Seg3: m4segment(D,m4bevel,0.5,attrib3) with .S at \
42 m4slu(m4wdth/2-m4segwid,m4segwid+inner/2)
43 Seg4: m4segment(L,m4bevel,m4bevel,attrib4) with .S at m4slu(0,m4segwid)
44 Seg5: m4segment(U,0.5,m4bevel,attrib5) with .S at \
45 m4slu(-m4wdth/2+m4segwid,m4segwid+inner/2)
46 Seg6: m4segment(U,m4bevel,0.5,attrib6) with .S at \
47 m4slu(-m4wdth/2+m4segwid,m4hght-m4segwid-inner/2)
48 Seg7: m4segment(R,0.5,0.5,attrib7) with .c at m4slu(0,m4hght/2)
49 ifelse(dodp,1,`Seg8: circle diam m4segwid m4on \
50 at m4slu(Seg3.e.x+m4segwid/2+m4gap,Seg4.s.y+m4segwid/2)') popdef(`dodp')
51 popdef(`m4hght',`m4wdth',`m4slant',`m4segwid',`m4gap',`m4bevel',
52 `m4on',`m4off',`m4code',`opcode')dnl
53 for_(1,7,1,`popdef(`attrib'm4x)') for_(0,9,1,`popdef(`Cd'm4x)')dnl
54 ]')
55 define(`m4segment',`[ setdir_(`$1')
56 m4seven_pos(SE,E,NE,,`$2'); m4seven_pos(SW,W,NW,-,`$3')
57 resetdir_
58 S: 1/2 between SW and SE
59 Line: line from m4slu(S.x,S.y) to m4slu(SE.x,SE.y) then to m4slu(E.x,E.y) \
60 then to m4slu(NE.x,NE.y) then to m4slu(NW.x,NW.y) then to m4slu(W.x,W.y) \
61 then to m4slu(SW.x,SW.y) then to m4slu(S.x,S.y) `$4' ] ')
62 define(`m4seven_pos',
63 `AA: (`$4'(m4wdth/2-m4segwid-gapch),0); `$1': rot_(AA.x,AA.y,rp_ang)
64 BA: AA + (`$4'1,1)*m4segwid*(1-`$5'); `$2': rot_(BA.x,BA.y,rp_ang)
65 CA: BA - (`$4'1,-1)*m4segwid*`$5'; `$3': rot_(CA.x,CA.y,rp_ang) ')
66 define(`m4slu',`(`$1'+(`$2')*m4slant,`$2')')
67
68 divert(0)dnl
69
70
71 [
72 S: sevensegment(code=4.;hght=1)
73 { for_(1,8,1,`"m4x" at S.Seg`'m4x') }
74 move right 0.25
75 P: sevensegment(code=X1100011;off=invis;hght=1)
76 ]
77 [
78 for_(0,9,1,`sevensegment(code=m4x`'ifelse(m4x,1,.);slant=1/4;off=invis)
79 move movewid/4')
80 ] with .nw at last [].sw+(0,-boxht/3)
81
82 .PE