使用 tikz 实现内部模糊阴影

使用 tikz 实现内部模糊阴影

尝试回答后这个问题,虽然我很确定有多个地方可以改进,但我觉得唯一缺少的一点是下图中圆圈内的模糊阴影和条形图。

在此处输入图片描述 在此处输入图片描述

经过一番搜索,似乎没有太多关于此类的问题内部的阴影或边界影。

这是我目前为圆圈想出的效果,但它确实很混乱,是经过多次调整的结果。

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,patterns.meta,shadows,shadows.blur}
% Definition of custom colors based on the initial figure of the bar by the OP
\definecolor{myblue}{HTML}{57AED1}

% Definition of custom tikz styles in order to ease readability
\tikzset{
    % Node style (Arguments : color, section number)
    sectionnode/.style={
        fill=#1,
        draw=none,
        thick,
        circle,
        text=white,
        radius=10pt,
        },
    shadowed/.style={
        preaction={transform canvas={shift={(0.2pt,-0.2pt)}},draw=myblue!50!black},
        preaction={transform canvas={shift={(0.4pt,-0.4pt)}},draw=myblue!60!black},
        preaction={transform canvas={shift={(0.6pt,-0.6pt)}},draw=myblue!70!black},
        preaction={transform canvas={shift={(0.8pt,-0.8pt)}},draw=myblue!80!black},
        preaction={transform canvas={shift={(1.0pt,-1.0pt)}},draw=myblue!90!black}},
}

\begin{document}
    \begin{tikzpicture}[]
    \path[clip] (0,0) circle (9.2pt);
    \node[sectionnode=myblue] at (0,0) {1};
    \path[shadowed] (0,0) circle (9pt);
    \draw[black] (0,0) circle (9pt);
    \end{tikzpicture}

\end{document}

在此处输入图片描述

我也尝试使用该shadows.blur库做一些事情,但似乎无法将其用于此。

所以我的问题是:有人可以提出一种无需使用多个和或剪辑即可重现这种阴影效果的node样式/风格。path\path

答案1

嗯,我想这次是我自己找到的了。

基于这个答案由安德鲁·斯泰西 (Andrew Stacey) 创作,我设法使用preactions 和postactions 重新组合所有内容,然后瞧!

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,patterns.meta,shadows,shadows.blur}
% Definition of custom colors based on the initial figure of the bar by the OP
\definecolor{myblue}{HTML}{57AED1}

% Definition of custom tikz styles in order to ease readability
\pgfmathsetmacro{\blurshift}{0.15}
\pgfmathsetmacro{\blurwidth}{0.3}
% From https://tex.stackexchange.com/a/24957/141947
\tikzset{
  repeated postaction/.style={%
    repeat postaction/.list={#1}
  },
  repeat postaction/.code args={#1/#2}{\tikzset{postaction={transform canvas={shift={(\blurshift*#1 pt,-\blurshift*#1 pt)}},draw=myblue!#2!black,line width={\blurwidth pt}}}},
    % Node style (Arguments : color, section number)
    sectionnode/.style={fill=#1,draw=white,thick,circle,text=white,radius=10pt},
    shadowed/.style={circle,text=white,clip,
        preaction={sectionnode=myblue},
        postaction={repeated postaction={1/50,2/55,3/60,4/65,5/70,6/75,7/80,8/85,9/90,10/95}},
        postaction={sectionnode=none},
    }
}

\begin{document}
    \begin{tikzpicture}[]
    \node[shadowed] at (0,0) {1};
    \end{tikzpicture}

\end{document}

在此处输入图片描述

编辑这是处理虚线条的更新版本。主要变化是,为了处理虚线,您必须降低阴影的不透明度。

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,patterns.meta,shadows,shadows.blur}
% Definition of custom colors based on the initial figure of the bar by the OP
\definecolor{myblue}{HTML}{57AED1}

% Definition of custom tikz styles in order to ease readability
\pgfmathsetmacro{\blurshift}{0.15}
\pgfmathsetmacro{\blurwidth}{0.3}
% From https://tex.stackexchange.com/a/24957/141947
\tikzset{
  repeated postaction/.style={%
    repeat postaction/.list={#1}
  },
  repeat postaction/.code args={#1/#2}{\tikzset{postaction={transform canvas={shift={(\blurshift*#1 pt,-\blurshift*#1 pt)}},opacity=0.5,draw=myblue!#2!black,line width={\blurwidth pt}}}},
    % Node style (Arguments : color, section number)
    sectionnode/.style={fill=#1,draw=white,thick,circle,text=white,radius=10pt},
    shadowednode/.style={circle,text=white,clip,
        preaction={sectionnode=myblue},
        postaction={repeated postaction={1/50,2/55,3/60,4/65,5/70,6/75,7/80,8/85,9/90,10/95}},
        postaction={sectionnode=none},
    },
    sectionbar/.style={preaction={fill=#1,draw=white,thick,rounded corners=2pt},pattern={Lines[angle=45,distance={6pt},line width=3pt]},pattern color=#1!70},
    shadowedbar/.style={rounded corners=2pt,clip,
        preaction={sectionbar=myblue},
        postaction={repeated postaction={1/50,2/55,3/60,4/65,5/70,6/75,7/80,8/85,9/90,10/95}},
        postaction={draw=white,thick},
    }
}

\begin{document}
    \begin{tikzpicture}[]
    \node[shadowednode] at (0,0) {1};

    \draw[draw=none,shadowedbar] (-3,-0.5) rectangle (3,-0.65);
    \end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容