在 TikZ 中为矩形发光盒添加灯光效果

在 TikZ 中为矩形发光盒添加灯光效果

我想在我的第一个 MWE 中添加我可以让 TikZ 中的盒子周围发光吗? 如 pgfmanual 示例中所示的灯光效果:

在此处输入图片描述

通过修改以前的 MWE:

 \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{calc}
    \begin{document}
    \def\shadowradius{3pt}
    %
    \newcommand\drawshadowbis[1]{
        \begin{pgfonlayer}{shadow}
    %
            \fill[inner color=blue,outer color=blue!10!black] ($(#1.south east)$) circle (\shadowradius);
            \fill[inner color=blue,outer color=blue!10!white] ($(#1.north west)$) circle (\shadowradius);
            %\fill[inner color=blue,outer color=blue!10!black] ($(#1.south west)$) circle (\shadowradius);
            %\fill[inner color=blue,outer color=blue!10!white] ($(#1.north east)$) circle (\shadowradius);
            %
            \fill[ top color=blue, bottom color=blue!10!black] ($(#1.south west)+((0,-\shadowradius)$) rectangle ($(#1.south east)$);
            \fill[left color=blue,right color=blue!10!black] ($(#1.south east)$) rectangle ($(#1.north east)+((\shadowradius,0)$);
            \fill[bottom color=blue,top color=blue!10!white] ($(#1.north west)$) rectangle ($(#1.north east)+((0,\shadowradius)$);
            \fill[right color=blue,left color=blue!10!white] ($(#1.south west)$) rectangle ($(#1.north west)+(-\shadowradius,0)$);
    \end{pgfonlayer}
    }
    %
    \pgfdeclarelayer{shadow} 
    \pgfsetlayers{shadow,main}
    \begin{tikzpicture}
       \node [fill=blue,rectangle,rounded corners=0pt,draw=blue, ultra thick, text=white] (box) {Test!!!};
       \drawshadowbis{box}
    \end{tikzpicture}
    \end{document}

我明白了:

在此处输入图片描述

但我不知道如何定义缺失角度的颜色。

任何帮助都将不胜感激!

答案1

tikz 库shadings允许您进行双线性插值。它需要一个矩形,但您可以将其剪裁为圆形,因此我有以下示例:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shadings}

\begin{document}
\def\shadowradius{3pt}
%
\newcommand\drawshadowbis[1]{
  \begin{pgfonlayer}{shadow}
    %
    \fill[inner color=blue,outer color=blue!10!black] ($(#1.south east)$) circle (\shadowradius);
    \fill[inner color=blue,outer color=blue!10!white] ($(#1.north west)$) circle (\shadowradius);

    \begin{scope}
      \clip ($(#1.south west)$) circle (\shadowradius);
      \shade[upper left=blue!10!white,upper right=blue,
             lower left=blue!10,      lower right=blue!10!black]
      ($(#1.south west)$) rectangle ++(-\shadowradius,-\shadowradius);
    \end{scope}

    \begin{scope}
      \clip ($(#1.north east)$) circle (\shadowradius);
      \shade[upper left=blue!10!white,upper right=blue!10,
             lower left=blue,         lower right=blue!10!black]
      ($(#1.north east)$) rectangle ++(\shadowradius,\shadowradius);
    \end{scope}

    %
    \fill[ top color=blue, bottom color=blue!10!black] ($(#1.south west)+((0,-\shadowradius)$) rectangle ($(#1.south east)$);
    \fill[left color=blue,right color=blue!10!black] ($(#1.south east)$) rectangle ($(#1.north east)+((\shadowradius,0)$);
    \fill[bottom color=blue,top color=blue!10!white] ($(#1.north west)$) rectangle ($(#1.north east)+((0,\shadowradius)$);
    \fill[right color=blue,left color=blue!10!white] ($(#1.south west)$) rectangle ($(#1.north west)+(-\shadowradius,0)$);
  \end{pgfonlayer}
}
%
\pgfdeclarelayer{shadow}
\pgfsetlayers{shadow,main}
\begin{tikzpicture}
  \node [fill=blue,rectangle,rounded corners=0pt,draw=blue, ultra thick, text=white] (box) {Test!!!};
  \drawshadowbis{box}
\end{tikzpicture}
\end{document}

阴影角

可以通过在远角选择更好的颜色来改善这种情况。

相关内容