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?

1

1 Answer 1

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

6
  • Can you tell me which CVS version is needed and where I can get it? thanks
    – bonanza
    Jun 18, 2015 at 8:57
  • I guess, with respect to pgf 3.0.0, I only need the file pgflibrarypatterns.meta.code.tex from pgf.cvs.sourceforge.net/viewvc/pgf/pgf/generic/pgf/libraries/… 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, 2015 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. Jun 24, 2015 at 6:11
  • Thanks for your answer. Can you maybe post here an example based on the current CVS version?
    – bonanza
    Jun 24, 2015 at 7:55
  • @MarkWibrow could you please supply an answer to this question? Feb 19, 2018 at 9:25

You must log in to answer this question.

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