7

I would like to insert a stripey ball in TikZ, i.e. a filled-in circle that looks like this one. Would you know a clever solution for doing that?

stripy ball

1
  • Welcome to TeX.SX! I added your image for you. When you get a bit more reputation you will be able to add them yourself.
    – Alan Munn
    Mar 18, 2011 at 1:25

1 Answer 1

9

You can declare a pattern and then apply it to the circle. This is quite easy to do, but you need to know the PGF commands for generating graphics. See section 78 ”Patterns” in the manual (v2.10).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}

\pgfdeclarepatternformonly{stripes}
{\pgfpointorigin}{\pgfpoint{1cm}{1cm}}
{\pgfpoint{1cm}{1cm}}
{
    \pgfpathmoveto{\pgfpoint{0cm}{0cm}}
    \pgfpathlineto{\pgfpoint{1cm}{1cm}}
    \pgfpathlineto{\pgfpoint{1cm}{0.5cm}}
    \pgfpathlineto{\pgfpoint{0.5cm}{0cm}}
    \pgfpathclose%
    \pgfusepath{fill}
    \pgfpathmoveto{\pgfpoint{0cm}{0.5cm}}
    \pgfpathlineto{\pgfpoint{0cm}{1cm}}
    \pgfpathlineto{\pgfpoint{0.5cm}{1cm}}
    \pgfpathclose%
    \pgfusepath{fill}
}

\begin{tikzpicture}
    \filldraw[pattern=stripes, pattern color=black!60]
        (0,0) circle[radius=1cm];
\end{tikzpicture}
\end{document}

result in Acrobat

Every tile in the pattern looks like tile.

The unfortunate disadvantage of patterns is that they are not always rendered correctly. For example, there might be small white stripes where the boxes of the patters border. The picture above was taken with Adobe Acrobat at 125% zoom level. Evince renders it the following way (it seems to rasterize the pattern, hence the fuzziness):

result in Evince

3
  • Brilliant, dear Caramdir, thanks! This works without a hitch on my machine when I change “(0,0) circle[radius=1cm];” to “(0,0) circle (1cm);”. Mar 18, 2011 at 13:43
  • @Thanos: the [radius=...] notation seems to be the preferred way to draw circles in version 2.10 of TikZ (but might not be available in older versions).
    – Caramdir
    Apr 3, 2011 at 2:39
  • Funny, those small stripes vanish (in evince) when I do the same with 0.5cm wide stripes. I guess you can fix those gaps by simply drawing one of the pieces a tad bigger.
    – Raphael
    Jun 21, 2012 at 14:02

You must log in to answer this question.

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