10

I would like to add to my first MWE in Can I have a glow around a box in TikZ? a lighting effect as shown in this example of the pgfmanual:

enter image description here

By modifying the previous 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}

I get this:

enter image description here

but I do not know how to define the colours of the missing angles.

Any help will be really appreciated!

1 Answer 1

9
+50

The tikz library shadings allows you to do bilinear interpolation. It takes a rectangle, but you can clip it to a circle, so I have the following example:

\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}

Shaded corners

This could be improved by picking a better color on the far corner.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.