Graphics, Figures & TablesConditions for PSTricks figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Conditions for PSTricks figure

Post by svend_tveskaeg »

Hi all.

First: This is a crosspost from {TeX} SE but the post there seems to be `dead', so I try here.

Consider the following code:

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calc
  \fp_eval:n
\ExplSyntaxOff

% Parameters
\def\radius{1.5 }
\def\doublelayers{2}
\def\columns{2}

\begin{document}

\begin{figure}[htbp]
\def\diameter{\calc{2*\radius}}
\def\distance{\calc{2*3^(1/2)*\radius}}
\def\width{\calc{(2*\columns+1)*\radius}}
\def\height{\calc{(2+3^(1/2)*(\doublelayers-1))*\radius}}
 \centering
  \begin{pspicture}(\width,\height)
   \rput(\radius,\radius){
     \multido{\rC=0+\diameter}{\columns}{
       \multido{\rD=0+\distance}{\doublelayers}{
         \psdot(\rC,\rD)
         \pscircle(\rC,\rD){\radius}
       }
     }
   }
   \rput(!2 \radius mul 1 3 sqrt add \radius mul){
     \multido{\rE=0+\diameter}{\columns}{
       \multido{\rF=0+\distance}{\doublelayers}{
         \psdot(\rE,\rF)
         \pscircle(\rE,\rF){\radius}
       }
     }
   }
  \end{pspicture}
\end{figure}

\end{document}
The document should be compiled using

Code: Select all

pdflatex -shell-escape <filename>.tex
How do I change the code from using \doublelayers to using single layers? The point is that if there are 2n layers, there should be should be drawn n layers to the far-left and n layers indented by an amount of \radius; if there are 2n-1 layers, there should be should be drawn n layers to the left and n-1 layers indented.

Example: If I have three layers, the code should draw two rows of circles beginning at the left of the figure and one row of circles in between, indented.

The attached picture shows 2 double layers (where the curser in the circle i a screenshot mistake). With 3 single layers, the top row shouldn't be there.
Attachments
Example
Example
test.jpg (64.01 KiB) Viewed 2758 times
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply