How to simplify my code with looping macros?
\documentclass[pstricks,preview,margin=5mm]{standalone}
\usepackage{multido}
\def\obj#1{%
\begin{pspicture}(-2,-2)(2,2)
\multido{\i=#1+30}{12}{\rput{\i}(0,0){\pswedge*(0,0){2}{0}{15}}}
\end{pspicture}%
}
\begin{document}
\obj{0}\obj{15}%
\end{document}
Note: Starred \pswedge
does not need linestyle=none,linewidth=0
to remove the outline because it has been done automatically.
\documentclass{article}
\usepackage{pstricks,multido}
\begin{document}
\begin{pspicture}
\multido{\i=0+15}{24}{%
\def\dowedge{\pswedge}%
\ifodd\i\def\dowedge{\pswedge*}\fi
\dowedge(0,0){2}{\i}{\number\numexpr\i+15}%
}
\end{pspicture}
\end{document}
Potentially one could also draw a filled, black circle and insert 12 white wedges.
As a secondary request, you can set the linestyle
to none
, which removes the outer circle as well as the "inner dot". Effectively, there is then no need for printing the white wedges then, making to code a little lighter:
\documentclass{article}
\usepackage{pstricks,multido}
\begin{document}
\begin{pspicture}
\multido{\i=0+30}{12}{%
\pswedge*(0,0){2}{\i}{\number\numexpr\i+15}%
}
\end{pspicture}
\end{document}
\foreach
from pgffor
package is also available by default in PSTricks. As a result, you don't need to use \multido
.
\documentclass[pstricks,preview,margin=5mm]{standalone}
\begin{document}
\begin{pspicture}(-2,-2)(2,2)
\foreach \i [evaluate = \i as \j using \i+15] in {0,30,..., 330}{\pswedge*{2}{\i}{\j}}
\end{pspicture}
\end{document}
The output is exactly the same as other answers.