8

I would like a result similar to that provided by pattern = sixpointed stars (or fivepointed; doesn't matter), but where the underlying grid is at an angle. I understand this can't be done with the pattern library directly, so I might have to do it with a couple of nested for loops and a bit of clipping.

Is there a standard - or simple - way of doing this? In particular, what is the easiest way of obtaining one star which I can then replicate?

Alasdair
  • 5,257
  • 4
  • 38
  • 64

1 Answers1

8

The (very) new patterns.meta library allows for easier ways of specifying patterns and in particular allows a transformation to be applied to the pattern tiles.

It is still under development (there is no documentation yet), only supports PDF output, and is only available in the latest CVS version but is more-or-less stable (so you have been warned).

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{patterns.meta}
\tikzdeclarepattern{name=Stars,
  type=uncolored,
  tile bounding box={(-5pt,-5pt) and (5pt,5pt)},
  tiling size={(\tikztilesize, \tikztilesize)},
  parameters={\tikzstarpoints,\tikzstarradius,\tikzstarrotate,\tikztilesize},
  tiling transformation={rotate=\tikzstarrotate},
  keys={  
    points/.store count=\tikzstarpoints,   points=5,
    radius/.store length=\tikzstarradius,  radius=3pt,
    rotate/.set macro=\tikzstarrotate,     rotate=0,
    tile size/.store length=\tikztilesize, tile size=10pt
  },
  code={
    \pgfmathparse{180/\tikzstarpoints}\let\a=\pgfmathresult
    \fill (90:\tikzstarradius) \foreach \i in {1,...,\tikzstarpoints}{
      -- (90+2*\i*\a-\a:\tikzstarradius/2) -- (90+2*\i*\a:\tikzstarradius)
    } -- cycle;
  }
}   

\begin{document}
\begin{tikzpicture}
\draw [pattern=Stars, pattern color=blue]             (0,0) rectangle ++(2,2);
\draw [pattern={Stars[points=7, tile size=15pt]}]     (2,0) rectangle ++(2,2);
\draw [pattern={Stars[rotate=45]}, pattern color=red] (0,2) rectangle ++(2,2);
\draw [pattern={Stars[rotate=30,points=4,radius=5]}]  (2,2) rectangle ++(2,2);
\end{tikzpicture}
\end{document}

enter image description here

Mark Wibrow
  • 70,437
  • Can you tell me which CVS version is needed and where I can get it? thanks – bonanza Jun 18 '15 at 08:57
  • I guess, with respect to pgf 3.0.0, I only need the file pgflibrarypatterns.meta.code.tex from http://pgf.cvs.sourceforge.net/viewvc/pgf/pgf/generic/pgf/libraries/pgflibrarypatterns.meta.code.tex?view=log&pathrev=MAIN But which revision of this file are you referring to? I tried to most recent CVS version of pgf, and it seems to break my custom pgfdeclarepatternformonly definitions – bonanza Jun 19 '15 at 11:14
  • @bonanza actually, I've completely reimplemented the patterns.meta stuff so the answer above is out of date and possibly wrong given the current CVS code. I haven't checked backward compatibility yet. – Mark Wibrow Jun 24 '15 at 06:11
  • Thanks for your answer. Can you maybe post here an example based on the current CVS version? – bonanza Jun 24 '15 at 07:55
  • @MarkWibrow could you please supply an answer to this question? – rhombidodecahedron Feb 19 '18 at 09:25
  • I am wondering why the library patterns.meta, even though it is part of the TeXLive2018 distribution, did not make its way to the pgfmanual. I really like the approach. (And for some reason your code does not seem to compile with the library from the distribution. What am I doing wrong?) –  Aug 04 '18 at 14:21