10

I wish to draw the picture like below, however, I don't know how to add multiple lines in side the circle.

enter image description here

This is my code:

\documentclass[tikz]{standalone}
\usetikzlibrary{
    shapes.geometric,
    positioning,
    fit,
    calc
}
\usepackage{tikz}
\begin{document}
\tikzset{
 block/.style = {circle, draw,
    text width=1em,align=center,inner sep=0pt},
  line/.style = {draw,thick,->},
}
\begin{tikzpicture}
\node [block,fill=yellow] (s1) {3};
\end{tikzpicture}
\end{document} 
10

You can use a hatched picture as a mask and put your desired fading to be seen through that hatching. Simple example

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{fadings,patterns}%

\begin{tikzfadingfrompicture}[name=hatch fade]%
\foreach\x in{-10,...,10}{
\draw[ultra thick,transparent!20] ([xshift=2*\x mm]-1cm,-1cm) -- ([xshift=2*\x mm]1cm,1cm);
}
\end{tikzfadingfrompicture}


\begin{document}

\begin{tikzpicture}
\node[path fading=hatch fade,fit fading,
font=\sffamily,
circle,
top color=yellow,bottom color=black,
]
{\small 3};
\end{tikzpicture}

\end{document}

enter image description here

  • Try also fit fading=false – percusse Feb 21 '13 at 11:39
  • That's really nice.. I always forget how much powerful is tikzfadingfrompicture. :) – Claudio Fiandrino Feb 21 '13 at 11:49
8

This is one possible solution: the only library needed is patterns.

When one defines:

\node [
  pattern=north east lines,
  left color=orange,
  right color=yellow,
  ] (<name>) at (<some where>) {<text>}; 

or

\node [
  left color=orange,
  right color=yellow,
  pattern=north east lines] (<name>) at (<some where>) {<text>}; 

the problem is that the pattern is overridden by the shading. Thus, one possibility is to define a style exploiting the path picture which allows to mix the shading and the pattern; for example:

 my pattern/.style args={#1 colored by #2}{%
   path picture={
     \node[pattern=#1,pattern color=#2] at (path picture bounding box.center) {};
   }
 },

In such a way, the definition of:

\node [
  my pattern=<some pattern> colored by <some color>,
  left color=orange,
  right color=yellow,      
  ] (<name>) at (<some where>) {<text>}; 

or

\node [
  left color=orange,
  right color=yellow,
  my pattern=<some pattern> colored by <some color>
  ] (<name>) at (<some where>) {<text>};

both work. Moreover, the solution allows to easily select the gradient style to fill the node; the keys:

\pgfkeys{/tikz/.cd,
  gradient style init/.initial=left color,
  gradient style init/.get=\grsi,
  gradient style init/.store in=\grsi,
  gradient style end/.initial=right color,
  gradient style end/.get=\grse,
  gradient style end/.store in=\grse,
}

are devoted to the type choice and the style

  my gradient/.style args={#1 and #2}{%
   \grsi=#1,
   \grse=#2,
 },

to the color choice.

The code:

\documentclass[tikz,border=2pt,png]{standalone}

\usepackage{tikz}
\usetikzlibrary{patterns}

\pgfkeys{/tikz/.cd,
  gradient style init/.initial=left color,
  gradient style init/.get=\grsi,
  gradient style init/.store in=\grsi,
  gradient style end/.initial=right color,
  gradient style end/.get=\grse,
  gradient style end/.store in=\grse,
}

\tikzset{
 block/.style = {circle, draw,
    text width=1em,align=center,inner sep=0pt}, 
 my pattern/.style args={#1 colored by #2}{%
   path picture={
     \node[pattern=#1,pattern color=#2] at (path picture bounding box.center) {};
   }
 },
 my gradient/.style args={#1 and #2}{%
   \grsi=#1,
   \grse=#2,
 },
}

\begin{document}

\begin{tikzpicture}
\node [minimum size=1.75cm,
  block,
  my pattern=north east lines colored by blue!50,
  my gradient=orange!60 and yellow!40] (s1) {1};

% Changing gradient style
\tikzset{gradient style init=top color,
         gradient style end=bottom color}         
\node [minimum size=1.5cm,
  right of=s1,
  block,
  my pattern=north west lines colored by blue!60,
  my gradient=white and green!50] (s2) at (s1.east) {2};

% Changing gradient style
\tikzset{gradient style init=inner color,
         gradient style end=outer color}
\node [minimum size=1.25cm,
  right of=s2,
  block,
  my pattern=crosshatch dots colored by magenta!60,
  my gradient=violet!50!magenta!25 and violet!50!magenta!5] (s3) at (s2.east) {3};

\end{tikzpicture}

\end{document}

The result:

enter image description here

  • thanks, however, when I tried your method, there only two lines in the circle. – sweetyBaby Feb 21 '13 at 11:41
  • @sweetyBaby: which pattern you applied and which circle's dimension? – Claudio Fiandrino Feb 21 '13 at 11:48
  • \tikzset{gradient style init=top color, gradient style end=bottom color} this pattern – sweetyBaby Feb 21 '13 at 11:58
  • @sweetyBaby: I meant my pattern=... and minimum size – Claudio Fiandrino Feb 21 '13 at 12:08
  • I didn't use minimum size, my pattern=north east lines colored by blue!50. – sweetyBaby Feb 21 '13 at 14:38
3

Another solution (except for the shading)

\begin{tikzpicture}

\coordinate (O) at (0,0);

\begin{scope}[rotate=30]
\coordinate (sw) at (-2ex,-2ex); 
\coordinate (ne) at (2ex,2ex);
\clip (0,0) circle (2ex); % clip the surface
\path (ne) -- (sw) % calculate points
    coordinate[pos=.167] (a)
    coordinate[pos=.333] (b)
    coordinate[pos=.500] (c)
    coordinate[pos=.667] (d)
    coordinate[pos=.833] (e);
% draw lines
\draw[blue,very thich] (sw |- a) -- (ne |- a);
\draw[blue,very thich] (sw |- b) -- (ne |- b);
\draw[blue,very thich] (sw |- c) -- (ne |- c);
\draw[blue,very thich] (sw |- d) -- (ne |- d);
\draw[blue,very thich] (sw |- e) -- (ne |- e);
\end{scope}

\draw[thick] (O) circle (2ex);
\node[fill=white,inner sep=.2pt] at (O) {3};
\end{tikzpicture}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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