Translating a shape 3 times: What is a smarter way to code?
Reference: pgfmanual.pdf
, section 18.
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\tikzset{
myc/.pic={
\draw[line width=0.2cm] (0, 0) -- (2, 0) -- (2, 1) -- (1, 1) -- (1, 2) -- (2, 2) -- (2, 3) -- (0, 3) -- cycle;
\fill[red] (0, 0) -- (2, 0) -- (2, 1) -- (1, 1) -- (1, 2) -- (2, 2) -- (2, 3) -- (0, 3) -- cycle;
}
}
\path (0,0) pic {myc} (1,3) pic {myc} (2,6) pic {myc};
\end{tikzpicture}
\end{document}
as supplement to @JpuleV answer:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots} % it load tikz too
\pgfplotsset{compat=1.10, % it is very old, now is available 1.16 ... upgrade it!
ticks=none}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{backgrounds, % For testing with "framed" option to look at the bounding box
calc,
patterns}
\begin{document}
\begin{tikzpicture}[scale=2, transform shape]
\tikzset{
myc/.pic={
\draw[line width=2mm,fill=red] (0, 0) -| (2, 1) -| (1, 2) -| (2, 3) -| cycle;
}
}
\path (0,0) pic {myc} (1,3) pic {myc} (2,6) pic {myc};
\end{tikzpicture}
\quad
\begin{tikzpicture}[scale=4, transform shape]
\tikzset{
myc/.pic={
\draw[line width=2mm,fill=red] (0, 0) -| (2, 1) -| (1, 2) -| (2, 3) -| cycle;
}
}
\path (0,0) pic {myc} (1,3) pic {myc} (2,6) pic {myc};
\end{tikzpicture}
\qquad
\begin{tikzpicture}%[scale=4, transform shape]
\tikzset{
myc/.pic={
\draw[line width=2mm,fill=red, xscale=-1] (0, 0) -| (2, 1) -| (1, 2) -| (2, 3) -| cycle;
}
}
\path (0,0) pic {myc} (-1,3) pic[xscale=-1] {myc} (2,6) pic {myc};
\end{tikzpicture}
\end{document}
edit:
If you like to rotate for 180 degrees all shapes, than simply add scale=-1 to myc
style definition. IN case that you like to mirroring only one of them, than add xscale-1
to pic
: pic[xscale=-1] {myc}
. however, reflecting picreflect its internal coordinates. this you can simple compensate with accordingly changed
x` coordinate of pic position. see third example in above image.