Debian Codegraph @

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

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