7

I would like to draw the light rays as below picture. enter image description here

The below MWE is not beautifull. Please help me correct it. Thank you in advance!

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{fadings}
\pgfdeclareradialshading{rayball}{\pgfpoint{-0.45cm}{0.35cm}}%
{%
  color(0cm)=(white!50!red);
  color(0.15cm)=(red!90!white);
  color(0.55cm)=(red!70!white);
  color(1cm)=(red!60!white)
}
\begin{document}
\pagecolor{red}
\begin{tikzpicture}
\def\n{8} %%number of ray lights
\def\r{0.15} %% radius of circle
\pgfmathsetmacro{\arcangle}{360/(4*\n)}
\def\lightray{(\arcangle:\r)
    \foreach \i in {1,3,...,2\n}{
      --({2*\i*\arcangle}:{30*\r})--({(2*\i+1)*\arcangle}:\r)
      --({2*(\i+1)*\arcangle}:{14*\r})--({(2*\i+3)*\arcangle}:\r)
    }
};
\tikzfading[name=fade out, inner color=transparent!0, outer
color=transparent!100]
\tikzfading[name=fade outTWO, inner color=transparent!0, outer
color=transparent!50]
%%%Ball color
\begin{scope}[opacity=0.85]
    \foreach \rt in {1,2,...,9}{
        \fill[path fading=fade outTWO,shading=rayball,color=red] circle(\rt*\r) ;
    }
\end{scope}
%%%Light rays
\begin{scope}
\pgfsetblendmode{lighten}
\fill[path fading=fade out,color=yellow!70!red] \lightray;
\foreach \i in {-0.25,0,0.25}{
    \fill[path fading=fade out,color=white,scale=1.75,opacity=0.25,rotate=\i] \lightray;
}
\end{scope}
\end{tikzpicture}
\end{document}
4

1 Answer 1

3

enter image description here

The construction of the light rays is based on @Alain Matthes's answer; one of the colors (at the tapered end) is the background color. Afterwards, some fading disks (more or less) are added to suggest the highlights. The needed libraries are decorations.markings and fadings.

The code

\documentclass[11pt, margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, math}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{fadings}

\pgfkeys{/pgf/decoration/.cd,
  width factor/.store in =\wfactor,
  start color/.store in =\startcolor,
  end color/.store in =\endcolor
}
\makeatletter
\pgfdeclaredecoration{width and color change}{initial}{%
  \state{initial}[width=0pt, next state=line, persistent precomputation={%
    \pgfmathdivide{50}{\pgfdecoratedpathlength}%
    \let\increment=\pgfmathresult%
    \def\x{0}%
  }]{}
  \state{line}[width=.5pt, persistent postcomputation={%
    \pgfmathadd@{\x}{\increment}%
    \let\x=\pgfmathresult%
  }]{%
    \pgfsetlinewidth{\wfactor*\x/50*0.075pt+\pgflinewidth}%
    \pgfsetarrows{-}%
    \pgfpathmoveto{\pgfpointorigin}%
    \pgfpathlineto{\pgfqpoint{.75pt}{0pt}}%
    \pgfsetstrokecolor{\endcolor!\x!\startcolor}%
    \pgfusepath{stroke}%
  }
  \state{final}{%
    \pgfsetlinewidth{\pgflinewidth}%
    \pgfpathmoveto{\pgfpointorigin}%
    \color{\endcolor!\x!\startcolor}%
    \pgfusepath{stroke}% 
  }
}
\makeatother

\xdefinecolor{Y}{RGB}{238, 204, 17}
\xdefinecolor{R}{RGB}{238, 34, 34}
\xdefinecolor{LightY}{RGB}{247, 225, 34}

\begin{document}

\tikzfading[name=ffade out, inner color=transparent!64, outer color=transparent!100]
\tikzfading[name=fade out, inner color=transparent!0, outer color=transparent!100] 
\begin{tikzpicture}
  % background
  \fill[R] (-5, -5) rectangle (5, 5);

  % small fading rays
  \foreach \a in {0, 60, ..., 300}{%
    \draw[%line width=.4pt,
    decoration={
      width and color change,   
      width factor=.1,
      start color=R,
      end color=LightY!40!white
    }, decorate] (\a+30: 3.5) -- (0, 0);
  }

  % long rays
  \foreach \a in {0, 60, ..., 300}{%
    \draw[decoration={
      width and color change,   
      width factor=.3,
      start color=R,
      end color=Y
    }, decorate] (\a+5: 5) -- (0, 0);
  }
  \foreach \a in {0, 60, ..., 300}{%
    \draw[decoration={
      width and color change,   
      width factor=.1,
      start color=R,
      end color=LightY
    }, decorate] (\a+5: 5) -- (0, 0);
  }

  % higlights
  \fill[LightY!20!white, path fading=fade out] (0, 0) circle (.8);
  \foreach \a in {0, 60, 120}{%
    \fill[LightY!50!white, path fading=ffade out, rotate={\a+5}] 
    (0, 0) ellipse [x radius=1.3, y radius=1];
  }
\end{tikzpicture}
2
  • Thank you very much. I think the layers can be increased. Then the lights are more naturally! Commented Dec 30, 2021 at 7:57
  • This is the idea, to look for the best parameters that suit you. But do not forget to validate in case you accept an answer.
    – Daniel N
    Commented Dec 30, 2021 at 14:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .