%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Some MetaPost figures by Anthony Phan. % file: wordtree.mp (version 0.0) % last modification: january 18, 2003. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Licence? Feel-free-to-send-me-a-postcard % % Anthony Phan, % % D\'epartement de Math\'ematiques, % SP2MI, T\'el\'eport 2, % Boulevard Marie et Pierre Curie, % BP 30179, % F-86962 Futuroscope-Chasseneuil cedex. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Setting % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% labeloffset:=2pt; pickup pencircle scaled 0.2pt; thin.nib := savepen; pickup pencircle scaled 0.4pt; rule.nib := savepen; pickup pencircle scaled 0.6pt; thick.nib := savepen; picture wpict, lpict; string lettersuffix, tmpstring; color graphcolor, leafcolor; defaultfont:="cmtt10"; graphcolor=black; leafcolor=black; lettersuffix=""; wpict := "o" infont defaultfont scaled defaultscale; uw := xpart urcorner wpict-xpart ulcorner wpict; uh := 0.5(xpart urcorner wpict-xpart ulcorner wpict); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Macros % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% def labelize(expr t, z_, z__, z___) = if picture t: lpict := t; else : lpict = t infont defaultfont scaled defaultscale; fi a_ := ((angle(z__-z_)+90) mod 180)-90; draw lpict shifted (-0.5(xpart urcorner lpict-xpart ulcorner lpict), if dir(a_+90) dotprod (z__-z___)>0: labeloffset-ypart llcorner lpict else: -ypart ulcorner lpict-labeloffset fi) rotated a_ shifted 0.5[z_, z__] enddef; def wordtree(suffix $)(expr s, t, w, zdir) = if length lettersuffix > 0: tmpstring:=for i = 1 upto length s: substring (i-1, i) of s & lettersuffix if i < length s: & fi endfor; wpict := tmpstring infont defaultfont scaled defaultscale; else: wpict := s infont defaultfont scaled defaultscale; fi draw wpict shifted (z$ - (0.5(xpart urcorner wpict-xpart ulcorner wpict),0) +((0.5length s*(1+length lettersuffix)*uw+labeloffset)*xpart zdir, -uh+0.5(10pt+2labeloffset)*ypart zdir)) withcolor leafcolor; x$' := x$+(length s*(1+length lettersuffix)*uw+2labeloffset)*xpart zdir; y$' := y$+(10pt+2labeloffset)*ypart zdir; if length s > 1 : x$a := x$'+w*(xpart zdir-t*abs(ypart zdir)); y$a := y$'+w*(t*abs(xpart zdir)+ypart zdir); draw z$'..z$a withcolor graphcolor; x$b := x$'+w*(xpart zdir+t*abs(ypart zdir)); y$b := y$'+w*(-t*abs(xpart zdir)+ypart zdir); draw z$'..z$b withcolor graphcolor; labelize(btex $\scriptstyle -1$ etex, z$', z$a, z$b) withcolor graphcolor; wordtree($a, cutword(s, -1), 0.5t, w, zdir); labelize(btex $\scriptstyle +1$ etex, z$', z$b, z$a) withcolor graphcolor; wordtree($b, cutword(s, 1), 0.5t, w, zdir); fi enddef; def swaparrow(suffix $) = drawdblarrow 2/3abs(0.5(z$a+z$b)-z$')*unitvector(z$a-z$')+z$' ...2/3(0.5(z$a+z$b)-z$')+z$'{z$b-z$a}... 2/3abs(0.5(z$a+z$b)-z$')*unitvector(z$b-z$')+z$' withcolor graphcolor enddef; def swaplabel(suffix $)(expr t) = if picture t: lpict := t; else : lpict = t infont defaultfont scaled defaultscale; fi draw lpict shifted (-2*(0.5[urcorner lpict, llcorner lpict]) +((bbox lpict) intersectionpoint (0.5[urcorner lpict, llcorner lpict].. 0.5[urcorner lpict, llcorner lpict]+ 10cm*unitvector(0.5(z$a+z$b)-z$'))) +(2/3abs(0.5(z$a+z$b)-z$')+labeloffset) *unitvector(0.5(z$a+z$b)-z$')+z$') withcolor leafcolor enddef; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Figures % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Remove one half of the word s % depending on the sign of x. % def cutword(expr s, x) = if x < 0 : substring (0, floor(length s/2)) of s else : substring (floor(length s/2), length s) of s fi enddef; graphcolor:=(139/255, 115/255, 85/255); leafcolor:=(34/255, 139/255, 34/255); beginfig(1); pickup rule.nib; z1=origin; lettersuffix:="'"; wordtree(1,"abcd", 1, 1cm, right); z2=z1+2(0.5[z1a.a',z1b.b']-z1)+1cm*unitvector(0.5[z1a.a',z1b.b']-z1); lettersuffix:=ditto; wordtree(2,"abcd", 1, 1cm, left); draw z1a.a'..z2a.a' withcolor graphcolor; draw z1a.b'..z2a.b' withcolor graphcolor; draw z1b.a'..z2b.a' withcolor graphcolor; draw z1b.b'..z2b.b' withcolor graphcolor; swaparrow(1) withcolor 0.75red; swaplabel(1, btex $\tau'$ etex) withcolor 0.75blue; swaparrow(1a) withcolor 0.75red; swaplabel(1a, btex $\tau'$ etex) withcolor 0.75blue; swaparrow(2) withcolor 0.75red; swaplabel(2, btex $\tau''$ etex) withcolor 0.75blue; swaparrow(2a) withcolor 0.75red; swaplabel(2a, btex $\tau''$ etex) withcolor 0.75blue; endfig; lettersuffix:=""; % % Remove the first or the last letter of the word s % depending on the sign of x. % def cutword(expr s, x) = if x < 0 : substring (1, length s) of s else : substring (0, length(s) - 1) of s fi enddef; beginfig(2); pickup rule.nib; z1=origin; wordtree(1,"abcdef", 3, 1cm, down); swaparrow(1); swaplabel(1, btex $\tau$ etex); swaparrow(1a); swaplabel(1a, btex $\tau$ etex); swaparrow(1a.a); swaplabel(1a.a, btex $\tau$ etex); swaparrow(1a.a.b); swaplabel(1a.a.b, btex $\tau$ etex); swaparrow(1a.b.b.a); swaplabel(1a.b.b.a, btex $\tau$ etex); endfig; end.