Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/GrayCode.m4

raw
1 .PS
2 # GrayCode.m4
3 gen_init
4
5 GrayCode: [
6 outer = 4
7 inner = 0.75
8 nbits = 10
9
10 C: circle diam outer
11 circle diam inner at C
12 sectors = 2^nbits
13 lthk = (outer-inner)/2/nbits
14 for bit = 1 to nbits do {
15 for is = 2^(bit-1) to sectors by 2^(bit+1) do {
16 startang = is/sectors*360
17 endang = min(startang+(2^bit)/sectors*360,360)
18 arcd(C,outer/2-(bit-0.5)*lthk,startang,endang) thick lthk/(1bp__)
19 }
20 }
21 ]
22 # Crossbar
23 Crossbar: [
24 circlerad = 0.12
25 boxwid = 0.18
26 boxht = 0.18
27 rathick = 1.5
28 rawd = rathick*4 bp__
29 raht = rawd*2
30 boxdist = boxwid*1.8
31
32 define bcoord {($2,-($1))*boxdist}
33 define redarrow { arrow ht raht wid rawd thick rathick color "red" }
34
35 define cbx {
36 thinlines_
37 n = $+ - 1
38 for i=0 to n do {
39 line color "blue" from bcoord(i,0) to bcoord(i,n)
40 line color "blue" from bcoord(0,i) to bcoord(n,i)
41 C[i]: circle invis at bcoord(i,-1.5)
42 }
43 for i=0 to n do {
44 exec sprintf("col = $%g",i+1)
45 redarrow from C[i].e right 1.25*boxwid
46 redarrow from C[i].w+(-boxwid,0) right raht
47 for j=0 to n do {
48 B: box outlined "blue" shaded "yellow" at bcoord(i,j)
49 if j==col then {
50 line color "blue" from B.s to B.e
51 line thick rathick color "red" from C[i].e to B.w \
52 then to B.n then to (B.x,C[0].y+(2+j*2/3)*boxht)
53 continue to (C[j].x-(2+j*2/3)*boxht,Here.y)
54 continue to (Here,C[j]) then to C[j].w
55 } \
56 else {
57 line color "blue" from B.n to B.s
58 line color "blue" from B.w to B.e
59 }
60 }
61 }
62 thicklines_
63 for i=0 to n do {
64 circle thick 1.5 outlined "blue" shaded "yellow" at C[i] \
65 sprintf("iflatex(\large)%g",i)
66 }
67 }
68
69 ifdpic(`
70 cbx(3,6,0,5,2,7,1,4)
71 ',`box wid 1 ht 0.75 "Crossbar" "requires" "dpic"')
72
73 ] with .w at GrayCode.e+(0.2,0)
74 .PE