1

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:

result

\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.)

edge

Is there any easier way to draw this picture correctly?

3
  • "The left and right side is not symmetry". Could you draw or explain the desired way to make the figure symmetrically? Oct 31 '20 at 6:23
  • I think I understand the symmetry part - it is not about tho colors, but the shape. You are missing a point - try \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. Oct 31 '20 at 6:31
  • @hpekristiansen, Thanks, this is my mistake missing a point. I've added a result picture there but due to the problem of internet connection I cannot see it myself so I'm not sure if it has been successfully uploaded.
    – Jinwen
    Oct 31 '20 at 6:55
1

I draw the symbol with two fadings, and experiment with lining them up at the right side.

This solution is obvious not optimal. The fading is not along the path, but west to east. There is a color difference and render artefact where the lines meet at the right side. There is a problem where the lines intersect - if it was just transparency, it could have been solved with a transparency group.

\documentclass[tikz]{standalone}
\usetikzlibrary {fadings, patterns}
\begin{document}
\begin{tikzpicture}
\pattern[pattern=checkerboard,pattern color=yellow](-1,-0.5) rectangle (1,0.5);
\begin{scope}
  \clip(-1,-0.5)--(0,-0.5)--(0.5,0)--(1,0)--(1,0.5)--(0,0.5)--(-0.5,0)--(-1,0)--cycle;
  \draw[darkgray, line width=5.5, path fading=west, fading transform={xscale=2, xshift=10},  line cap=round] plot[smooth] coordinates{(-0.7,0.02)(-0.5,-0.35)(0.5,0.35)(0.7,-0.02)};
\end{scope}
\begin{scope}
  \clip (-1,-0.5)--(1,-0.5)--(1,0)--(0.5,0)--(0,0.5)--(-1,0.5)--cycle;
  \draw[darkgray, line width=5.5, path fading=east, fading transform={xscale=2, xshift=10},  line cap=round] plot[smooth] coordinates{(-0.7,0)(-0.5,0.35)(0.5,-0.35)(0.7,0.02)}; 
\end{scope}
\end{tikzpicture}
\end{document}

Faded infinity symbol


Edit:

This is just to demonstrate that it is possible to cut one path completely out of the other

\documentclass[tikz]{standalone}
\usetikzlibrary{fadings, patterns}
\begin{tikzfadingfrompicture}[name=myfading]
\clip(-1,-0.5)--(0,-0.5)--(0.5,0)--(1,0)--(1,0.5)--(0,0.5)--(-0.5,0)--(-1,0)--cycle;
\draw[white, line width=5.5, path fading=west, fading transform={xscale=2, xshift=10},  line cap=round] plot[smooth] coordinates{(-0.7,0.02)(-0.5,-0.35)(0.5,0.35)(0.7,-0.02)};
\draw[line width=5.5, line cap=round] plot[smooth] coordinates{(-0.7,0)(-0.5,0.35)(0.5,-0.35)(0.7,0.02)}; 
\end{tikzfadingfrompicture}
\begin{document}
\begin{tikzpicture}
\pattern[pattern=checkerboard,pattern color=yellow](-1,-0.5) rectangle (1,0.6);
\fill[path fading=myfading, left color = white, right color = gray] (-1,-1) rectangle (1,1);
\end{tikzpicture}
\end{document}

Half infinity symbol with middle crossing cut away

This could solve the overlap problem, but whenever I try to use tikzfadingfrompicture, I get strange scaling problems due to my lack of understanding. -see https://tex.stackexchange.com/a/551723/8650

1
  • BTW: The original OP code can directly be used within a tikzfadingfrompicture and thereby transforming it into a fading. This will however not solve the issues with the edge of the path. Also, I do not how to do it without scaling/stretching the symbol. Nov 1 '20 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.