ChengsongTanPhdThesis/Chapters/tape.tex
author Chengsong
Fri, 03 Jun 2022 16:45:30 +0100
changeset 532 cc54ce075db5
child 533 6acbc939af6a
permissions -rw-r--r--
restructured

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{ifthen}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{calc, decorations.pathmorphing}
\tikzstyle{tape}=[thick, draw, minimum height=5mm, minimum width=7mm, fill=green!35,outer sep=0pt]
\tikzstyle{head}=[very thick, draw, minimum height=6mm, minimum width=7mm, fill=none,outer sep=0pt]

\def\DrawTape#1{
\begin{scope}[start chain=1 going right,node distance=-0.15mm]
    % start tape
    \node [on chain=1,tape,draw=none, tape, fill=none, draw=none] at (0,-\i*1) (node\i0){\ldots\ };
    \draw [thick,fill=green!35] (node\i0.north east) -- ++(-.07,0) decorate [decoration={zigzag, segment length=.10cm, amplitude=.015cm}] 
    {-- ($(node\i0.south east)+(-.15,0)$)} -- (node\i0.south east) -- cycle;
    % draw tape 
      \foreach [count=\j] \element in \adlist {     
	  \ifthenelse{\j = \head}{ % read-write heads current position
		    \node [on chain=1,tape, fill=red!35] (node\i\j){\element};
	      }
	      {
		    \node [on chain=1,tape] (node\i\j) {\element};
	      }
      }    
    % close tape
    \draw [thick,fill=green!35] (node\i\j.north east) -- ++(.15,0) decorate [decoration={zigzag, segment length=.10cm, amplitude=.015cm}] 
    {-- ($(node\i\j.south east)+(.07,0)$)} -- (node\i\j.south east) -- cycle;
    \node [on chain=1,tape, fill=none, draw=none] (end\i) {\ \ldots};
    \node [right = of end\i]{\tiny tape~\i};
    
    % draw read-write head
    \prevnode=\head
    \advance\prevnode by -1
    \node [head,right = of node\i\the\prevnode] (head\i){};
    \node [above = of head\i]{\tiny head \i};
\end{scope}
}
\newcount\prevnode
\begin{document}
% Define the turing machine as a list of pairs, where each pair consists of the read-writes head position the delimiter "/" and  the list of symbols on the tape.
\newcommand{\tapes}{ 3/{, , ,1,1, }, 1/{, 1, 0, 1 , 0,}, 2/{ , 1 , 1, 0, 1,}}
\begin{tikzpicture}
% Draw program node
\draw (-1.5,-2) node [draw, thick, rectangle, minimum height= 2.5cm, minimum width=2cm, fill=white, rounded corners] (program){program};

% Draw tapes and heads
\foreach [count=\i] \head/\adlist in \tapes {
    % Draw tape and head
    \DrawTape{\i,\head,\adlist}
    % Draw link to program
    \draw[thick, rounded corners=3pt] (program) {-- ($(node\i0.south west) + (0,-0.15)$)} 
	{-- ($(head\i.south) + (0,-0.1)$)}-- (head\i.south);
}
\end{tikzpicture}
\end{document}