3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ドラゴン曲線(TeXブック付録Dのあれ)

Last updated at Posted at 2012-03-16

過疎ってるので年明けの景気づけに。TeXブック付録Dの\pathコマンドそのままですが、TeXブックの例に出てくる非実在フォント\qcの代わりにハートマークで描いてみました。

pdftex にかけるとこんなん出ます。
http://www.scribd.com/doc/77092245/Dragon-Curve

dragonheart.tex
%from the TeX book appendix D

\font\qc=cmsy5

\catcode`\ =9 \endlinechar=-1
\newcount\dir \newdimen\y \newdimen\w
\newif\ifvisible \let\B=\visibletrue \let\W=\visiblefalse
\newbox\NE \newbox\NW \newbox\SE \newbox\SW \newbox\NS \newbox\EW
\setbox\SW=\hbox{\qc \char'176} \setbox\NW=\hbox{\qc \char'176}
\setbox\NE=\hbox{\qc \char'176} \setbox\SE=\hbox{\qc \char'176}
\w=\wd\SW \dimen0=\fontdimen1\qc

\setbox\EW=\hbox{\kern-\dp\SW \vrule height\dimen0 width\wd\SW} \wd\EW=\w
\setbox\NS=\hbox{\vrule height\ht\SW depth\dp\SW width\dimen0}  \wd\NS=\w
\def\L{\ifcase\dir \dy+\NW \or\dx-\SW \or\dy-\SE \or\dx+\NE\dd-4\fi \dd+1}
\def\S{\ifcase\dir \dx+\EW \or\dy+\NS \or\dx-\EW \or\dy-\NW\fi}
\def\R{\ifcase\dir \dy-\SW\dd+4 \or\dx+\SE \or\dy+\NE \or\dx-\NW\fi \dd-1}
\def\T{\ifcase\dir\kern-\w\dd+2 \or\ey-\dd+2 \or\kern\w\dd-2 \or\ey+\dd-2\fi}
\edef\dd#1#2{\global\advance\dir#1#2\space}
\def\dx#1#2{\ifvisible\raise\y\copy#2 \if#1-\kern-2\w\fi\else\kern#1\w\fi}
\def\dy#1#2{\ifvisible\raise\y\copy#2 \kern-\w \fi \global\advance\y#1\w}
\def\ey#1{\global\advance\y#1\w}
\def\path#1{\hbox{\B \dir=0 \y=0pt #1}}
\catcode`\ 10

\endlinechar=`\^^M

\newcount\n
\def\dragon{\ifnum\n>0{\advance\n-1 \dragon\L\nogard}\fi}
\def\nogard{\ifnum\n>0{\advance\n-1 \dragon\R\nogard}\fi}

\hskip10mm\path{\dir=2 \n=13 \dragon}

\end
3
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?