tikz/pgf

a little bit of tikz/pgf

Sat, 2012-05-26 15:32

I've been working with tikz/pgf, a system for creating figures in LaTeX. I've been encouraged to do this partly as a result of my frustration with Inkscape, which is excellent in places, but crashes often and frequently fails to be able to do exactly the thing I need.

Today, I figured out the use of variables in tikz. Here is an example:

\documentclass[12pt]{report}
\usepackage{tikz}
\begin{document}

%%% this is the tikz code
\begin{tikzpicture}[auto,scale=1]
\def\n{10}; % the number of circles
\def\wid{5}; % the width of the drawing
\def\r{2.0}; % radius of each circle
\foreach \j in {1,2,...,\n} {
\foreach \i in {1,2,...,\n} {
\pgfmathparse{1.0*\i/(\n)*360}\let\ang\pgfmathresult;
\pgfmathparse{ 0.5*\wid*(\j)/(\n)*cos(\ang) }\let\xx\pgfmathresult;
\pgfmathparse{ 0.5*\wid*(\j)/(\n)*sin(\ang) }\let\yy\pgfmathresult;
\draw (\xx,\yy) circle (\r);
}
}

\end{tikzpicture}
%%% end of tikz code

\end{document}

This example shows the use of variables, nested for loops, and mathematical calculations.

Here is the output: