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:


%%% this is the tikz code
\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{ 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 of tikz code


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

Here is the output: