# Tessellating pattern using Tikz

I would like to regenerate the same image in a tessellating pattern

My base image is what I generated from my understanding of working in a tikz environment. It is a bit verbose

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric}
\pagestyle{empty}

\pgfdeclarelayer{edgelayer}
\pgfdeclarelayer{nodelayer}
\pgfsetlayers{edgelayer,nodelayer,main}

\tikzstyle{latticesite}=[circle,fill=black,draw=black]
\tikzstyle{corner}=[rectangle,inner sep=0pt,fill=black,draw=black]

\tikzstyle{particlevelocity}=[-latex,draw=black,line width=2.000]
\tikzstyle{arrow}=[-,draw=black,postaction={decorate},decoration={markings,mark=at position .5 with {\arrow{>}}},line width=2.000]
\tikzstyle{tick}=[-,draw=black,postaction={decorate},decoration={markings,mark=at position .5 with {\draw (0,-0.1) -- (0,0.1);}},line width=2.000]
\tikzstyle{Edges}=[-,draw=black,line width=1.000]

\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\newlength{\imagewidth}
\newlength{\imagescale}

\begin{document}

\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=latticesite] (0) at (0, 2) {};
\node  at (0.15, 0.4) {0};
\node [style=latticesite] (1) at (0, -2) {};
\node  at (0.25, -1.6) {1};
\node [style=latticesite] (2) at (2, 0) {};
\node  at (1.75, 0.4) {4};
\node [style=latticesite] (3) at (-2, 0) {};
\node  at (0.25, 1.5) {2};
\node [style=latticesite] (4) at (0, -0) {};
\node  at (-1.65,0.4) {3};
%       \node [style=latticesite] at (2, 2){};
\node [style=latticesite] (5) at (2, 2) {};
\node  at (1.75, 1.4) {5};
\node [style=latticesite] (6) at (2, -2) {};
\node  at (-1.65,1.4) {6};
\node [style=latticesite] (7) at (-2, -2) {};
\node  at (-1.65,-1.4) {7};
\node [style=latticesite] (8) at (-2, 2) {};
\node  at (1.75, -1.4) {8};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=Edges] (0) to (5);
\draw [style=Edges] (2) to (5);
\draw [style=Edges] (6) to (1);
\draw [style=Edges] (3) to (8);
\draw [style=Edges] (0) to (8);
\draw [style=Edges] (3) to (7);
\draw [style=Edges] (2) to (6);
\draw [style=Edges] (7) to (1);
\draw [style=particlevelocity] (4) to (0);
\draw [style=particlevelocity] (4) to (2);
\draw [style=particlevelocity] (4) to (3);
\draw [style=particlevelocity] (4) to (1);
\draw [style=particlevelocity] (4) to (5);
\draw [style=particlevelocity] (4) to (6);
\draw [style=particlevelocity] (4) to (7);
\draw [style=particlevelocity] (4) to (8);
\end{pgfonlayer}
\end{tikzpicture}

\end{document}


I would like to know if I can use this as a base figure and create a pattern similar to first image the. Moreover, the sample image has a 2X2 arrangement of the base figure. I would like to extend this to 3X3, or 4X4.

Any workarounds will also be appreciated.

Thanks,

Fowaz

• I'm a little confused here. You have the figure produced by the code in your question and what exacly do you what to do with it? Do you have an image (even hand-drawn) od the desired result? – Gonzalo Medina Oct 16 '15 at 19:56
• I have rephrase the question, the first image is my desired result. Also I would like to extend this pattern to n dimension using Tikz – Fowaz Ikram Oct 16 '15 at 21:01

Here's one option using a pic for the basic shape; the basic command is \MyTess{<number>} which gives a square array having <number>x<number> basic patterns. For example, the image below was produced using

\MyTess{2}\par\bigskip
\MyTess{3}\par\bigskip
\MyTess{4}\par\bigskip
\MyTess{5}


The code:

\documentclass[border=4pt,varwidth=100cm]{standalone}
\usepackage{tikz}

\tikzset{
latticesite/.style={
circle,
fill=black,
draw=black
},
corner/.style={
rectangle,
inner sep=0pt,
fill=black,
draw=black
},
particlevelocity/.style={
-latex,
draw=black,
line width=2.000
},
arrow/.style={
-,
draw=black,
postaction={decorate},
decoration={
markings,
mark=at position .5 with {\arrow{>}}
},
line width=2.000
},
tick/.style={
-,
draw=black,
postaction={decorate},
decoration={
markings,
mark=at position .5 with {\draw (0,-0.1) -- (0,0.1);}
},
line width=2.000
},
Edges/.style={
-,
draw=black,
line width=1.000
},
myshape/.pic={
\foreach \Pos [count=\xi from 0] in {(0,0),(0,-2),(0,2),(-2,0),(2,0),(2,2),(-2,2),(-2,-2),(2,-2)}
\node[latticesite] (\xi) at \Pos {};
\draw [Edges] (5) to (6) to (7) to (8) to (5);
\foreach \Value in {1,...,8}
\draw [style=particlevelocity] (0) to (\Value);
\path
node at (0.15, 0.4) {0}
node  at (0.25, -1.6) {1}
node  at (1.75, 0.4) {4}
node  at (0.25, 1.5) {2}
node  at (-1.65,0.4) {3}
node  at (1.75, 1.3) {5}
node  at (-1.65,1.3) {6}
node  at (-1.65,-1.4) {7}
node  at (1.75, -1.4) {8};
}
}

\newcommand\MyTess[1]{%
\begin{tikzpicture}
\foreach \XValue in {1,...,#1}
{
\foreach \YValue in {1,...,#1}
{
\pic at (4*\XValue,-4*\YValue) {myshape};
}
}
\end{tikzpicture}%
}

\begin{document}

\MyTess{2}\par\bigskip

\MyTess{3}\par\bigskip

\MyTess{4}\par\bigskip

\MyTess{5}

\end{document}


# Some remarks

• I simplified the creation of the basic shape by using some loops and suppressing the layers which are not really needed in this case.
• Instead of the old \tikzstyle I switched to the more appropriate \tikzset syntax.