Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to create a circle of elements with some randomness to it. I want to predefined the coordinates to create complicated element. I am using this:

\newcommand{\elm}[2]{
  \shade [ball color=red] (#1,#2) circle (4 pt);
}

and this:

\begin{tikzpicture}
  \foreach \ang in {0,90,...,270}{
    \pgfmathsetmacro{\r}{200pt}
    \pgfmathsetmacro{\dx}{rand*2}
    \pgfmathsetmacro{\dy}{rand*2}
    \elm{{\r*cos(\ang) + \dx},{\r*sin(\ang)+\dy}}
  }
\end{tikzpicture}

All I get is a blank sheet of paper without any figure. How can do this correctly?

share|improve this question
add comment

1 Answer

It might be more beneficial to use \pgfmathsetlengthmacro for this. Currently it takes 2 meters for the \r variable since the default is centimeters.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \foreach \ang in {0,90,...,270}{
    \pgfmathsetlengthmacro{\r}{2cm}
    \pgfmathsetlengthmacro{\dx}{rand*2 cm}
    \pgfmathsetlengthmacro{\dy}{rand*2 cm}
    \shade [ball color=red] ({\r*cos(\ang) + \dx},{\r*sin(\ang) + \dy}) circle (4 pt);
  }
\end{tikzpicture}
\end{document}

Also if I am not wrong you are passing only one argument to \elm where you have two defined. I removed it to make it more concise.

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.