Inspired by this question, I would like to draw a infinity symbol whose opacity changes along the path, what I can achieve so far is this:
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\pagecolor{yellow}
\definecolor{col1}{RGB}{127,127,127}
\definecolor{col2}{RGB}{240,240,240}
\begin{document}
\begin{tikzpicture}
\path[postaction={
decorate,
decoration={
markings,
mark=between positions 0 and \pgfdecoratedpathlength step 0.5pt with {
\pgfmathsetmacro\myval{multiply(divide(
\pgfkeysvalueof{/pgf/decoration/mark info/distance from start}, \pgfdecoratedpathlength),100)};
\pgfsetfillcolor{col1!\myval!col2};
\pgfpathcircle{\pgfpointorigin}{0.1cm};
\pgfusepath{fill};}
}}] plot[smooth cycle] coordinates{(0,0.7)(-0.2,0.35)(0,0)(1,0.7)(1.2,0.35)(1,0)};
\end{tikzpicture}
\end{document}
However there are two problems with it:
(1) This is drown with color gradient, not opacity gradient, thus for example if I use this picture in a paper with yellow background, it is still gray and white, not gray and yellow.
(2) The edge of the path, as you can see, is not smooth, it seems as if the edge is some kind of wave. (I think it is because the color gradient is achieved by drawing many many circles and so the line looks not very straight. However I don't know how to fix this except reduce the step 0.5pt
, but if I do so the drawing process would be very slow.)
Is there any easier way to draw this picture correctly?
\draw plot[smooth cycle, mark=*] coordinates{(0,0.7)(-0.2,0.35)(0,0)(1,0.7)(1.2,0.35)(1,0)};
. Include a picture in your question.