Drawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawing

\draw (20,12) -- ++(2,0) -- ++(0,2) -- ++(-3,0) -- ++(45:3);

Use ++ before each new incremental coordinate to make it relative to the last one and put the pencil there.

Here's a complete example:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikz\draw (20,12) -- ++(2,0) -- ++(0,2) -- ++(-3,0) -- ++(30:3) {[rounded corners=10pt]-- ++(5,0) -- ++(0,-6)} -- ++(-7,0) -- cycle;
\end{document}

enter image description here

Of course, combining this with the -| or |- path operators can simplify the code even further; the following two pieces of code produce the same result:

\tikz\draw (20,12) -- ++(2,0) -- ++(0,2) -- ++(3,0) -- ++(0,1) -- ++(1,0) -- ++(0,-3) -- ++(2,0);\par\bigskip

and

\tikz\draw (20,12) -| ++(2,2) -| ++(3,1) -- ++(1,0) |- ++(2,-3);

I don't think that defining commands in this case adds anything; in fact, I think it reduces the functionality of the existing syntax (which is already simple). The example demonstrates that you can use, for example, polar coordinates and modify (up to TikZ limitations) the path attributes midways; even if the current question doesn't require this, it's a good thing to have the possibility to do those kind of modification if they are required.


Not sure it is what is required, but here is a rectilinear decoration which sort of achieves the required effect:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations}
\pgfdeclaredecoration{rectilinear}{start}{%
\state{start}[width=\pgfdecorationsegmentlength/2,
  next state=draw above]{%
  \pgfpathmoveto{\pgfpointorigin}%
  \pgfcoordinate{@1}{\pgfpointorigin}%
}
\state{draw above}[width=\pgfdecorationsegmentlength/2, 
  next state=draw below]{%
  \pgfcoordinate{@2}{\pgfpointorigin}%
  \pgftransformreset%
  \pgfpointanchor{@1}{center}\pgfgetlastxy\a\b%
  \pgfpointanchor{@2}{center}\pgfgetlastxy\c\d%
  \pgfpathlineto{\pgfqpoint{\a}{\d}}%
  \pgfpathlineto{\pgfqpoint{\c}{\d}}%
  \pgfnodealias{@1}{@2}%
}
\state{draw below}[width=\pgfdecorationsegmentlength/2, 
  next state=draw above]{%
  \pgfcoordinate{@2}{\pgfpointorigin}%
  \pgftransformreset%
  \pgfpointanchor{@1}{center}\pgfgetlastxy\a\b%
  \pgfpointanchor{@2}{center}\pgfgetlastxy\c\d%
  \pgfpathlineto{\pgfqpoint{\c}{\b}}%
  \pgfpathlineto{\pgfqpoint{\c}{\d}}%
  \pgfnodealias{@1}{@2}%
}
\state{final}{%
  \pgftransformreset%
  \pgfpointanchor{@1}{center}\pgfgetlastxy\a\b%
  \pgfpointdecoratedpathlast\pgfgetlastxy\c\d%
  \pgfpathlineto{\pgfqpoint{\a}{\d}}%
  \pgfpathlineto{\pgfqpoint{\c}{\d}}%
}
}
\tikzset{rectilinear/.style={
  decoration={rectilinear, #1}, decorate
}}
\begin{document}
\begin{tikzpicture}[very thick, line join=round, line cap=round]
\draw [gray, postaction={rectilinear, draw=red}]
  (0,4) -- ++(30:2) -- ++(300:3);
\draw [gray, postaction={rectilinear, draw=green!50!black}]
  (0,2) circle [radius=1];
\draw  [gray, postaction={rectilinear={segment length=0.25cm}, draw=blue}]
  (0,0) -- (3,1) arc (90:-90:1) .. controls ++(180:1) and ++(225:1) .. cycle;
\end{tikzpicture}
\end{document}

enter image description here


Here four macro \Start, \Goleft, \Godown and \Goup to creat the desired path.

Code

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{every node/.style={inner sep=0pt,minimum size=0pt}}

\newcommand{\Start}[1]{\node (A) at #1 {};}
\newcommand{\Goleft}[1]{\draw($(A)+( -0.5\pgflinewidth ,0.5\pgflinewidth)$)--+(#1,0)node(A){};}
\newcommand{\Godown}[1]{\draw($(A)+(-0.5\pgflinewidth,0)$)--+(0,-#1)node(A){};}
\newcommand{\Goup}[1]{\draw($(A)+(-0.5\pgflinewidth,0)$)--+(0,#1)node(A){};}

\begin{document}

\begin{tikzpicture}
   \Start{(20,12)}
   \Goleft{2}
   \Godown{2}
   \Goleft{3}
   \Godown{1}
   \Goleft{4}
   \Goup{3}
\end{tikzpicture}

\end{document}

Output

enter image description here