summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/misc/flowchart.sty
blob: 0df4442fefbb890eca5985bc63c2e84978b46d9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
%
%From: chase@orc.olivetti.com (David Chase)
%Subject: re: Flow charts in LaTeX
%Date: Mon, 24 Oct 88 15:34:42 -0700
%
%Here is a tool that might be useful; you can use it to get lines
%which bend (90 degrees) ending in arrows, and you can study it (ha ha)
%to figure out how it might be extended to do a flow chart.
%It is included within a program to test demonstrate it.  It uses only
%the LaTeX picture macros for graphics.
%
%Note the use of dirty tricks to turn points into dimensionless
%numbers.  There may be a better way, but I couldn't find it.  My
%difficulties with this lead me to believe that either
%(1) TeX should really provide dimensionless real numbers
%or
%(2) Maybe LaTeX should use real lengths instead of dimensionless
%numbers in the picture environment.  I might get tired of always
%attaching a dimension to things, but it would be LOTS easier to write
%interesting macros.
%
%If anyone can point out to me an easier way to do this, I'd be happy
%to hear it.  People on TeXhax tried to help me a couple of years ago
%with this, but nothing seemed to work.
%
%---------------- BEGINNING OF MACROS  ----------------
% First, a dirty trick

{\catcode`p=12 \catcode`t=12 \gdef\bogusmacro#1pt{#1}}
\let\getfactor=\bogusmacro
\def\unpt#1{\expandafter\getfactor\the#1}

% A macro to get us out of the iteration.

\def\gobbleemup#1,#2,#3,{}

% TWAI does all the work, and could probably be rewritten
% to be much prettier.

\def\twai#1,#2,#3,#4,#5,{
%	\typeout{Twisty arrow increment of |#1| |#2| |#3| |#4| |#5|}

% Turn parameters into PT quantities so we can do simple arithmetic.
	\xco#1pt\relax
	\yco#2pt\relax
	\len#4pt\relax
	\advance\len -\firstshrink\relax
% We get \taoval dynamically from our caller
	\def\firstshrink{\taoval pt}\relax
% Set things up for selection and iteration
	\let\drawcommand=\line
	\def\this{#3}
	\def\xvec{0}
	\def\yvec{0}
	\let\next=\twai
% Figure out which way we're going now
	\if\this\uu
		\addtolength{\yloc}{\len}
		\def\yvec{1}
		\corner=0
		\else
	\if\this\dd
		\addtolength{\yloc}{-\len}
		\def\yvec{-1}
		\corner=1
		\else
	\if\this\ll
		\addtolength{\xloc}{-\len}
		\def\xvec{-1}
		\corner=0
		\else
	\if\this\rr
		\addtolength{\xloc}{\len}
		\def\xvec{1}
		\corner=2
		\else
	\if\this\ee
		\relax
		\else
		\typeout{Twisty Arrow Increment--arg 2 (\this) not one of {udlre}}
	\fi\fi\fi\fi\fi
        \if#5\ee
%		\typeout{Ending vector}
		\let\drawcommand=\twaiend
		\advance\len\tarad
	\fi
%        \typeout{New XL \unpt\xloc\space YL \unpt\yloc}
% Here we emit the line or ending command
	\put(\unpt\xco,\unpt\yco){\drawcommand(\xvec,\yvec){\unpt\len}}
	% Figure out the next line
	\if#5\uu
		\advance\yloc \tarad
		\advance\corner 1
		\else
	\if#5\dd
		\advance\yloc -\tarad
		\advance\corner 0
		\else
	\if#5\ll
		\advance\xloc -\tarad
		\advance\corner 2
		\else
	\if#5\rr
		\advance\xloc \tarad
		\advance\corner 0
		\else
	\if#5\ee
		\let\next=\gobbleemup
                \corner=4
		\else
	typeout{Twisty Arrow Increment--arg 5 (#5) not one of {udlre}}
	\fi\fi\fi\fi\fi
%       \typeout{Corner center XL \unpt\xloc\space YL \unpt\yloc}
	\ifcase\corner
		% case 0 TL
		\put(\unpt\xloc,\unpt\yloc){\oval(\taoval,\taoval)[tl]}
		\or
		% case 1 BL
		\put(\unpt\xloc,\unpt\yloc){\oval(\taoval,\taoval)[bl]}
		\or
		% case 2 TR
		\put(\unpt\xloc,\unpt\yloc){\oval(\taoval,\taoval)[tr]}
		\or
		% case 3 BR
		\put(\unpt\xloc,\unpt\yloc){\oval(\taoval,\taoval)[br]}
		\or
		% case 4 END
		\relax
		\fi
	\advance\xloc \xvec\tarad
	\advance\yloc \yvec\tarad
%        \typeout{Final XL \unpt\xloc\space YL \unpt\yloc}
% iterate or finish, depending upon value of 'next'
	\next\unpt\xloc,\unpt\yloc,#5,
	}
\def\twistyarrowgen(#1,#2,#3,#4)#5{{
	\def\uu{u}
	\def\dd{d}
	\def\ll{l}
	\def\rr{r}
	\def\ee{e}
	\countdef\corner=255
	\newskip{\xco}\newskip{\yco}\newskip{\len}
	\newskip{\xloc}\newskip{\yloc}
	\newskip{\tarad}\setlength{\tarad}{#3pt}
	\newskip{\dummylen}
	\let\twaiend=#4
	\setlength{\dummylen}{\tarad}
	\advance\dummylen \dummylen
	\def\taoval{\unpt\dummylen}
	\setlength{\xloc}{#1pt}\setlength{\yloc}{#2pt}
	\def\firstshrink{\tarad}\relax
	\twai #1,#2,#5,e,}}
%
\def\twistyarrow(#1,#2){\twistyarrowgen(#1,#2,2,\vector)}
\def\twistyarrowrad(#1,#2,#3){\twistyarrowgen(#1,#2,#3,\vector)}
%----------------  END OF MACROS ----------------
%\documentstyle[flowchart]{article}
%\begin{document}
%\unitlength=.1in
%\begin{center}
%\begin{picture}(30,30)
%\twistyarrowrad(0,0,1){%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11,r,11,d,10,l,10,%
%u,11}
%\end{picture}
%\end{center}
%\end{document}