ChengsongTanPhdThesis/Chapters/tape.tex
changeset 532 cc54ce075db5
child 533 6acbc939af6a
equal deleted inserted replaced
531:c334f0b3ef52 532:cc54ce075db5
       
     1 \documentclass{standalone}
       
     2 \usepackage[utf8]{inputenc}
       
     3 \usepackage{ifthen}
       
     4 \usepackage{tikz}
       
     5 \usetikzlibrary{chains}
       
     6 \usetikzlibrary{calc, decorations.pathmorphing}
       
     7 \tikzstyle{tape}=[thick, draw, minimum height=5mm, minimum width=7mm, fill=green!35,outer sep=0pt]
       
     8 \tikzstyle{head}=[very thick, draw, minimum height=6mm, minimum width=7mm, fill=none,outer sep=0pt]
       
     9 
       
    10 \def\DrawTape#1{
       
    11 \begin{scope}[start chain=1 going right,node distance=-0.15mm]
       
    12     % start tape
       
    13     \node [on chain=1,tape,draw=none, tape, fill=none, draw=none] at (0,-\i*1) (node\i0){\ldots\ };
       
    14     \draw [thick,fill=green!35] (node\i0.north east) -- ++(-.07,0) decorate [decoration={zigzag, segment length=.10cm, amplitude=.015cm}] 
       
    15     {-- ($(node\i0.south east)+(-.15,0)$)} -- (node\i0.south east) -- cycle;
       
    16     % draw tape 
       
    17       \foreach [count=\j] \element in \adlist {     
       
    18 	  \ifthenelse{\j = \head}{ % read-write heads current position
       
    19 		    \node [on chain=1,tape, fill=red!35] (node\i\j){\element};
       
    20 	      }
       
    21 	      {
       
    22 		    \node [on chain=1,tape] (node\i\j) {\element};
       
    23 	      }
       
    24       }    
       
    25     % close tape
       
    26     \draw [thick,fill=green!35] (node\i\j.north east) -- ++(.15,0) decorate [decoration={zigzag, segment length=.10cm, amplitude=.015cm}] 
       
    27     {-- ($(node\i\j.south east)+(.07,0)$)} -- (node\i\j.south east) -- cycle;
       
    28     \node [on chain=1,tape, fill=none, draw=none] (end\i) {\ \ldots};
       
    29     \node [right = of end\i]{\tiny tape~\i};
       
    30     
       
    31     % draw read-write head
       
    32     \prevnode=\head
       
    33     \advance\prevnode by -1
       
    34     \node [head,right = of node\i\the\prevnode] (head\i){};
       
    35     \node [above = of head\i]{\tiny head \i};
       
    36 \end{scope}
       
    37 }
       
    38 \newcount\prevnode
       
    39 \begin{document}
       
    40 % 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.
       
    41 \newcommand{\tapes}{ 3/{, , ,1,1, }, 1/{, 1, 0, 1 , 0,}, 2/{ , 1 , 1, 0, 1,}}
       
    42 \begin{tikzpicture}
       
    43 % Draw program node
       
    44 \draw (-1.5,-2) node [draw, thick, rectangle, minimum height= 2.5cm, minimum width=2cm, fill=white, rounded corners] (program){program};
       
    45 
       
    46 % Draw tapes and heads
       
    47 \foreach [count=\i] \head/\adlist in \tapes {
       
    48     % Draw tape and head
       
    49     \DrawTape{\i,\head,\adlist}
       
    50     % Draw link to program
       
    51     \draw[thick, rounded corners=3pt] (program) {-- ($(node\i0.south west) + (0,-0.15)$)} 
       
    52 	{-- ($(head\i.south) + (0,-0.1)$)}-- (head\i.south);
       
    53 }
       
    54 \end{tikzpicture}
       
    55 \end{document}