I'm trying to come up with a PGF decoration that adds pseudo-random noise to the y coordinates of a path, while leaving x coordinates the same. The idea is that if I'm drawing a function y=f(x), this decoration should leave it a function, just make it noisier. The random steps decoration doesn't work because it might yield two different points with the same x coordinate, which is no longer a function.
I tried taking the same basic approach as random steps, but using polar coordinates to add the noise at angle 90-\pgfdecoratedangle. However, this fails for paths that are not horizontal lines. Here is a minimal non-working example:
\documentclass[varwidth,convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\pgfdeclaredecoration{jiggly}{step}
{
\state{step}[width=+\pgfdecorationsegmentlength]
{
\pgfpathlineto{
\pgfpointadd
{\pgfpoint{\pgfdecorationsegmentlength}{0pt}}
{\pgfpointpolar{90-\pgfdecoratedangle}
{rand*\pgfdecorationsegmentamplitude}}
}
}
\state{final}
{
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}
\pgfmathsetseed{1}
\begin{tikzpicture}[very thick, decoration={jiggly, amplitude=1cm}]
\draw[help lines] (0,0) grid (7,4);
\draw[cyan, decorate] (0,1) -- (3,1);
\draw[red, decorate] (4,0) -- (7,3);
\end{tikzpicture}
\end{document}
As you can see, the cyan line looks fine, but the red line has been morphed into something that is no longer a function. It even extends out beyond the rightmost point of the input path, which shouldn't be possible by adding noise just to the y direction. Clearly I'm missing something about how decorations work, and the question is what?

