Debian Codegraph @

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

raw
1 .PS
2 # worm.m4
3 gen_init
4
5 define(`svgcolor',`sprintf("rgb(%g,%g,%g)",`$1',`$2',`$3')')
6
7 `define case { exec sprintf("$%g",floor($1+0.5)+1); }'
8
9 `define hsvtorgb {
10 h_ = $1; s_ = $2; v_ = $3
11 f_ = h_/60-floor(h_/60)
12 p_ = v_*(1-s_)
13 q_ = v_*(1-f_*s_)
14 t_ = v_*(1-(1-f_)*s_)
15 case(pmod(floor(h_/60),6)+1,
16 $4 = v_; $5 = t_; $6 = p_,
17 $4 = q_; $5 = v_; $6 = p_,
18 $4 = p_; $5 = v_; $6 = t_,
19 $4 = p_; $5 = q_; $6 = v_,
20 $4 = t_; $5 = p_; $6 = v_,
21 $4 = v_; $5 = p_; $6 = q_)
22 $4 = int(($4)*255+0.5)
23 $5 = int(($5)*255+0.5)
24 $6 = int(($6)*255+0.5)
25 }'
26
27 Worm: [
28 linethick_(0.1)
29 dimen = 1.25 # scale parameter; try dimen=2 for a larger picture
30 w = 0.15 * dimen # worm radius
31 nhues = 265
32 S: dimen,0
33 for inx = 1 to nhues +2 do {
34 theta = inx*360/nhues
35 R: dimen*cosd(3*theta), dimen*sind(2*theta)
36 D: R-(S.x,S.y)
37 t = sqrt(max(0,w^2/(D.x^2+D.y^2)-1/4))
38 Ra: 0.5<S,R> + (t*D.y,-t*D.x)
39 Rb: 0.5<S,R> - (t*D.y,-t*D.x)
40 if inx <= nhues then {
41 hsvtorgb(theta+120,1,1,r,g,b)
42 rgbfill( r,g,b,
43 arc cw from Ra to Rb rad w with .c at S
44 arc ccw from Rb to Ra rad w with .c at R )
45 } else {
46 arc cw from Ra to Rb rad w with .c at S
47 arc ccw from Rb to Ra rad w with .c at R }
48 S: R
49 }
50 ]
51
52 "svg_fsize(R,120)" at 0.9<Worm.se,Worm.ne> ljust
53 "svg_fsize(G,120)" at Worm.e ljust
54 "svg_fsize(B,120)" at 0.1<Worm.se,Worm.ne> ljust
55 "svg_fsize(Y,120)" at 0.1<Worm.sw,Worm.nw> rjust
56 "svg_fsize(M,120)" wid 0.2 at Worm.w rjust
57 "svg_fsize(C,120)" at 0.9<Worm.sw,Worm.nw> rjust
58 box invis ht Worm.ht wid Worm.wid+0.4 at Worm
59
60 [ thicklines_
61 C: circle rad 1.5 at 0,0
62 smallrad = C.rad/2
63 for t=0 to 330 by 30 do {
64 line from Rect_(C.rad-0.05,90-t) to Rect_(C.rad+0.05,90-t)
65 sprintf("%g",t) at Rect_(C.rad+0.2,90-t)
66 }
67 "svg_fsize(R,120)" at Rect_(C.rad+0.45,90-0)
68 "svg_fsize(Y,120)" wid 0.2 at Rect_(C.rad+0.45,90-60)
69 "svg_fsize(G,120)" at Rect_(C.rad+0.45,90-120)
70 "svg_fsize(C,120)" at Rect_(C.rad+0.45,90-180)
71 "svg_fsize(B,120)" at Rect_(C.rad+0.45,90-240)
72 "svg_fsize(M,120)" at Rect_(C.rad+0.45,90-300)
73 linethick_(0)
74
75 for t = 1 to 90 do {
76 hsvtorgb(t/90*360,1,1,r,g,b)
77 line shaded svgcolor(r,g,b) outlined svgcolor(r,g,b) \
78 from C to Rect_(C.rad-0.05,90-(t-0.5)/90*360) \
79 then to Rect_(C.rad-0.05,90-(t+0.5)/90*360) \
80 then to C
81 }
82
83 R: circle diam C.rad at Rect_(C.rad*3/8,90) color "rgb(255,0,0)"
84 G: circle diam C.rad at Rect_(C.rad*3/8,-30) color "rgb(0,255,0)"
85 B: circle diam C.rad at Rect_(C.rad*3/8,-150) color "rgb(0,0,255)"
86
87 RG: cintersect(R,R.rad,G,G.rad)
88 GR: cintersect(R,R.rad,G,G.rad,R)
89 GB: cintersect(G,G.rad,B,B.rad)
90 BG: cintersect(G,G.rad,B,B.rad,R)
91 BR: cintersect(B,B.rad,R,R.rad)
92 RB: cintersect(B,B.rad,R,R.rad,R)
93
94 # The following could be done other ways depending on the postprocessor
95 `define lozenge {
96 arc from $1$2 to $2$1 with .c at $2
97 arc from $2$1 to $1$2 with .c at $1 }'
98
99 # yellow
100 linethick = 0.1; rgbfill(255,255,0,lozenge(R,G))
101 linethick = 0.4; rgbdraw(255,255,0,lozenge(R,G))
102
103 # cyan
104 linethick = 0.1; rgbfill(0,255,255,lozenge(G,B))
105 linethick = 0.4; rgbdraw(0,255,255,lozenge(G,B))
106
107 # magenta
108 linethick = 0.1; rgbfill(255,0,255,lozenge(B,R))
109 linethick = 0.4; rgbdraw(255,0,255,lozenge(B,R))
110
111 `define white {
112 arc cw from RB to GR with .c at R
113 arc cw from GR to BG with .c at G
114 arc cw from BG to RB with .c at B }'
115 linethick = 0.1; rgbfill(255,255,255,white)
116 linethick = 0.4; rgbdraw(255,255,255,white)
117 setrgb(255,255,255)
118 line from RB to GR then to BG then to RB
119 resetrgb
120
121 ] with .w at Worm.e+(0.5,0)
122
123 .PE