\input blue.tex \loadindexmacros \report \hfuzz=25pt \newif\ifmac \macfalse%\mactrue \ifmac\def\smiley{\cs{S}}\let\sadsmiley\smiley \else \loadsmileys \unitlength.2pt\unitlengthy.2pt\unitlengthx.2pt \fi \bluechapter Pictures \beginsummary \bluetex{} contains graphics facilities collected from \TB, manmac and gkpmac. The gkpmac picture macros provide a subset of La\TeX's functionality. I introduced a database of pictures to cooperate with \TeX. Two main issues have been addressed: using a picture from the picturebase, and creating a picture. No interaction with META\-FONT (or META\-post) nor the incorporation of encapsulated Post\-Script have been treated. As appetizer a section about turtle graphics and fractals has been inserted. \endsummary \bluepictures \bluemodelpic \flowchartlooppic \furutapic \linespic \ntgpiepic \ovalpic \overviewtexpic \sgmltexpic \simplepic\systemtheorypic \bintreepic\chartpic\cantordustpic\dragonpic \hfractalpic\kochfractalpic\levyfractalpic \pythpic\pythtreepic\rotatedbintreepic \sierpinskitripic\spiralpic \trimodelpic\tritreepic\windpic \bluehead Introduction \bluetex{} allows pictures to be used from the picture database pic.dat. For creating pictures the turtle graphics approach\Dash the graphics body language\Dash manmac's \cs{makeblankbox}\Dash \TeX's boxing approach\Dash and gkpmac's (distilled from \LaTeX) picture environment\Dash Descartes coordinate approach\Dash are detailed with.\ftn{% {\smc METAfont} or {\smc Metapost} are not part of \bluetex, nor is the use of encapsulated {\smc PostScript} considered. BLUe's format approach entails a high degree of portability at the expense of creating picturebase entries for reuse, which can be tedious.} The three ways of creating pictures are loosely connected. \bluehead The roots In \TB{} Appendix D, Knuth states \beginquote \llap{`}\TeX{} is designed to put boxes together either horizontally or vertically, not diagonally. But that is not a serious limitation, because the use of negative spacing makes it possible to put things anywhere on the page.' \endquote Let us start with \cs{putatxy}, to put a dot\Dash a small \cs{hrule}\Dash in the position $(x, y)$ relative to the reference point, and exercise a little `^{pointillisme} en \TeX.' I defined \cs{x} and \cs{y} as dimen variables. \beginverbatim \def\putatxy{\hbox to0pt{\kern\x \vbox to0pt{\vss\hrule width.3pt\kern\y}\hss}} !endverbatim \blueexample Sierpi\'nski carpets, via gambling ^^{Sierpi\'nski carpet} These carpets display the point sets which emerge when we `average' a point $k$ with an arbitrary corner of the (enclosing) polygon to obtain point $k+1$, $\forall k$.\ftn{Courtesy Alan Hoenig.} \bgroup %Hoenig's probabilistic/stochastic fractal, Sierpinski's carpets, TUGboat 1989. %Point set defined by the sequence %(x,y)_{k+1} := [(x, y)_k + `a corner at random']/(n-1), k = 0, 1, ... , % n number of corners %cgl@rc.service.rug.nl June 1995. %\newdimen\unitlength %\newcount\k \newcount\kmax %\newcount\throw \newcount\nmone %\newdimen\x\newdimen\y \newdimen\xi \newdimen\yi \newdimen\xii \newdimen\yii \newdimen\xiii \newdimen\yiii \newdimen\xiv \newdimen\yiv \newdimen\xv \newdimen\yv \def\nextpoint{\throwdie \advance\x\ifcase\throw \xi\or\xii\or\xiii\or\xiv\or\xv\fi \advance\y\ifcase\throw \yi\or\yii\or\yiii\or\yiv\or\yv\fi \divide\x\nmone \divide\y\nmone } \def\putatxy{\hbox to0pt{\kern\x \vbox to0pt{\vss\hrule width.3pt\kern\y }\hss}} %blue.tex contains \dieiii, \dieiv, \diev, next to \rnd %\def\dieiii{\rnd\throw= % \ifnum\rndval<34 0\else % \ifnum\rndval<67 1\else2 % \fi\fi} \unitlength.1pt %Scale factor \null\kern700\unitlength %v-positioning $$\hbox to4cm{\unitlength.075pt \k0 \kmax=500 \x500\unitlength \y500\unitlength %Initial point \nmone2 \xi0pt \yi0pt %Corners \xii1000\unitlength \yii0pt \xiii500\unitlength \yiii1000\unitlength \let\throwdie\dieiii \loop \nextpoint \putatxy \advance\k1 \ifnum\k<\kmax \repeat \hss}\hbox to4.25cm{\unitlength.15pt \k0 \kmax400 \x500\unitlength \y500\unitlength %Initial point \nmone3 \xi0pt \yi0pt %Corners \xii1000\unitlength \yii0pt \xiii1000\unitlength \yiii1000\unitlength \xiv0pt \yiv1000\unitlength \let\throwdie\dieiv \loop \nextpoint \putatxy \advance\k1 \ifnum\k<\kmax \repeat \hss}\hbox to2cm{\unitlength.045pt \k0 \kmax=400 \x500\unitlength \y500\unitlength %Initial point \nmone4 \xi0pt \yi0pt %Corners \xii3000\unitlength \yii0pt \xiii4000\unitlength \yiii2800\unitlength \xiv1500\unitlength \yiv5000\unitlength \xv-1000\unitlength \yv2800\unitlength \let\throwdie\diev \loop \nextpoint \putatxy \advance\k1 \ifnum\k<\kmax \repeat \hss}$$ \kern70\unitlength \egroup Amazing isn't it? The figures are essentially obtained via\ftn{For the coding details consult the file pwt.grf.} \thisverbatim{\unmc} \beginverbatim \loop \nextpoint \putatxy \advance\k1 \ifnum\k<\kmax \repeat !endverbatim The following more general \cs{point}, from \TB{} {\oldstyle389}, is the basis for \LaTeX's picture environment. \begincenterverbatim \hbox{\unitlength\baselineskip\point 0 0 \point 1 1.5 }%etc. %with \newdimen\unitlength \def\point#1 #2 {\rlap{\kern#1\unitlength\raise#2\unitlength\hbox{$ \scriptstyle\bullet\;(#1,#2)$}}} !endcenterverbatim The examples with quarter circles, \TB{} {\oldstyle389}--{\oldstyle390}, the dragon figures, remind me of Papert's `Turtle' graphics. The latter approach has been implemented by Gurari in `\TeX{} \& \LaTeX\Dash Drawing \& Literate Programming.' The displayed fractals below are small, of low order, because of the memory needed, and \TeX's limitations. However, the programs can be used stand-alone for larger orders. \everyverbatim{\unmc} \bluehead Turtle graphics digression ^^{Turtle graphics}% Knuth showed how to cope with turtle graphics in the infamous Appendix~D by the so-called dragon figures. Possibly because of the popularity of the \LaTeX{} picture environment next to the ubiquitous (PC) displays and laser printers, that is, raster and vector graphics, the Turtle graphics approach\Dash a turtle paints its movements, a pedagogical\ftn{See for example Seymour Papert's Mindstorms, which builds on the pedagogical principles of Piaget. Gurari has implemented a turtle graphics suite in Dra\TeX.} synonym for the pen of the plotter, very close to handdrawing\Dash has faded. For highly systematic pictures like (simple, deterministic) fractals,\ftn{Geometric figures in endless repetition. A teaser for WYSIWYG oriented people.} the turtle graphics approach can be beneficial.\ftn{Much of the work in this section was incented by Gurari's Drawings and Literate programming work. Details and algorithms for drawing fractals have been borrowed from Lauwerier's `Fractals\Dash meetkundige figuren in eindeloze herhaling.' (It contains programs in BASIC to draw the fractals.)} To quote Papert \begincenter `Turtle geometry is a {\em computationally\/} style of geometry.' \endcenter Let us concentrate on the four directions of the wind north, east, south, west, and I'll show what can be obtained by this. Then we will extend the movements to {\oldstyle45}$^\circ$ directions, i.e., the halfwinds northeast, southeast, southwest, and northwest. The argument of these wind directions is assumed to expand to a `factor,' i.e. an integer or decimal constant, see \TB{} {\oldstyle270} for the syntax of factor. The basic idea is that the position of the turtle is maintained in \cs{x}, \cs{y}, with the reference point left invariant. The accompanying figure shows the effect of \cs{N1}. % %Perhaps I better put it in pic.dat \vskip2.5\bigskipamount $$\unitlength.5ex \y=0pt\x-10\unitlength {\W{4}\E{40}}\S{4}% {\advance\y-2\unitlength\xytxt{ Ref.\ point}}% \N{20}\whiteE{20}\S4\whiteS4\xytxt{ (x,y)}$$ \vskip1.5\bigskipamount % The movements\Dash our first steps in the turtle graphics world\Dash can be achieved by the control sequences \bitem \cs{N}1 means: draw the line (\cs{x}, \cs{y}))\dash(\cs{x}, \cs{y}+1)), that is the turtle moves up. After completion \cs{y} has been increased by \cs{unitlength}. \bitem \cs{N}, \cs{E}, \cs{S}, \cs{W} mean draw north, east, south and west. \bitem \cs{whiteN}, \cs{whiteE}, \cs{whiteS}, \cs{whiteW} mean {\em white}-draw north, east, south and west, i.e., the turtle just moves. \smallbreak \blueexample A line bundle Important is that the length of the lines in each direction is given by the argument. This is in contrast with \LaTeX's (and gkp's) picture environment. \begindemo \thispicture{\unitlength5ex} $$\windpic$$ !yields \thispicture{\unitlength5ex} $$\windpic$$ \enddemo Let us look at an example, where \cs{E} is used only\Dash just moving in one direction\Dash to get the so-called Cantor dust ^{fractal}. \blueexample Cantor dust fractal ^^{Cantor dust fractal} ^^{Cantor dust fractal, two-dimensional} ^^{Sierpi\'nski carpet} The idea is that each line is replaced by its left and right third parts. In the picture the upper line is {\oldstyle243}pt, and the {\oldstyle32} lines at the bottom are each {\oldstyle1}pt. This pattern can be repeated yielding what is called a fractal.\ftn{\cs{cantordustpic} is included in pic.dat. Generalization to {\oldstyle2} dimensions yield the so-called Sierpi\'nski carpets. For example subdivide a square in $3^2$ equal subsquares and delete the middle, or the middle cross, and this repeatedly for the remaining squares. pic.dat contains \cs{sierpinskisquarepic} and \cs{sierpinskicrosspic}.} \begindemo \def\cf{{\E{\the\k}}\divide\k3 \ifnum\k=0 \fc\fi \advance\y-3\unitlength{\cf}% \advance\x\the\k\unitlength \advance\x\the\k\unitlength \cf\relax} \def\fc#1\relax{\fi} $$\k243 \unitlength1pt \x-\the\k\unitlength\divide\x2 \cf$$ %with auxiliary \def\E#1{\hbox to0pt{\kern\x \vbox to0pt{\vss\hrule width #1\unitlength\kern\y}\hss }\advance\x#1\unitlength} !yields \thispicture{\xoffset{10}} $$\cantordustpic$$ \enddemo The maze example of Salomon\Dash see also the Tabular Material chapter\Dash can be obtained straightforward as follows. \blueexample Maze ^^{Maze} \begindemo $$\unitlength3ex\x-2\unitlength\y0pt \N1\E2% \S1\W1\S2\E2\N1\W1% \whiteN1\E1\whiteN1\whiteW1% \E2\S4\W2\whiteW1\W1\N2$$ !yields $$\unitlength3ex\x-2\unitlength\y0pt \N1\E2\S1\W1% \S2\E2\N1\W1\whiteN1\E1\whiteN1\whiteW1%inner \E2\S4\W2\whiteW1\W1\N2$$ \enddemo \blueexample Spiral \begindemo $$\unitlength.5ex \y0pt \k30 \x-\the\k\unitlength\divide\x2 \loop\E{\the\k}\advance\k-1 \S{\the\k}\advance\k-1 \W{\the\k}\advance\k-1 \N{\the\k}\advance\k-1 \ifnum\k>4 \repeat$$ !yields $$\spiralpic$$ \enddemo The \cs{spiralpic} has been added to pic.dat. \exercise How can we let the turtle draw nested squares? \answer The nested squares can be obtained as follows. \beginverbatim $$\unitlength.5ex \k32 \loop\x-\the\k\unitlength \divide\x2 \y-\x \E{\the\k}\S{\the\k}\W{\the\k}\N{\the\k}% \advance\k-2 \ifnum\k>1 \repeat$$ !endverbatim %endanswer \blueexample Binary tree ^^{Binary tree} %Turtle-draw the binary (fractal) tree. %\def\bintree{\S1\ifnum\kk=2 \eertnib\fi % \divide\kk2 % {\W{\the\kk}\bintree}% % \E{\the\kk}\bintree\relax} %\def\eertnib#1\relax{\fi} \begindemo \def\bintree{\S1\ifnum\kk=2 \eertnib\fi \divide\kk2 {\W{\the\kk}\bintree}% \E{\the\kk}\bintree\relax} \def\eertnib#1\relax{\fi} $$\def\eertnib#1\relax{\fi} \unitlength.5ex\x0pt\y0pt \kk32 \bintree$$ !yields $$\bintreepic$$ \enddemo \exercise How can we add leaves? \answer To give you an idea how to add leaves the following. \beginverbatim \def\eertnib#1\relax{\fi\global\advance\k1 \whiteS3\trttxt{\hss\csname\the\k\endcsname}} %with \def\1{x} \def\2{y} %etc. !endverbatim %endanswer \bgroup \blueexample Rotated tree Once we understand turtle graphics, rotating a tree can be done easily via shifting the meaning of the directions, and adjusting positioning of the leaves.\ftn{A white lie. The tree is actually mirrored because I like the leaves to be numbered from the top. In general we can rotate via \PS.} %\def\bintree{\S1\ifnum\kk=2 \eertnib\fi % \divide\kk2 % {\W{\the\kk}\bintree}% % \E{\the\kk}\bintree\relax} \begindemo %rotation via shifting \let\W\S \let\S\E \let\E\N %the leaves \def\1{x}\def\2{y}\def\3{a}\def\4{b} \def\5{piet}\def\6{hans}\def\7{etc.} $$\k0\unitlength1ex\x0pt\y0pt \kk16\bintree$$ %with \def\eertnib#1\relax{\fi\global\advance\k1 \whiteS1\xytxt{ \csname\the\k\endcsname}} !yields $$\thispicture{\yoffset{-16}} \rotatedbintreepic$$ \enddemo \egroup Because of its usefulness the above \cs{bintree} and \cs{eertnib} are in blue.tex. %chart TB 22.14, 248 cgl@rc.service.rug.nl %\input blue.tex \report The chart example\Dash see also the Tabular Material chapter\Dash can be done too via a variant binary tree implementation. \bgroup\newcount\ewidth \blueexample Chart, \TB{} ex{\oldstyle22}.{\oldstyle14} {\oldstyle248} \begindemo %labels in preorder \def\1{LMB, 1912} \def\2{MJHB, 1882}\def\5{PAME, 1884} \def\3{JHB, 1838}\def\4{MDB, 1840} \def\6{EFE, 1845}\def\7{CLW, 1850} \ekk8\k0\unitlength2ex \x0pt\y0pt\kk8\hbox{\bintree} %with auxiliaries \def\bintree{\E{\the\ekk}% \ifnum\kk=2 \eertnib\fi \divide\kk2 {\N{\the\kk}\bintree}% \S{\the\kk}\bintree\relax} \def\eertnib#1\relax{\fi} % \let\Eold\E \def\E{\global\advance\k1 \trttext{ \csname\the\k \endcsname}\Eold} !yields \chartpic \enddemo \egroup Remark. An aid in finding the numbers of the branches is to delete \cs{csname} and \cs{endcsname} in \cs{E} . The traversal at hand is called preorder. % i.e., root, one branch (left or up), and %other branch (right or down), and this recursively. \vfill\eject \blueexample Trinary tree ^^{Trinary tree} Here we have to correct for the direction and also adjust the drawing element, which is a rectangular block of size $.348{\times}.2$pt. % \begindemo %ESE= east-south-east etc \def\tritree{\ifnum1=\level \eertirt\fi \advance\level-1 \divide\kk2 {\N{\the\kk}\tritree}% {\ESE{\the\kk}\tritree}% \WSW{\the\kk}\tritree\relax} \def\eertirt#1\relax{\fi} $$\x0pt\y0pt\level6 \kk128\tritree$$ !yields $$\N{128}\tritreepic$$ \enddemo Remark. The \cs{unitlength}s are default and equal to the sides of the elementary rectangular block. The size of the tree can be controlled by \cs{kk}. If the \cs{tritree} is preceded by |\N{128}| a Christmas tree will emerge. The picture is included in pic.dat with name \cs{tritreepic}. Remark. Another class of fractals\Dash the so-called star fractals\Dash emerge if the {\em change\/} of direction is constant, while the length of each step varies according to a regular pattern. These fractals can be drawn by one (broken) line and are therefore suited for the turtle graphics approach. %If not for the triangular case. Because these are memory intensive I have omitted an example. \bgroup \exercise How can we obtain the following ^{H-fractal}? $$\hfractalpic$$ \answer The H-fractal can be obtained via \thisverbatim{\unmc} \beginverbatim \let\0\N \let\1\E \let\2\S \let\3\W \newcount\dir \def\mod#1{\advance\dir#1 \ifnum3<\dir \advance\dir-4 \fi}%mod 4 \def\nxt{\csname\the\dir\endcsname{\the\kk}\multiply\kk17\divide\kk24 \advance\level-1 \hf} \def\hf{\ifnum\level=0 \fh\fi {\mod1\nxt}\mod3\nxt\relax} \def\fh#1\relax{\fi} $$\unitlength.1ex\x-10\unitlength\y0pt \kk48 \dir0 \level6 \hf$$ !endverbatim To use it is even simpler because it comes with pic.dat. %end answer \egroup \ifmac\vfill\eject\fi \exercise How can we get the following ^{Sierpi\'nski carpet} fractal? $$\sierpinskitripic$$ \answer The triangle can be obtained via \beginverbatim \def\triangle{\ifnum\kk=0 \elgnairt\fi {\N{\the\kk}}{\E{\the\kk}}\divide\kk2 {\triangle}% {\advance\x\the\kk\unitlength\triangle}% \advance\y\the\kk\unitlength\triangle\relax} \def\elgnairt#1\relax{\fi} $$\unitlength1ex\x-8\unitlength\kk16 \triangle$$ !endverbatim %end answer \bgroup \exercise How can we extend the turtle movements? For example to {\oldstyle45}$^\circ$ directions? Draw the following binary tree with these edges. \def\E#1{\hbox to0pt{\kern\x\vbox to0pt{\vss \hrule width#1\unitlengthx\kern\y }\hss}\advance\x#1\unitlengthx } \def\N#1{\yy\y \advance\y#1\unitlengthy \hbox to0pt{\kern\x \vbox{\hrule height\y depth-\yy width.2pt}\hss}} \def\W#1{\advance\x-#1\unitlengthx \hbox to0pt{\kern\x\vbox to0pt{\vss \hrule width#1\unitlengthx\kern\y }\hss}} \def\S#1{\yy\y \advance\y-#1\unitlengthy \hbox to0pt{\kern\x \vbox{\hrule height\yy depth-\y width.2pt}\hss}} % \font\tenln=line10 \setbox\nel=\hbox{\tenln\char'045} \setbox\nwl=\hbox{\tenln\char'145} \unitlengthy\ht\nel \unitlengthx\wd\nel \def\NE#1{\auxdim#1\unitlengthx \loop\advance\auxdim-\unitlengthx \hbox to0pt{\kern\x \vbox to0pt{\vss\copy\nel \kern\y}\hss}% \advance\x\unitlengthx\advance\y\unitlengthy \ifdim\auxdim>0pt \repeat} \def\NW#1{\auxdim#1\unitlengthx \loop\advance\auxdim-\unitlengthx \advance\x-\unitlengthx \hbox to0pt{\kern\x \vbox to0pt{\vss\copy\nwl \kern\y}\hss}% \advance\y\unitlengthy \ifdim\auxdim>0pt \repeat} % \def\tree{\ifnum\kk=1 \eert\fi \N1 \divide\kk2 {\NW{\the\kk}\tree}% \NE{\the\kk}\tree\relax} \def\eert#1\relax{\fi} \bigskip $$\x0pt \y0pt \kk4 \tree$$ \answer We can extend it in a limited sense by using two lines from \LaTeX's line fonts. \thisverbatim{\unmc} \beginverbatim Draw the following binary tree with these edges. \def\E#1{\hbox to0pt{\kern\x\vbox to0pt{\vss \hrule width#1\unitlengthx\kern\y }\hss}\advance\x#1\unitlengthx } \def\N#1{\yy\y \advance\y#1\unitlengthy \hbox to0pt{\kern\x \vbox{\hrule height\y depth-\yy width.2pt}\hss}} \def\W#1{\advance\x-#1\unitlengthx \hbox to0pt{\kern\x\vbox to0pt{\vss \hrule width#1\unitlengthx\kern\y }\hss}} \def\S#1{\yy\y \advance\y-#1\unitlengthy \hbox to0pt{\kern\x \vbox{\hrule height\yy depth-\y width.2pt}\hss}} % \font\tenln=line10 \setbox\nel=\hbox{\tenln\char'045} \setbox\nwl=\hbox{\tenln\char'145} \unitlengthy\ht\nel \unitlengthx\wd\nel \def\NE#1{\auxdim#1\unitlengthx \loop\advance\auxdim-\unitlengthx \hbox to0pt{\kern\x \vbox to0pt{\vss\copy\nel \kern\y}\hss}% \advance\x\unitlengthx\advance\y\unitlengthy \ifdim\auxdim>0pt \repeat} \def\NW#1{\auxdim#1\unitlengthx \loop\advance\auxdim-\unitlengthx \advance\x-\unitlengthx \hbox to0pt{\kern\x \vbox to0pt{\vss\copy\nwl \kern\y}\hss}% \advance\y\unitlengthy \ifdim\auxdim>0pt \repeat} % \def\tree{\ifnum\kk=1 \eert\fi \N1 \divide\kk2 {\NW{\the\kk}\tree}% \NE{\the\kk}\tree\relax} \def\eert#1\relax{\fi} \bigskip $$\x0pt \y0pt \kk4 \tree$$ !endverbatim The better approach is to adhere to {\em square\/} atom elements, which is adopted in BLUe's format turtle graphics. %end answer \egroup The picture at the beginning of this section about the turtle movement could easily have been obtained via gkppic. Via turtle graphics the markup reads as follows. \beginverbatim \def\N{...}\def\E{...}\def\S{...}\def\W{...} %white writing i.e. just move, don't draw \def\whiteE#1{\advance\x#1\unitlength}%etc \vskip2.5\bigskipamount $$\unitlength.5ex \y=0pt\x-10\unitlength{\W{4}\E{40}}\S{4}% {\advance\y-2\unitlength\xytxt{ Ref.\ point}}% \N{20}\whiteE{20}\S4\whiteS4\xytxt{ (x,y)}$$\vskip1.5\bigskipamount !endverbatim Prompted by the above the turtle movements are extended to the directions of the wind and the halfwind. \vfill\eject \blueexample Pythagorean tree With the above directions\Dash and a little more especially when the lines are getting smaller and smaller\Dash we can obtain the classical ^{Pythagorean fractal}s. \begindemo \def\pythtree{\ifnum1=\level\eerthtyp\fi \advance\level-1 \multiply\kk23\divide\kk32 {\leftbranche\draw\pythtree}% \rightbranche\draw\pythtree\relax} \def\eerthtyp#1\relax{\fi} $$\unitlength.2pt\x0pt \y0pt \level7 \dir0 \kk90 \N{\the\kk} \pythtree$$ %with auxiliaries \let\0\N \let\1\NE etc. \def\leftbranche{\advance\dir7 \ifnum\dir>7 \advance\dir-8 \fi} \def\rightbranche{\advance\dir1 etc.} \def\draw{\csname\the\dir\endcsname {\the\kk}} !yields $$\pythtreepic$$ \enddemo \bgroup \exercise How can we get the asymmetric Pythagorean trees? \answer The asymmetric Pythagorean trees can be obtained as follows. \beginverbatim \input blue.tex \report \def\asympythtree{\ifnum\level=1 \eerthtyp\fi \advance\level-1 {\multiply\kk3 \divide\kk5 \leftbranche \draw\asympythtree}% \multiply\kk5 \divide\kk6 \rightbranche\draw\asympythtree\relax} \def\eerthtyp#1\relax{\fi} %with auxiliaries \let\0\N \let\1\NE \let\2\E \let\3\SE \let\4\S \let\5\SW \let\6\W \let\7\NW \def\draw{\csname\the\dir\endcsname{\the\kk}} \def\leftbranche{\advance\dir7 \ifnum\dir>7 \advance\dir-8 \fi}%mod 8 \def\rightbranche{\advance\dir1 \ifnum\dir>7 \advance\dir-8 \fi}%mod 8 % \unitlength0.2ex $$\x20\unitlength \y0pt \level9\dir0 \kk50 \N{\the\kk} \asympythtree$$ %\level9 \kk50 needed 60K of memory %\level10 \kk50 needed 95K of memory %$$\x20\unitlength \y0pt \level10 \dir0 \kk60 \N{\the\kk} \asympythtree$$ \tracingstats1 \bye !endverbatim %endanswer \egroup \ifmac\vfill\eject\fi \blueexample Pythagorean fractal with squares The Pythagorean fractal with squares is more complex, because of how the turtle should draw the left and right squares. \begindemo $$\unitlength0.2ex \kk20 \rightx\the\kk\unitlength \divide\rightx2 \x-\rightx \y0pt \level5 \pyth$$ \let\drawsq\ldrawsq \def\pyth{\ifnum\level=1 \htyp\fi \drawsq\advance\level-1 \multiply\kk18\divide\kk25 {\turn7\x\leftx \y\lefty \let\drawsq\ldrawsq\pyth}% \turn1\x\rightx \y\righty \let\drawsq\rdrawsq\pyth\relax} \def\htyp#1\relax{\fi} !yields $$\thispicture{\xoffset{10}}\pythpic$$ \enddemo The Pythagorean pictures have been added to pic.dat with names \cs{pythtreepic}, and \cs{pythpic}. \ifmac\vfill\eject\fi \blueexample Minkowski sausage \bgroup ^^{Minkowski sausage} This fractal emerges from replacing repeatedly a line by a block-wave, i.e., \dir1 \kk4 \unitlength1ex \hbox{\x0pt\y0pt {\E4}\kern5\unitlength$\longrightarrow$% \kochfractalpic \kern5\unitlength}. \thisverbatim{\unmc} \begindemo \def\koch{\ifnum\kk=1 \draw\hcok\fi {\divide\kk4 \koch\left\koch\right\koch\right\koch\koch \left\koch\left\koch\right\koch}\relax} \def\hcok#1\relax{\fi} % $$\x0pt\y0pt\dir1 \kk4 \koch$$ $$\x0pt\y0pt\dir1 \kk16 \koch$$ %with auxiliaries \def\left{\advance\dir3 \ifnum\dir>3 \advance\dir-4 \fi} \def\right{\advance\dir1 \ifnum\dir>3 \advance\dir-4 \fi} \def\draw{\csname\the\dir\endcsname1} !yields \def\draw{\csname\the\dir\endcsname1} $$\x0pt\y0pt\dir1 \kk4 \kochfractalpic$$ $$\thispicture{\kk16 \ydim{10}\yoffset{-5}} \kochfractalpic$$ \enddemo \egroup \ifmac\vfill\eject\fi \blueexample L\'evy fractal ^^{L\'evy fractal} This fractal emerges from replacing repeatedly a line by a roof. Two replacements in a row have the effect of a line replaced by a hat, i.e., \unitlength1ex \hbox{\x0pt\y0pt {\E2}\kern3\unitlength$\longrightarrow\,$\ {\N1\E2\S1}\kern3\unitlength }. As shown by Lauwerier we don't need recursion to obtain the regular patterns. Just a little (ahummm, \smiley) analysis might yield the following. \thisverbatim{\unmc} \begindemo \def\levyfractal{\loop \summodfour \draw \advance\k1 \ifnum\k<\order \repeat} $$\unitlength1ex\x0pt\y0pt \k0 \dir0 \order256 \levyfractal$$ %with auxiliaries \let\0\E\let\1\S\let\2\W\let\3\N % \def\summodfour{{\modsum0 \loop \ifodd\k \advance\modsum1 \fi \divide\k2 \ifnum\k>0 \repeat \global\dir\modsum \divide\modsum4 \multiply\modsum4 \global\advance\dir-\modsum}} \def\draw{\csname\the\dir\endcsname \the\kk} !yields $$\let\0\E\let\1\S\let\2\W\let\3\N \levyfractalpic$$ \enddemo \blueexample Dragon figures To conclude this digression a simplified variant of Knuth's dragon figure, \TB{} {\oldstyle391}. Just straight lines as used in the original {\em dragon\/} figures of Heighway. The figures emerge when we repeatedly fold a slip of paper\Dash double, double etc.\Dash and then unfold it. The change of the directions of the line elements obey a regular pattern. Because of this we can draw the curve starting from the first element and calculate the directions for the subsequent elements. \thisverbatim{\unmc} \begindemo \def\dragon{\k0 \loop \draw \advance\k1 \kk\k \calcdir \ifnum\k<\kmax \repeat} \unitlength2ex $$\dir0\x0pt\y0pt \kmax4 \dragon$$ $$\dir0\x0pt\y0pt \kmax64 \dragon$$ !yields \unitlength2ex $$\dragonpic$$ $$\thispicture{\kmax64 \ydim{7}\yoffset{-4}} \dragonpic$$ \enddemo \exercise How can we draw curves, for example a spline relative to the reference point? \answer Quintic spline \TeX nique. gkppic provides \cs{squines}, which is the quadratic variant of the \cs{mfs} given below. Another promising approach is given by Gurari's work `\TeX{} \& \LaTeX--- Drawing \& Literate programming,' especially the (Al)Dra\TeX{} macros. Within the \cs{Draw}\dots\cs{EndDraw} environment among other things Bezier curves can be drawn via \cs{Curve($p_1, q_1, q_2, p_2$)}. However, I have provided \cs{mfs} a macro which provides for the spline as given in {\it The METAfont\/} book. %\MFB. \beginverbatim %\mfs macro that creates a spline through %(x1, y1), (x4, y4) with control points %(x2, y2), (x3, y3). %The method is the same as given in the METAfont book, p13. %\S means the southbound moving in turtle graphics. %As examples some smileys are added. %cgl@rc.service.rug.nl, July 1995 \let\loadsmileys\relax%\input blue.tex \let\ea\expandafter \newdimen\unitlength \newdimen\x \newdimen\y \newdimen\yy \newcount\k \newcount\kmax \ea\newdimen\csname X1\endcsname \ea\newdimen\csname X2\endcsname \ea\newdimen\csname X3\endcsname \ea\newdimen\csname X4\endcsname \ea\newdimen\csname X12\endcsname \ea\newdimen\csname X23\endcsname \ea\newdimen\csname X34\endcsname \ea\newdimen\csname X123\endcsname \ea\newdimen\csname X234\endcsname \ea\newdimen\csname X1234\endcsname \def\X#1{\csname X#1\endcsname} % \ea\newdimen\csname Y1\endcsname \ea\newdimen\csname Y2\endcsname \ea\newdimen\csname Y3\endcsname \ea\newdimen\csname Y4\endcsname \ea\newdimen\csname Y12\endcsname \ea\newdimen\csname Y23\endcsname \ea\newdimen\csname Y34\endcsname \ea\newdimen\csname Y123\endcsname \ea\newdimen\csname Y234\endcsname \ea\newdimen\csname Y1234\endcsname \def\Y#1{\csname Y#1\endcsname} % \newbox\smileybox %Next the METAfont spline implementation \def\mfs{\ifnum\k=\kmax \sfm\fi \advance\k1 \midpoints\x\X{1234}\y\Y{1234}\putatxy {\X2\X{12}\X3\X{123}\X4\X{1234}% \Y2\Y{12}\Y3\Y{123}\Y4\Y{1234}\mfs}% {\X1\X{1234}\X2\X{234}\X3\X{34}% \Y1\Y{1234}\Y2\Y{234}\Y3\Y{34}\mfs}\relax}%end \mfs % \def\sfm#1\relax{\fi} % \def\midpoints{%z1,...,z4 -> z1, z12, z23,...,z1234 \X{12}\X1\advance\X{12}by\X2\divide\X{12}by2 \X{23}\X2\advance\X{23}by\X3\divide\X{23}by2 \X{34}\X3\advance\X{34}by\X4\divide\X{34}by2 \X{123}\X{12}\advance\X{123}by\X{23}\divide\X{123}by2 \X{234}\X{23}\advance\X{234}by\X{34}\divide\X{234}by2 \X{1234}\X{123}\advance\X{1234}by\X{234}\divide\X{1234}by2 % \Y{12}\Y1\advance\Y{12}by\Y2\divide\Y{12}by2 \Y{23}\Y2\advance\Y{23}by\Y3\divide\Y{23}by2 \Y{34}\Y3\advance\Y{34}by\Y4\divide\Y{34}by2 \Y{123}\Y{12}\advance\Y{123}by\Y{23}\divide\Y{123}by2 \Y{234}\Y{23}\advance\Y{234}by\Y{34}\divide\Y{234}by2 \Y{1234}\Y{123}\advance\Y{1234}by\Y{234}\divide\Y{1234}by2 } %\putatxy already in blue.tex \def\putatxy{\hbox to0pt{\kern\x\kern-.15pt \vbox to0pt{\vss\hrule width.3pt height.3pt\relax \kern\y}\hss}} % \def\S#1{\yy\y \advance\y-#1\unitlength \hbox to0pt{\kern\x \vbox{\hrule height\yy depth-\y width.2pt}\hss}} % \def\initialize#1#2#3#4#5#6#7#8{%points: (#1,#2),...(#7,#8) \csname X1\endcsname#1\unitlength \csname X2\endcsname#3\unitlength \csname X3\endcsname#5\unitlength \csname X4\endcsname#7\unitlength \csname Y1\endcsname#2\unitlength \csname Y2\endcsname#4\unitlength \csname Y3\endcsname#6\unitlength \csname Y4\endcsname#8\unitlength} % % \def\eyes{{\x250\unitlength\y150\unitlength \putatxy}%l-eye {\x750\unitlength\y150\unitlength \putatxy}%r-eye } \def\lefteyes{{\x200\unitlength\y150\unitlength \putatxy}%l-eye {\x700\unitlength\y150\unitlength \putatxy}%r-eye } \def\squinteyes{{\x300\unitlength\y150\unitlength \putatxy}%l-eye {\x700\unitlength\y150\unitlength \putatxy}%r-eye } \def\winkeye{\initialize{100}{150}{250}{75}{250}{75}{400}{150}% {\k0\kmax2\x0pt\y0pt\mfs}%l-winkeye {\x750\unitlength\y150\unitlength \putatxy}%r-eye } \def\mouth{\initialize{250}{-250}{500}{-350}{500}{-350}{750}{-250}% \k0\x0pt\y0pt\mfs } \def\sadmouth{\initialize{250}{-350}{500}{-250}{500}{-250}{750}{-350}% \k0\x0pt\y0pt\mfs} % \kmax5 %level \setbox\smileybox=\hbox{\unitlength.01pt \initialize000{650}{1000}{650}{1000}0% \k0\putatxy\mfs \initialize 000{-650}{1000}{-650}{1000}0% \k0\mfs\y0pt\x\X4\putatxy \kmax3 \initialize{100}{200}{250}{250}{250}{250}{400}{200}% \k0\x0pt\y0pt\mfs%l-brow \initialize{600}{200}{750}{250}{750}{250}{900}{200}% \k0\x0pt\y0pt\mfs%r-brow {\x500\unitlength\y150\unitlength\S{250}}%Nose } \def\smiley{\loadsmileys\raise.5ex\hbox{\unitlength.01pt \copy\smileybox\eyes\mouth\kern1000\unitlength} } \def\winksmiley{\loadsmileys\raise.5ex\hbox{\unitlength.01pt \copy\smileybox\winkeye\mouth\kern1000\unitlength} } \def\sadsmiley{\loadsmileys\raise.5ex\hbox{\unitlength.01pt \copy\smileybox\squinteyes\sadmouth\kern1000\unitlength} } % $$pretext\ \smiley\ posttext$$ % $$pretext\ \winksmiley\ posttext$$ % $$pretext\ \sadsmiley\ posttext$$ \tracingstats1 \bye !endverbatim For the moment I'll stop `\dots fooling around making pictures, instead of typesetting ordinary text\dots' One thing is crystal clear, however. Fractals are a `mer \`a boire,' to exercise recursive programming, while on the outlook for straightforward alternatives. \everyverbatim{\emc} \bluehead Using pictures pic.dat contains definitions of prefab pictures. In order to use these, the picture must be loaded via\ftn{I use myself \cs{bluepictures}% $\cs{}\langle\,name_1\rangle\hbox{\tt pic}\dots \cs{}\langle\,name_n\rangle\hbox{\tt pic}$, followed by a blank line or \cs{par}. \smiley.} ^^|\beginpictures|%^^|\pictures| \begincenterblock \cs{beginpictures} $\cs{}\langle\,name_1\rangle\hbox{\tt pic}\dots% \cs{}\langle\,name_n\rangle\hbox{\tt pic}\qquad% \hbox{or}\qquad% \cs{pictures}\{\cs{}\langle\,name_1\rangle\hbox{\tt pic}\dots% \cs{}\langle\,name_n\rangle\hbox{\tt pic}\}$ \cs{endpictures} \endcenterblock After this each picture loaded can be used by its name, i.e., via the invocation \displaycenterline{$\cs{}\langle\,name_x\rangle\hbox{\tt pic}$} if necessary preceded by ^|\thispicture||{...}|, ^^|\everypicture| with actual values for ^|\unitlength|, and the offsets. The result is packed as an |\hbox to#1\unitlength{...}| with depth reset to zero. Note that although the picture database is a file of defs, alphabetically sorted on definition name, the names of the pictures to be selected can be supplied in any order to \cs{pictures}. \exercise What is the effect of |\pictures{}|? \answer The common-for-pictures macro, \cs{commonforpic}, is loaded, and invoked. The latter means that you can use for example the macros \cs{corners}, i.e., the macros which are common for several pictures, and these can be used over and over. \blueexample Simple picture \begindemo \thispicture{\markorigintrue} \simplepic !yields \thispicture{\markorigintrue} \qquad\qquad\qquad\qquad\simplepic \enddemo \bluesubhead Pictures from tools.dat The database of tools also contains pictures especially my PMS, i.e.\ poor man's smileys. \blueexample Smileys \begindemo \input blue.tex \centerline{\smiley\quad \sadsmiley\quad \winksmiley} !yields \centerline{\smiley\quad \sadsmiley\quad \winksmiley} \enddemo Similar for \cs{ntglogo} and \cs{xyz}-axes. \vfill\eject \bluehead Creating pictures I'll discuss two approaches: one for simple schemes, and the ^{picture environment} as used by Graham, Knuth, and Pastashnik. \bluesubhead Stacking boxes For simple schemes we can use ^{framed boxes}. \bluetex{} provides \begincenterverbatim \def\fbox#1{\setbox0\hbox{\strut$\;$#1$\,$}\leavevmode \rlap{\copy0}\makeblankbox{.2pt}{.2pt}} !endcenterverbatim The idea is that the argument is set in box 0. This box is framed by manmac's \cs{makeblankbox}. \blueexample Simple scheme \begindemo \stack{\fbox{amsppt.sty}} \vconnector \stack{\fbox{amstex.tex}} \vconnector \stack{\fbox{\TeX}}} %with \def\stack#1{\hbox to10ex{\hss #1\hss}} \def\vconnector{\stack{\vrule height2.5exdepth1exwidth.2pt}} !yields\qquad\qquad\qquad\qquad\qquad \vbox{\offinterlineskip \def\stack#1{\hbox to 10ex{\hss#1\hss}} \def\vconnector{\stack{\vrule height2.5exdepth1exwidth.2pt}} \stack{\fbox{amsppt.sty}} \vconnector \stack{\fbox{amstex.tex}} \vconnector \stack{\fbox{\TeX}}} \enddemo \bluesubhead Samplebox diversions A lot of details can be learned from Knuth's markup of the \cs{samplebox} picture, \TB{} chapter {\oldstyle11}: composing long vertical arrows, to measure the axis height, samplebox coding. For daily use this markup is too cumbersome. However, the ^|\samplebox| macro is amply used in \TB{} chapter {\oldstyle12}. \blueexample Manmac's samplebox Knuth attaches three dimensions to these boxes: height, width, and depth. \begindemo %Vertical arrows, similar to %\arrows, but now vertically. \setbox0=\hbox{$\uparrow$} \setbox1=\hbox to \wd0{$\hss\mid \hss$}%with luck,they'll line up \def\vline{\nointerlineskip \kern-.5pt\copy1} \setbox2=\vbox{\copy0 \vline\vline \moveleft 1em\hbox{height} \copy1\vline \nointerlineskip\kern-.5pt \hbox{$\downarrow$}\kern.2pt} %To measure axis height %\ht0 is the axis height \setbox0=\hbox{$\vcenter{}$} !yields \qquad\vbox{\eightpoint \setbox0=\hbox{$\uparrow$} \setbox1=\hbox to \wd0{$\hss\mid\hss$} % with luck, they'll line up \setbox2=\vbox{\copy0 \nointerlineskip \kern-.5pt \copy1 \nointerlineskip \kern-.5pt \copy1 \moveleft 1em\hbox{height} \copy1 \nointerlineskip \kern-.5pt \copy1 \nointerlineskip \kern-.5pt \hbox{$\downarrow$} \kern.2pt} \setbox3=\vbox{\kern.2pt\copy0 \moveleft 1em\hbox{depth} \hbox{$\downarrow$} \kern0pt} \setbox4=\vtop{\kern-3pt % this cancels the null text above the samplebox \hbox{\samplebox{\ht2}{\ht3}{6em}{}% \kern-6em \raise3pt\hbox to 6em{\hss Baseline\hss}} \kern3pt \arrows{6em}{width}} \medskip\indent \setbox0=\hbox{$\vcenter{}$}% \ht0 is the axis height \lower\ht0\hbox{Reference point$-$\kern-.2em$\rightarrow$\kern2pt}% \raise\ht2\box4 \kern1.5em \raise\ht2\vtop{\kern0pt\box2\nointerlineskip\box3}} \enddemo From the above I distilled the following ^|\gbox| macro\Dash generalized samplebox\Dash which draws a box similar to sample box, with depth, height and width, and a hook to put in material relative to the reference point. This is a generalization of a framed box, because the frame has its own dimensions independent of the material to be framed. In order to be in full control of the positioning of the elements, I chose the parameters ^|\xshift| and ^|\yshift|\Dash dimen vars\Dash to shift material relative to the reference point. %The above used with |\setbox=\hbox{}| and %\cs{makelightbox} can put elements anywhere within a framed box. %For the framing I used \cs{gbox} a modification of \cs{samplebox}. \blueexample Generalized samplebox macro \begindemo pretext \xshift1ex \yshift2ex \gbox{7ex}{3ex}{5ex}{abc} posttext %with the generalized sample box \def\gbox#1#2#3#4{%#1=ht,#2=dp %#3=wd, #4=text. %Assumed: the dimen vars \xshift, %\yshift have been initialized. {\setbox0=\vtop{\vbox to#1{% \hbox to#3{}\vss} \nointerlineskip \vbox to#2{}} %now \box0 has the desired %ht, dp, and wd \hbox{\makelightbox\kern-#3% \raise\yshift\hbox to#3{% \kern\xshift#4\hss}}}} !yields \def\gbox#1#2#3#4{%#1=ht,#2=dp,#3=wd %#4=text. Assumed: the dimen vars %\xshift, \yshift have been initialized. %position of begin of text. {\setbox0=\vtop{\vbox to#1{% \hbox to#3{}\vss}\nointerlineskip \vbox to#2{}} %now \box0 has the desired %ht, dp, and wd \hbox{\makelightbox\kern-#3% \raise\yshift\hbox to#3{% \kern\xshift#4\hss} }}} \qquad\qquad\qquad pretext \xshift1ex \yshift2ex \gbox{7ex}{3ex}{5ex}{abc} posttext \enddemo The markup of the picture of astronomy data, \TB{} {\oldstyle389}, can be simplified. Also ^|\point| can be generalized as follows. \def\ftntxt{\cs{prepoint}=$\{$\$\cs{scriptstyle} \cs{bullet}\cs{;}\$$\}$ was hardwired in \TB.} \begincenterverbatim \def\point#1 #2 #3{\kern#1\unitlength\raise#2\unitlength\hbox to0pt{\the\prefil \the\prepoint#3\the\postfil}\kern-#1\unitlength} %with parameters \prepoint to allow material to be inserted (toks var)!ftn!bgroup!ftntxt!egroup \prefil to insert the fill (toks var) \postfil to insert the fill (toks var, default \hss) !endcenterverbatim \blueexample Atlas \TB{} {\oldstyle389} Use \cs{gbox} of the right size with the data in a box. {\prepoint{$\scriptstyle\bullet\;$} \begindemo \unitlength3ex \prepoint{$\scriptstyle\bullet\;$} \setbox1= \hbox{\point 0 0 {Alioth} \point 0 8 {Dubhe} \point 0 -8 {Alkaid} \point -1 -2.5 {Miza} \point 4 7 {Merak} \point 4 2 {Phekda} \point 1 1.5 {Megrez} } \xshift2\unitlength pretext \gbox{10\unitlength}%height {9\unitlength} %depth {11\unitlength}%width {\copy1} %material posttext !yields %\newdimen\unitlength \unitlength=3ex \setbox1=\hbox{\point 0 0 {Alioth} \point 0 8 {Dubhe} \point 0 -8 {Alkaid} \point -1 -2.5 {Miza} \point 4 7 {Merak} \point 4 2 {Phekda} \point 1 1.5 {Megrez} } \xshift2\unitlength%\yshift0pt pretext \gbox{10\unitlength}%height {9\unitlength} %depth {11\unitlength}%width {\copy1} %material posttext \enddemo} \vfill\eject \blueexample Layout pages \cs{gbox} and \cs{point} can be combined for drawing a rough design of pages, what the pages should look like. As an example a sketch of the Inside Cover Page and the Title Page as implemented in the \cs{report} format has been given below. ^^{design pages} \begindemo \unitlength1cm \prepoint{\small} \noindent\setbox1=\hbox{% \point1.3 1 {{\tiny\copyright}% \thinspace signature}% \point.3 1.5 {acknowledgements}% \point.3 3.75 {bibliographydata}% \point.3 4.25 {keywords}% {\prefil{\hss}\point1.5 5.1 {Inside Cover}}} \gbox{5\unitlength} %height {0pt} %depth {3\unitlength} %width {\copy1} %material % \prefil{\hss} \setbox1=\hbox{% \point1.5 2.85 {abstractname}% \point1.5 1.5 {\gbox{1.25\unitlength} {0pt}{2.5\unitlength}{}}% \point1.5 3.5 {author}% \point1.5 4.05 {\tiny subtitle}% \point1.5 3.8 {\tiny by}% \point1.5 4.25 {title}% \point1.5 5.1 {Title Page}} \gbox{5\unitlength} %height {0pt} %depth {3\unitlength} %width {\copy1} %material !yields \unitlength1cm \prepoint{\small} \noindent\setbox1=\hbox{% \point 1.3 1 {{\tiny\copyright}% \thinspace signature}% \point .3 1.5 {acknowledgements}% \point .3 3.75 {bibliographydata}% \point .3 4.25 {keywords}% {\prefil{\hss}\point 1.5 5.1 {Inside Cover}}} \gbox{5\unitlength} %height {0pt} %depth {3\unitlength} %width {\copy1} %material % \prefil{\hss} \setbox1=\hbox{% \point 1.5 2.85 {abstractname}% \point 1.5 1.5 {\gbox{1.25\unitlength}{0pt}{2.5\unitlength}{}}% \point 1.5 3.5 {author}% \point 1.5 4.05 {\tiny subtitle}% \point 1.5 3.8 {\tiny by}% \point 1.5 4.25 {title}% \point 1.5 5.1 {Title Page}} \gbox{5\unitlength} %height {0pt} %depth {3\unitlength} %width {\copy1} %material \enddemo \blueexample Typesetting outlines, \TB{} ex{\oldstyle11}.{\oldstyle5} Just an outline of characters is also used in the logo of the GUST bulletin. ^^{outline} Below is my solution to \TB{} ex11.5\Dash via nested FIFO, processing: words, via \cs{fifow}, and characters, via \cs{fifo}\Dash to this `tough problem.' \begindemo \fifow Tough exercise \wofif \unskip. %with \def\fifow#1 {\ifx\wofif#1\wofif\fi \processw{#1}\fifow} \def\processw#1{\fifo#1 \ofif\ } \def\process#1{\boxit#1} \def\boxit#1{\setbox0=\hbox{#1}% \hbox{\lower\dp0\vbox{\hrule \hbox{\vrule\phantom#1\vrule}% \hrule}}} !yields \def\fifow#1 {\ifx\wofif#1\wofif\fi \processw{#1}\fifow} \def\processw#1{\fifo#1\ofif\ } \def\process#1{\boxit#1} \def\boxit#1{\setbox0=\hbox{#1}% \hbox{\lower\dp0\vbox{\hrule \hbox{\vrule\phantom#1\vrule}% \hrule}}} \qquad\qquad\qquad \fifow Tough exercise \wofif \unskip.~ \enddemo \blueexample Sierpi\'nski carpet again Salomon\ftn{Advanced \TeX, Springer, {\oldstyle1995}.} provides another variant of one of ^{Sierpi\'nski carpet}s, done by just stacking boxes. \begindemo \setbox0=\vbox{% \hrule width2pt height0pt \hrule width0pt height1pt \hrule width1pt height1pt} \def\tri#1{{\count0=#1 \loop\ifnum\count0>0 \setbox0=\vbox{\offinterlineskip \hbox{\kern.5\wd0\copy0}% \hbox{\copy0\copy0}}% \advance\count0-1 \repeat\copy0}} \hbox{\tri1 \tri2 \tri3 \tri4 \tri5} !yields \setbox0=\vbox{\hrule width2pt height0pt \hrule width0pt height1pt \hrule width1pt height1pt} \def\tri#1{{\count0=#1 \loop\ifnum\count0>0 \setbox0=\vbox{\offinterlineskip \hbox{\kern.5\wd0\copy0}% \hbox{\copy0\copy0}}% \advance\count0-1 \repeat\copy0}} \hbox{\tri1 \tri2 \tri3 \tri4 \tri5} \enddemo \bluesubhead Picture environment It has been called in the file of gkpmac `Pictures (a subset of \LaTeX's conventions).' \LaTeX's ^{line\ font}s are used. Macros are provided for lines, vectors, curves, disks, circles, and ovals. The lines and vectors have discrete orientations and can vary in thickness ({\oldstyle2} states). The implementation is simpler than \LaTeX's, because the options have been omitted. Dimensionless units get their value via \cs{unitlength}. %The user must initialize the latter. The documentation of the ^{picture environment} in pseudo-code comes with \LaTeX, and applies to this set too. In \bluetex{} a macro for rhombus-framed elements has been added to the facilities provided by gkpmac. \thissubsubhead{\runintrue} \bluesubsubhead The markup for the environment \par reads ^|\gkpbeginpicture| and |\gkpendpicture|.\ftn{Not conform to \LaTeX, because the offset parameters are obligatory. These two outer level names have been prefixed by gkp, to preserve \cs{beginpicture} and \cs{endpicture}.} \beginverbatim \def\gkpbeginpicture(#1,#2)(#3,#4){%#1,#2 x,y-dimensions; #3,#4 x,y-offsets ...} !endverbatim \bluesubsubhead Line thickness Default is ^|\thinlines| which can be toggled via the use of ^|\thicklines|. This does not apply to curves. \bluesubsubhead (multi)put These put control sequences are used for the positioning of picture objects. ^^|\multiput|^^|\put| \begincenterverbatim \def\put(#1,#2)#3{%#1,#2 x,y-coordinates %#3 picture object, printed at #1,#2 to the right \raise#2\unitlength \rlap{\kern#1\unitlength #3}\ignorespaces} \def\multiput(#1,#2)(#3,#4)#5#6{% %#1,#2 x,y-coordinates; #3,#4 x,y-increases; %#5 number of times; #6 picture object ...} !endcenterverbatim \bluesubsubhead Picture objects Provided are: (h)box, line, vector, disk, circle, oval, and rhombus. ^^|\makebox|^^|\line|^^|\vector|^^|\disk|^^|\circle|^^|\oval|^^|\rhombus| \thisverbatim{\unmc} \begincenterverbatim \def\makebox(#1,#2)#3{%#1,#2 x,y-sizes (dimensionless) %#3 is put in hbox to#1\unitlength{\hss#3\hss} ...} % \def\framebox(#1,#2)#3{%#1,#2 x,y-sizes (dimensionless) %#3 is put in framed hbox to#1\unitlength{\hss#3\hss} ...} % \def\line(#1,#2)#3{%abs(#1,#2)<=6 %#1,#2 horizontal,vertical-slopes; #3 horizontal size ...} % \def\vector(#1,#2)#3{%abs(#1,#2)<=4 %#1,#2 horizontal, vertical slopes; #3 horizontal size ...} % \def\disk#1{%#1 diameter <=.2inch ...} % \def\circle#1{%#1 diameter <=.5inch ...} % \def\oval(#1,#2){%#1,#2 x,y-sizes (dimensionless) %centre put at reference point ...} \def\rhombus(#1,#2)#3#4{%#1,#2 hor. respectively vert. ratio <=6 %#3 the size in unitlengths (half of total width) %#4 (text) put in the middle, that is the reference point. ...} !endcenterverbatim \noindent Remark. Quarters of an oval are set and controlled via \cs{ifovalbl} (bottom left), \cs{ifovalbr} (bottom right), \cs{ifovaltl} (top left), \cs{ifovaltr} (top right). By default all four are true, but we can set one quarter only if we wish. \blueexample Simple picture markup \begincenterverbatim \unitlength=1cm \begingkppicture(3,1.25)(0,0) \ifmarkorigin\put(0,0)\markorigin\fi \put(1.5,.5){\oval(2,1)} \put(0.5,0){\makebox(2,1){Kees}} \endgkppicture !endcenterverbatim \bluesubsubhead Curves The method has been explained in the \MF{} book page {\oldstyle13}. The functionality provided is similar to Lamport's Bezier.sty, although here a ^{quadratic spline} is used. ^^|\squine| \begincenterverbatim \def\squine(#1,#2,#3,#4,#5,#6){% %#1, #2, #3 x-coordinates of consecutive points %#4, #5, #6 y-coordinates of consecutive points %To plot f(x) between x0 and x1 %\put(0, 0){\squine(x0,xm,x1,y0,ym,y1)}, with %y0=f(x0), y1=f(x1) %xm=(y0-y1+s1x1-s0x0)/(s1-s0) %ym=(s0(s1x1-y1)-s1(s0x0-y0))/(s1-s0) %s0=f'(x0), s1=f'(x1) !endcenterverbatim \noindent The `line thickness' can be varied by redefining ^|\squineelem|. Default: |\def\squineelem{.}|. \bluehead Adding a picture to the database pic.dat Why a picturebase? ^^{database,\ pic.dat}^^{add\ a\ picture} To begin with, it is convenient to have all your pictures at hand and well-organized. Furthermore, it is nice to load the picture from the picturebase, and use it with `arguments,' especially with the value for \cs{unitlength}, or actual values for the offsets, and if necessary with values for the x,y-dimensions. It also nice to specify the `level' of the picture via \cs{fulltrue}, which by default is set to false. The defaults can be changed via providing values in |\thispicture{...}|. \cs{pictures} load all the specified names as defs. The above ideas resulted in the following approach. \blueexample Entry for pic.dat \cs{unitlength} is a dimension variable, ^^{entry\ for\ pic.dat} and \cs{xdim}, \cs{ydim}, \cs{xoffset}, and \cs{yoffset} are token variables. Each entry is a list element preceded by the list element tag, \cs{lst}, and its name. \begincenterverbatim \lst\simplepic{\bgroup%next supply defaults \unitlength=1cm\xdim{3}\ydim{1.25}%offsets are 0 by default \beginpicture \ifmarkorigin\put(0,0)\markorigin\fi \put(1.5,.5){\oval(2,1)} \put(0.5,0){\makebox(2,1){Kees}} \endpicture\egroup}%end simplepic %with in \bluetex{} the shortcuts \def\beginpicture{\the\everypicture\the\thispicture \gkpbeginpicture(\the\xdim,\the\ydim)(\the\xoffset,\the\yoffset)} \def\endpicture{\gkpendpicture\global\thispicture{}} !endcenterverbatim A little more abstract an entry for pic.dat reads as follows. \begincenterverbatim \lst\pic{\bgroup%next the defaults \unitlength\xdim{}\ydim{} \xoffset{}\yoffset{} \beginpicture %next the picture elements \endpicture\egroup} !endcenterverbatim ^^{list\ of\ database} \exercise How can we get a list of names of the pictures in the database? \answer \bluetex{} contains a macro \cs{contentsdatabase} that writes the list of names of a lit, pic, or address database to the file contentslit, contentspic, or contentsaddress.\\ Let us assume that we wish the list of names in a toks variable \cs{namelst}. To facilitate processing of \cs{namelst} \cs{lst} has been inserted before each name in the list. \beginverbatim \newtoks\namelst \def\lst#1#2{\namelst\ea{\the\namelst\lst#1}} \input pic.dat %and to verify the contents \baselineskip12pt plus2pt minus1pt \lineskip1pt plus 1pt minus1pt \def\lst#1{{\tt\string#1}\endgraf} \the\namelst !endverbatim \bluesubhead Check for data integrity After a picture has been added one can check whether the file can be scanned by \TeX{} via making a table of contents as follows. \begincenterverbatim \input blue.tex \contentsdatabase{pic} \bye !endcenterverbatim This script produces no pages of output (that is OK). The file contentspic will be created, though. \bluehead Examples These are added to illustrate what can be achieved with the picture environment. It is true that creating the markup is not as simple as drawing by the mouse. But once you have got the template, (parts of) it can be reused. I explained the approach in broad terms. %The origin has been printed via a + now and then. ^^{flow chart} \blueexample Flow chart loop: flowchartlooppic \thisverbatim{\unmc} \begindemo Interesting is the rhombus. Similar to \oval and \framebox. \def\rhombus(#1,#2)#3#4{% %#1,#2 ratio of hor./vert. size, <=6 %#3 the size in unitlengths % (half of total width) %#4 text to be put in the middle. %The centre is the reference point, %similar as with \oval. \setbox0=\hbox{\line(#1,#2){#3}}% \setbox1=\hbox{\line(#1,-#2){#3}}% \hbox to0pt{\hss \vbox to0pt{\offinterlineskip\vss \copy0\copy1\vss}% \vbox to0pt{\vss\copy1\copy0\vss }\hss}% \vbox to0pt{\vss \hbox to 0pt{\hss#4\hss}\vss}} !yields \thispicture{\xoffset{-4}} \flowchartlooppic \enddemo \blueexample Flow chart due to Furuta: furutapic Note the use of PMA---poor man's arrow heads. \begindemo Interesting here are the arcs and the arrow heads. The latter have been provided separately for reuse. The reference point is at the head. %lu is pointing left up, %rd is pointing right down \def\rdarrowhead{\hbox to0pt{\hss\vrule height.1pt depth.1pt width.5ex \vrule height.5ex\relax}} \def\luarrowhead{\hbox to0pt{\vrule depth.5ex \vrule height.1pt depth.1pt width.5ex}} !yields \furutapic \enddemo \newpage \blueexample Salomon's overviewtexpic ^^{overviewtexpic} \begindemo \thispicture{\fulltrue \xoffset{.25}} \overviewtexpic The right upper corners, suggesting multiple copies, are nice. Recursive use of \put has been applied. Use \put(,){\corners{}} The reference point is ,. \def\corners#1{%#1 the size \put(.1,.1){\line(-1,0){#1}}% \put(.1,.1){\line(0,-1){#1}}% \put(.2,.2){\line(-1,0){#1}}% \put(.2,.2){\line(0,-1){#1}}% } The quarter ovals are specified via e.g. \put(1.1, 2.1){ \ovaltlfalse%TopLeft \ovalblfalse%BottomLeft \ovalbrfalse%BottomRight \oval(2, 1)} !yields \thispicture{\xoffset{.25}\fulltrue} \overviewtexpic \enddemo \exercise Apply the same approach for a macro \cs{card}, i.e., for the figure to denote multiples, as used with \TeX, \LaTeX, \AmS-\AllTeX, to denote some of \TeX's flavours. \answer The important parameters for this macro are the coordinates of the upper right corner of the card. Given that point we can draw lines, put text somewhere et cetera. The macro has been included in the `common-for-pictures' part of pic.dat to be used in pictures. \beginverbatim \def\card#1#2#3{%#1,#2 x,y coord.corner; #3 label \put(#1,#2){\line(-1,0){1.25}} \put(#1,#2){\line(0,-1){ .45}} \put(#1,#2){\lower.45\unitlength \hbox{\line(-1,0){ .25}}} \put(#1,#2){\hbox to0pt{\kern-1.25\unitlength \hbox{\line(0,-1){ .25}}\hss}} \put(#1,#2){\lower.5\unitlength\hbox {\hskip.05\unitlength{\tiny #3}}} }%end card !endverbatim \exercise And what about the diagonal dots? \answer The important parameters for this macro are the coordinates of the first point of the right\-upper diagonal ellipsis. The macro has been included in the `common-for-pictures' part of pic.dat to be used in pictures. The basic part from below is borrowed from \TB{} ex18.45. \beginverbatim \def\diagdots#1#2{\put(#1,#2){$.^{.^.}$}} !endverbatim \blueexample SGML-\TeX{} relation ^^{sgmltexpic} \begindemo The interesting thing in the markup is the abstraction of the level in the picture via the counter \leg. Instead of explicit numbers the counter is used via \the\leg<.fraction>, and advanced for the next level. \thispicture{\small \unitlength=3ex \xoffset{-9} }\sgmltexpic !yields \thispicture{\small \unitlength=2.75ex \xoffset{-9} }\sgmltexpic \enddemo \newpage \blueexample Systemtheory picture \begindemo %These kinds of pictures occur often. %Just the template from pic.dat \lst\systemtheorypic {\bgroup \unitlength1cm\xoffset{-1.5} \xdim{7}\ydim{2.25} \beginpicture \ifmarkorigin\put(0,0){\markorigin}\fi \put(-1,1.75){$u_1$} \put(-.4,1.5){$^{\fivesy+}$} \put(-1,1.5){\vector(1,0){.9}} \put(0,0){\vector(0,1){1.4}} \put(-.3,1.125){$^{\fivesy+}$} \put(0,1.5){\circle{.1}} % \put(.1,1.5){\vector(1,0){1.65}} \put(.5,1.25){$e_1$} \put(1.75,1.125){\framebox(1,.75){$G$}} \put(2.75,1.5){\line(1,0){1.75}} % \put(4.5,1.5){\vector(0,-1){1.4}} \put(4.6,.2){$^{\fivesy+}$} \put(4.5,0){\circle{.1}} % \put(1.75,0){\line(-1,0){1.75}} \put(1.75,-.375){\framebox(1,.75){$K$}} \put(4.4,0){\vector(-1,0){1.65}} \put(3.25,-.25){$e_1$} % \put(5.5,0){\vector(-1,0){.9}} \put(4.7,-.375){$^{\fivesy+}$} \put(5.5,-.25){\llap{$u_2$}} \endpicture\egroup} !yields $$\systemtheorypic$$ \enddemo \blueexample Pie-chart: ntgpiepic ^^{ntgpiepic} \begindemo The challenge was to create a `circle' via splines. Another thing is that the top of the candles is done by \line, which does not show in print when too small. The origin is close to the middle of the chart. !yields \ntgpiepic \enddemo \exercise How to generalize the above picture in such a way that a business pie-chart can be represented? \answer It is not a problem to complete the circle. An open problem is how to specify and implement the parts of the pie-chart, especially each size. If you have found a graceful solution, let me know. Perhaps we should let it go because of \PS, where it can be done easily. However, Gurari in `\TeX{} \& \LaTeX--- Drawing \& Literate programming,' provides a solution within \TeX, especially the AlDra\TeX{} macros for drawing pie, bar and XY charts. The picture on the cover\Dash BLUe's format in a nutshell\Dash is nice too. Consult pic.dat for the markup. \bluehead Advanced fractals On the edge of order and chaos, the limit cycles of various non-linear models, there is a fascinating, inspiring world for all those who love nature the mother of all art. Julia researched the mapping $z^2, z\in\C$, perhaps the simplest nonlinear mapping. Nevertheless its limit cycle consists of what is called today the Mandelbrot fractals.\ftn{I had to kludge a little because a dimen${\times}$dimen is forbidden, yields arithmetic overflow. To circumvent this \cs{x} and \cs{y} are counters.} \blueexample Mira model ^^{Mira} \bgroup %Mira dust fractals, without much detail, too course arithmetic. Iteration with TeX! %cgl@rc.service.rug.nl, June 1995. %Iteration (in psuedo-TeX notation % x_{n+1}=b*y_n + f(x_n) % y_{n+1}= -x_n + f(x_{n+1}), f(x)= a*x + 2(1-a)x^2/(1+x^2), % or one of your choice :-) %Very primitive (integer) arithmetic, but immediate formatting. %\newdimen\unitlength \newcount\k \newcount\x \newcount\y \newcount\oldx\newcount\oldy \newcount\huna\newcount\scaledb \newcount\scale \newcount\hunc \newcount\sqx \newcount\sqxone \newcount\wx \newcount\npoints %Typeset a `dot' at (x, y). Ref point left invariant. \def\putatxy{\hbox to0pt{\kern\x\unitlength \vbox to0pt{\vss\hrule width.3pt\kern\y\unitlength }\hss}} % %Perhaps I should take over Gurari's *, /, + and - for assigning arithmetic \def\w{\sqx\x \multiply\sqx\x \sqxone\sqx \advance\sqxone1 %\sqxone:= x^2 + 1 \wx\x \multiply\wx\huna \multiply\sqx\hunc \divide\sqx\sqxone \advance\wx\sqx \divide\wx100 %\wx:= a*x + c*x^2/(x^2 + 1) } \def\mira#1%100*a #2%\scale*b #3%100*x #4%100*y {\huna#1 \scaledb#2 \hunc\huna \multiply\hunc-2 \advance\hunc200 %c:= 2-2a \x#3 \y#4 \w %\huna means 100 times a (simple scaling to compensate for integer arithmetic) \k0 \loop \putatxy \oldx\x \x\y \multiply\x\scaledb \divide\x\scale \advance\x\wx %\x:= y*b + w \w \y\wx \advance\y-\oldx %\y:= w - x \ifnum\x=0 \ifnum\y=0 \message{x and y are 0, at k=\the\k.}\k\npoints \fi\fi \advance\k1 \ifnum\k<\npoints \repeat}%end mira % \unitlength.2pt \scale100 \npoints400 % %MIRA mappings, cgl, from Lauwerier's Fractals \begindemo %x_{n+1}=b*y_n + f(x_n) %y_{n+1}= -x_n + f(x_{n+1}), % f(x)= a*x + 2(1-a)x^2/(1+x^2) %a=-.48 b=.93 x=4 y=0 \scale100 $$\mira{-48}{93}{400}{0}$$ !yields $$\scale100 \mira{-48}{93}{400}{0}$$ \enddemo \vskip4\bigskipamount \begindemo %a=-.25 b=.99 x=3 y=0 $$\scale100 \mira{-25}{99}{300}{0}$$ !yields $$\scale100 \mira{-25}{99}{300}{0}$$ \enddemo \vskip2\bigskipamount %Three paths nested: \begindemo %a=.32, b=1, x=-5, y=0 %a=.31, b=1, x=12, y=0 %a=.30, b=1, x= 7, y=-12 \unitlength.02pt \scale100 $$\mira{32}{100}{-500}0% \mira{31}{100}{1200}0% \mira{30}{100}{700}{-1200}$$ !yields \unitlength.02pt \scale100 $$\mira{32}{100}{-500}0% \mira{31}{100}{1200}0% \mira{30}{100}{700}{-1200}$$ \enddemo \kern-1\medskipamount \blueexample H\'enon model ^^{H\'enon} %H\'enon's model. %cgl@rc.service.rug.nl June 1995. %\newdimen\unitlength \unitlength1pt %\newcount\k\newcount\maxk %\newcount\x\newcount\y\newcount\oldx\newcount\oldy \newcount\thoa \newcount\thob \def\putatxy{\hbox to0pt{\kern\x\unitlength \vbox to0pt{\vss\hrule width.5pt height.5pt\kern\y\unitlength }\hss}} \def\henon#1#2{%#1=1000*a #2=1000*b. a, b have a factor 1000 %Transforms (x) (a -b) (x) (b*x*x) % | |=| | | | + | | % (y) (b a) (y) (-a*x*x) \loop%\showthe\x\showthe\y; \oldx\x \multiply\oldx\oldx \multiply\y100 \advance\y-\oldx \oldy\y \oldx\x \multiply\x#1 \multiply\x100 \multiply\oldy#2 \advance\x-\oldy \divide\x100000 \multiply\oldx#2 \multiply\oldx100 \multiply\y#1 \advance\y\oldx \divide\y100000 %\ifnum\k>500 \putatxy%\fi %\ifnum\x=0 \ifnum\y=0 \message{x and y are 0, at k=\the\k.} \k\kmax\fi\fi \advance\k1 \ifnum\k<\kmax \repeat}%end \henon \begindemo %x_{k+1} = ax_k - by_k + b*x_k^2 %y_{k+1} = bx_k + ay_k - a*x_k^2 %a=cos(alfa) b=sin(alfa) \x50 \y99 \unitlength1pt \thoa240 \thob=971 %alfa=~76 degrees \maxk200 \vskip2\bigskipamount $$\henon{\the\thoa}{\the\thob}$$ !yields \x50 \y99 \unitlength1pt \thoa=240 \thob=971 %alfa=~76 degrees %a=\the\thoa/1000, b=\the\thob/1000, x=\the\x, y=\the\y \kmax200 \vskip2\bigskipamount $$\henon{\the\thoa}{\the\thob}$$ \enddemo \egroup \vskip5\bigskipamount Afterthought. To program fractals is fun. With \TeX{} it is tedious because of the limited arithmetic facilities and the consumed memory. This can be a nuisance for authors writing about fractals in \TeX. The more complex fractals emerging from for example looking into the details of the structure of limit cycles, such as the Mira islands, are beyond the scope of this work and \TeX's arithmetic capabilities. In the last picture the islands emerge at the horizon, at the end of the spirals, with a little imagination. %\tracingstats1\endinput \endinput