0

This following code extends a bit, an answer posted by the user Sandy G in How to Give Stars a Glow Effect which asked for a way to produce a glowing star with LaTeX.

\documentclass{book}
\textheight 8.5in \textwidth 5.75in 

\usepackage{tikz}
\usetikzlibrary{fadings, calc}
\tikzfading[name=dim fade, inner color=transparent!40, outer color=transparent!100]
\tikzfading[name=bright fade, right color=transparent!100, left color=transparent!100, middle color=transparent!0]

\newcommand{\glowstar}[2][.5]{\fill[white,path fading=dim fade](#2)circle[radius=#1*.6];
    \foreach \t in {0,60,120}{
    \fill[rotate around={\t:(#2)}, white,path fading=bright fade]($(#2)-(.9*#1,0)$)--($(#2)-(0,.05*#1)$)--($(#2)+(.9*#1,0)$)--($(#2)+(0,.02*#1)$)--cycle;
    \fill[rotate around={\t:(#2)}, white,path fading=bright fade]($(#2)-(.5*#1,0)$)--($(#2)-(0,.04*#1)$)--($(#2)+(.5*#1,0)$)--($(#2)+(0,.04*#1)$)--cycle;
    }
    \foreach \t in {0,90,270}{
        \fill[rotate around={\t:(#2)}, white,path fading=bright fade]($(#2)-(1.1*#1,0)$)--($(#2)-(.4,.06*#1)$)--($(#2)+(1.1*#1,0)$)--($(#2)+(.4,.06*#1)$)--cycle;
     }        
    \fill[white] (#2)circle[radius=#1*.13];
    }

\begin{document}
\begin{center}
\begin{tikzpicture}
\fill[blue!25!black] rectangle (16,12);
\glowstar[0.8]{8,10}
\glowstar[0.8]{4,6}
\glowstar[0.8]{12,6}
\end{tikzpicture}
\end{center}
\end{document}

which produces the output

enter image description here

I'm not sure that I modified the code of user Sandy G in the most efficient way, but I have been able to produce, with it the output you see.

I would like to add another extension, but so far, I have been unable to figure out how to do it:

I would like to adjust the length of the vertical tail of the glowing star a bit---so that the lower vertical portion is a bit longer than the upper portion. This could be accomplished if I could raise the glowing center a bit, but again, I have not figured out how to do that.

QUESTION: (1) Most importantly, how may I make an adjustment to the image so that the vertical tail is longer than the upper vertical portion? and, (2) Secondly, is there a way that I may specify the lengths of the horizontal and vertical portions of the star individually?

Thank you.

1
  • First you always can "unroll" the loop into individual statements... (although it's more tedious to edit that way it should be easy to understand)
    – user202729
    Jun 1, 2022 at 0:45

1 Answer 1

3

You could do this to adjust the length of long tails in 4 different directions. You also could do the similar thing on the short tails (because you didn't ask for it, so I didn't do that). One more arg #3 is needed in the command \glowstar which specify the tail length in left, bottom, right, top.

\documentclass{book}
\textheight 8.5in \textwidth 5.75in 

\usepackage{tikz}
\usetikzlibrary{fadings, calc}
\tikzfading[name=dim fade, inner color=transparent!40, outer color=transparent!100]
\tikzfading[name=bright fade, right color=transparent!100, left color=transparent!100, middle color=transparent!0]

\newcommand{\glowstar}[3][.5]{\fill[white,path fading=dim fade](#2)circle[radius=#1*.6];
    \foreach \t in {0,60,120}{
    \fill[rotate around={\t:(#2)}, white,path fading=bright fade]($(#2)-(.9*#1,0)$)--($(#2)-(0,.05*#1)$)--($(#2)+(.9*#1,0)$)--($(#2)+(0,.02*#1)$)--cycle;
    \fill[rotate around={\t:(#2)}, white,path fading=bright fade]($(#2)-(.5*#1,0)$)--($(#2)-(0,.04*#1)$)--($(#2)+(.5*#1,0)$)--($(#2)+(0,.04*#1)$)--cycle;
    }
    \foreach \l [count=\n from 0] in {#3}{
        \fill[rotate around={\n*90:(#2)}, white,path fading=bright fade]($(#2)-(\l*#1,0)$)--($(#2)-(.4,.06*#1)$)--($(#2)+(.4,.06*#1)$)--cycle;
     }        
    \fill[white] (#2)circle[radius=#1*.13];
    }

\begin{document}
\begin{center}
\begin{tikzpicture}
\fill[blue!25!black] rectangle (16,12);
\glowstar[0.8]{8,10}{1.1,1.8,1.1,1.1}% length of left,bottom,right,top
\glowstar[0.8]{4,6}{1.8,1.1,1.8,1.1}
\glowstar[0.8]{12,6}{1.1,1.8,1.1,1.8}
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

5
  • Many thanks for this fine answer. Jun 1, 2022 at 4:44
  • You are welcome, there is one thing I forget that you should define a new fade style. Because the long bright tail is drawn individually, so the fade style should be complete transparent on the right and non-transparent on the left. Such as \tikzfading[name=long bright fade, right color=transparent!100, left color=transparent!0]. However if the tail was not extreme long, it hard to see the effect.
    – Tom
    Jun 1, 2022 at 5:03
  • Thank you. To make sure I understand, should I then replace fading=bright fade to fading=long bright fade in the code segment: \fill[rotate around={\t:(#2)}, white,path fading=bright fade]($(#2)-(.5*#1,0)$)--($(#2)-(0,.04*#1)$)--($(#2)+(.5*#1,0)$)--($(#2)+(0,.04*#1)$)--cycle; ? Jun 1, 2022 at 5:19
  • @mlchristians yes.
    – Tom
    Jun 1, 2022 at 5:28
  • Many thanks for the clarification. Jun 1, 2022 at 5:31

You must log in to answer this question.

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