1

I need some help drawing arbitrary shapes with hairline strokes. Goal: To draw a transparent hairline stroke, which would show the background sea-green color in this example, an inner stroke, and an outer stroke on a path.

In this first example code, I have incorporated a technique used in inkscape to clip an object with itself to produce both an outer stroke and an inner stroke path, which then lie ontop one another. The implimentation for the outerstroke clipping was found here, credit to Symbol 1.

The issue I have yet to figure out is how to add the transparent hairline. The way I would do this in inkscape is via the stroke to path conversion, then use this new shape for clipping.

Idealy there would be an "eraser" color that I could assign to a path. But really what I want to do is to clip just under the stroke line. I have added a 50% opacity white stroke to the shape demonstrating where this clipping should be.

Arrow example, demonstrating where the transparent hairline should be


\documentclass[boarder=7pt]{standalone}
\usepackage{fontspec}%unit code character support, advanced font configuration

\usepackage{tikz} \usetikzlibrary{arrows,automata,positioning,calc,backgrounds}

% https://tex.stackexchange.com/questions/12010/how-can-i-invert-a-clip-selection-within-tikz
\tikzset{%credit Symbol 1
    clip even odd rule/.code={\pgfseteorule}, % Credit to Andrew Stacey 
    reverseclip/.style={
        clip,insert path=
            [clip even odd rule]{
                [reset cm](-\maxdimen,-\maxdimen)rectangle(\maxdimen,\maxdimen)
            }
    }
}%endtikzset

\usepackage{xfp}%for fpeval{}

%here I define an arrow path

\def\arrowheight{1} \def\arrowwidth{0.9} \def\arrowtailratio{0.42} \def\arrowtailwidth{0.42} \def\arrowmidline{\fpeval{2\arrowheight\arrowtailratio-1}} \def\mypath{(0,\arrowheight) -- (\arrowwidth,\arrowmidline) -- (\arrowtailwidth,\arrowmidline) -- (\arrowtailwidth,-\arrowheight) -- (-\arrowtailwidth,-\arrowheight) -- (-\arrowtailwidth,\arrowmidline) -- (-\arrowwidth,\arrowmidline) -- cycle;} \begin{document} % % \begin{tikzpicture}[background rectangle/.style={fill=green!55!blue}, show background rectangle] \begin{scope} %create an outerstroke by reverse clipping \begin{pgfinterruptboundingbox}%these are needed for bounding box stuff when reverse clipping \path[reverseclip] (0,0) \mypath \end{pgfinterruptboundingbox} \path[draw,scale=1,line width=4,color=black,fill=black,anchor=center] \mypath \end{scope} \begin{scope} %create an innerstroke by clipping \path[clip] (0,0) \mypath \path[draw,scale=1,line width=4,color=red,draw opacity=0.8,fill=cyan,anchor=center] \mypath \end{scope} %draw my white demonstration line \begin{scope} \path[draw,line width=1,color=white, draw opacity=0.5] \mypath \end{scope} \end{tikzpicture}

\end{document}

Another possibility, albeit not enitrely what I want because it has no inner stroke, but a very clever method yet was demonstrated here, which I have altered to the best of my ability to work with genaric paths. This seems to function by repeating the stroke on top one another with reducing thicknesses. But this leaves the problem that if a color is turned translucent it starts to show the stroke color from the last used color, rather than the background.

multi-stroke method


\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{shapes.symbols}
\usetikzlibrary{arrows,automata,positioning,calc,backgrounds}

%https://tex.stackexchange.com/questions/477589/how-to-add-multiple-differently-colored-borders-around-a-node % define the rainbow style \tikzset{ % next color/.style={preaction={draw=#1,next width}}, next opacity/.style={preaction={draw=#1, draw opacity={0.5},next width}}, next width/.code={ \pgfkeysalso{line width/.expanded={\rainbowwidth pt}} \pgfmathsetmacro{\rainbowwidth}{\rainbowwidth-\rainbowstep} % decrease the rainbow width \xdef\rainbowwidth{\rainbowwidth} % set the rainbow width global }, % rainbow/.style={next color/.list={#1}}, rainbow/.style={next opacity/.list={#1}}, rainbow/.prefix code={ \edef\rainbowstep{\the\pgflinewidth} \foreach[count=\i]~in{#1}{} % count the number of colors \pgfmathsetmacro{\rainbowwidth}{\i*\rainbowstep} } }

\begin{document} \begin{tikzpicture}[background rectangle/.style={fill=green!55!blue}, show background rectangle] \path[fill,line width=1mm,inner sep=-4,fill=gray,rainbow={red,orange,yellow,green,blue,purple}] (0,0) -- (3,3) -- (6,0) -- cycle; \end{tikzpicture} \end{document}

Bob
  • 1,270
  • 9
  • 14

0 Answers0