Skip to content

Instantly share code, notes, and snippets.

@flying-sheep
Created June 1, 2011 11:18
Show Gist options
  • Save flying-sheep/1002130 to your computer and use it in GitHub Desktop.
Save flying-sheep/1002130 to your computer and use it in GitHub Desktop.
A quick hack of how you can derive tiles for automatic tiling from three source tiles (you can cramp the third one – the corners – into the second, since the space there isn’t needed)
\usetikzlibrary{calc}
\begin{tikzpicture}
\def\b{.2}
\def\ts{1.5}
\tikzstyle{glass}=[fill opacity=0.1]
\coordinate (empty) at (0,0);
\coordinate (borders) at ($(empty) + (\ts+\b, 0)$);
\coordinate (corners) at ($(borders) + (\ts+\b, 0)$);
\coordinate (ex1) at ($(empty) - (-\b, \ts+3*\b)$);
\coordinate (ex2) at ($(ex1) + (\ts, 0)$);
\coordinate (ex3) at ($(ex2) + (\ts, 0)$);
\coordinate (ex4) at ($(ex2) - (0, \ts)$);
\coordinate (ex5) at ($(ex4) + (\ts, 0)$);
\fill[glass] (empty) rectangle ++(\ts, \ts);
\fill[glass] (borders) rectangle ++(\ts, \ts);
\fill[green] (borders) -- ++( \ts, 0) -- ++(-\b, \b) -- ++(-\ts+2*\b, 0) -- cycle; % bottom
\fill[red] (borders) -- ++( 0, \ts) -- ++(\b, -\b) -- ++(0, -\ts+2*\b) -- cycle; % left
\fill[green] (borders) ++(\ts,\ts) -- ++(-\ts, 0) -- ++(\b, -\b) -- ++( \ts-2*\b, 0) -- cycle; % top
\fill[red] (borders) ++(\ts,\ts) -- ++( 0,-\ts) -- ++(-\b, \b) -- ++(0, \ts-2*\b) -- cycle; % right
\fill[glass] (corners) rectangle ++(\ts,\ts);
\fill[blue]
(corners) rectangle ++( \b, \b)
(corners) ++( 0, \ts) rectangle ++( \b,-\b)
(corners) ++(\ts, \ts) rectangle ++(-\b,-\b)
(corners) ++(\ts, 0) rectangle ++(-\b, \b);
\fill[glass] (ex1) rectangle ++(\ts, \ts);
\fill[blue] (ex1) ++(\ts,\ts) |- ++(-\b,-\b);
\fill[green] (ex1) ++(\ts,\ts) -- ++(-\ts, 0) -- ++(\b, -\b) -- ++( \ts-2*\b, 0) -- cycle; % top
\fill[red] (ex1) -- ++( 0, \ts) -- ++(\b, -\b) -- ++(0, -\ts+2*\b) -- cycle; % left
\fill[green] (ex1) -- ++( \ts, 0) -- ++(-\b, \b) -- ++(-\ts+2*\b, 0) -- cycle; % bottom
\fill[blue] (ex1) ++(\ts, 0) |- ++(-\b, \b);
\fill[glass] (ex2) rectangle ++(\ts, \ts);
\fill[blue] (ex2) ++( 0,\ts) |- ++( \b,-\b);
\fill[green] (ex2) ++(\ts,\ts) -- ++(-\ts, 0) -- ++(\b, -\b) -- ++( \ts-2*\b, 0) -- cycle; % top
\fill[blue] (ex2) ++(\ts,\ts) |- ++(-\b,-\b);
\fill[blue] (ex2) rectangle ++( \b, \b);
\fill[glass] (ex3) rectangle ++(\ts, \ts);
\fill[blue] (ex3) ++( 0,\ts) |- ++( \b, -\b);
\fill[green] (ex3) ++(\ts,\ts) -- ++(-\ts, 0) -- ++( \b,-\b) -- ++( \ts-2*\b, 0) -- cycle; % top
\fill[red] (ex3) ++(\ts,\ts) -- ++( 0,-\ts) -- ++(-\b, \b) -- ++(0, \ts-2*\b) -- cycle; % right
\fill[blue] (ex3) ++(\ts, 0) -| ++(-\b, \b);
\fill[glass] (ex4) rectangle ++(\ts, \ts);
\fill[blue] (ex4) ++( 0,\ts) -| ++(\b, -\b);
\fill[red] (ex4) -- ++( 0, \ts) -- ++(\b, -\b) -- ++(0, -\ts+2*\b) -- cycle; % left
\fill[green] (ex4) -- ++( \ts, 0) -- ++(-\b, \b) -- ++(-\ts+2*\b, 0) -- cycle; % bottom
\fill[blue] (ex4) ++(\ts, 0) |- ++(-\b, \b);
\fill[glass] (ex5) rectangle ++(\ts, \ts);
\fill[blue] (ex5) |- ++(\b, \b);
\fill[green] (ex5) -- ++( \ts, 0) -- ++(-\b, \b) -- ++(-\ts+2*\b, 0) -- cycle; % bottom
\fill[red] (ex5) ++(\ts,\ts) -- ++( 0,-\ts) -- ++(-\b, \b) -- ++(0, \ts-2*\b) -- cycle; % right
\fill[blue] (ex5) ++(\ts,\ts) -| ++(-\b, -\b);
\end{tikzpicture}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment