-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlife_setup.tex
128 lines (114 loc) · 5.09 KB
/
life_setup.tex
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
% !TEX root = life.tex
%% ## Setup. ##
\newcount\i \newcount\j \newcount\k \newcount\t \newcount\p \newcount\h \newcount\rem
\i=0 \j=0 \k=1 \t=1 \p=1 \h=1 \rem=1
\newcount\lb@size@x \newcount\lb@size@y \newcount\lb@iter \newcount\lb@diff
\lb@size@x=46 \lb@size@y=59 \lb@iter=0 \lb@diff=0
\newcount\l@attrib@x \newcount\l@attrib@y \newcount\l@tmpx \newcount\l@tmpy
\l@attrib@x=0 \l@attrib@y=0 \l@tmpx=0 \l@tmpy=0
\newcount\lb@size@xdefault \newcount\lb@size@ydefault
\lb@size@xdefault=46 \lb@size@ydefault=59\relax
\def\l@setup{%
\global\expandafter\let\csname lc@update@alive@hook@0\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@alive@hook@1\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@alive@hook@2\endcsname\lc@update@to@alive
\global\expandafter\let\csname lc@update@alive@hook@3\endcsname\lc@update@to@alive
\global\expandafter\let\csname lc@update@alive@hook@4\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@alive@hook@5\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@alive@hook@6\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@alive@hook@7\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@alive@hook@8\endcsname\lc@update@to@dead
%
\global\expandafter\let\csname lc@update@dead@hook@0\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@dead@hook@1\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@dead@hook@2\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@dead@hook@3\endcsname\lc@update@to@alive
\global\expandafter\let\csname lc@update@dead@hook@4\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@dead@hook@5\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@dead@hook@6\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@dead@hook@7\endcsname\lc@update@to@dead
\global\expandafter\let\csname lc@update@dead@hook@8\endcsname\lc@update@to@dead
%
\global\i=0\global\j=0
\global\def\l@rule@B{23}
\global\def\l@rule@S{3}
\global\let\l@attrib@name\empty
\global\let\l@attrib@desc\empty
\global\let\l@attrib@seed\empty
\global\let\l@attrib@auth\@undefined
\global\let\l@attrib@rule\@undefined
\global\t=1\global\p=1\global\h=1
\global\l@tmpx=0\global\l@tmpy=0
\global\lb@size@x=\lb@size@xdefault\global\lb@size@y=\lb@size@ydefault\global\lb@iter=0
\global\l@attrib@x=0\global\l@attrib@y=0\global\lb@diff=0
\global\let\lb@forw@once\lb@forw@once@
\global\let\do\empty
}\l@setup
%% ## Title. ##
\font\magtensc=cmcsc10 scaled 1200
\font\magtenrm=cmr10 scaled 2000
\font\minit=cmti10
\baselineskip=1000pt \lineskip=2pt \lineskiplimit=16383pt \parindent=0pt \let\folio\relax
%% The title.
\def\title{%
\line{\hskip -2em\magtensc Conway's \hss \tt Iteration \the\lb@iter}\vskip 5pt
\line{\magtenrm Game of Life \hss \magtenit An implementation in \TeX\rlap{.}}\vskip 15pt
}
%% Loops over the entire board.
\def\lb@loop#1#2{%
\i=0\j=0
\loop
{\loop#1\advance\j1\ifnum\j<\lb@size@x\repeat}#2%
\advance\i1\relax
\ifnum\i<\lb@size@y\repeat
}
%% The cells for alive and dead states.
\newbox\lc@deadbox
\setbox\lc@deadbox=\hbox{\hskip 1pt\vrule height 8pt width .1pt\leaders\hrule height .1pt\hskip 7.8pt\llap{\raise 7.9pt\hbox{\leaders\hrule height .1pt\hskip 7.8pt}}\vrule height 8pt width .1pt\hskip 1pt}
\newbox\lc@alivebox
\setbox\lc@alivebox=\hbox{\hskip 1pt\vrule height 8pt width 8pt\hskip 1pt}
\def\lc@dead{\unhcopy\lc@deadbox}
\def\lc@alive{\unhcopy\lc@alivebox}
%% Loops over board creating empty (dead) cells.
\def\lb@init{%
\lb@loop{\global\expandafter\let\csname lc@\the\i;\the\j\endcsname\lc@dead}{}%
}
%% Generating iterations.
\def\lb@forw@once{\lb@tick\lb@print@next}
\let\lb@forw@once@\lb@forw@once
\def\gameforw#1{%
\h=1\begingroup
\aftergroup\def\aftergroup\next\aftergroup{%
\loop\aftergroup\lb@forw@once\advance\h1\ifnum\h<#1\repeat
\aftergroup}%
\endgroup\next
}
%% Halts processing.
\def\lb@stop{%
\errmessage{All activity ceased after iteration \the\lb@iter.}
\let\lb@forw@once\empty
}
%% Prints header lines.
\def\l@input@header@make{%
\line{\hskip -2em\magtensc Conway's Game of Life. \hss \tt Change \the\lb@diff, Iteration \the\lb@iter, Rule B\l@rule@B/S\l@rule@S\rlap{.}}\vskip 2ex
\line{\magtenrm \l@attrib@name\ \l@input@header@author \hss \minit \l@attrib@desc}\vskip 2ex
}
%% Special check for existence.
\def\l@input@header@author{
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname l@attrib@auth\endcsname\relax
\else
{\magtensc by \rm\l@attrib@auth}
\fi
}
%% Returns the value of (#1 + #3) % #2, used to implement the toroidal array.
\def\l@modadvance#1#2#3{%
\advance#1 by#2
\advance#1 by#3
\rem=#1
\divide\rem by#2
\multiply\rem by#2
\multiply\rem by-1
\advance\rem by#1\relax
#1=\rem
}