Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 8 down vote accepted
+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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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