4

I want to draw chain of beads of two colors arranged in alternating fashion. The overall shape is kind of open regular polygon but preferably with some smooth curve on the side. Each side of the polygon has the same number of beads, of which k number of red beads are followed by n number of blue beads.

The bead at the vertices are of the same color. There is some discontinuity on the side to suggest openness. The code below is the simple case I can draw for square arrangement, in which every two red beads are followed by a blue one.

beads in patterns

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [gray!66] plot [smooth] coordinates {(-.2,0.1)(.35,-.03)(.65,.03) (1,0) (1.35,-.03)(1.65,0.03) (2,0) (2.35,-0.03) (2.65,0.03) (3,0) (3.4,0)(3.6,0) };
\draw [gray!66] plot [smooth] coordinates { (4.635,0) (5.1,-.023) (5.42,.023) (5.76,-.023) (6.1,0) };

%nodes on the horizontal sides first segment
\draw[fill=blue!66] (0,0.03) circle(3.85pt);
\draw[fill=red!66] (0.35,-.03) circle(3.85pt);
\draw[fill=red!66] (0.65,.03) circle(3.85pt);
\draw[fill=blue!66] (1,0) circle(3.85pt);
\draw[fill=red!66] (1.35,-0.03) circle(3.85pt);
\draw[fill=red!66] (1.65,0.03) circle(3.5pt);
\draw[fill=blue!66] (2,0) circle(3.85pt);
\draw[fill=red!66] (2.36,-0.03) circle(3.85pt);
\draw[fill=red!66] (2.66,0.03) circle(3.85pt);
\draw[fill=blue!66] (3,0) circle(3.85pt);
\draw[fill=red!66] (3.4,0) circle(3.85pt);


%nodes on the horizontal sides second segment
\draw[fill=blue!66] (4.8757,0) circle(3.85pt);
\draw[fill=red!66] (5.219,-.023) circle(3.85pt);
\draw[fill=red!66] (5.69523,.023) circle(3.85pt);
\draw[fill=blue!66] (6.13,-.023) circle(3.85pt);

\draw [gray!66] plot [smooth] coordinates { (6.135,0) (6.135,1) (6.137,2) (6.135,3) (6.135,3.64) };

%nodes on the vertical  sides right, first segment
\draw[fill=red!66] (6.135,0.3) circle(3.85pt);
\draw[fill=red!66] (6.135,0.6) circle(3.85pt);
\draw[fill=blue!66] (6.137,.91) circle(3.85pt);
\draw[fill=red!66] (6.137,1.21) circle(3.85pt);
\draw[fill=red!66] (6.137,1.5) circle(3.85pt);
\draw[fill=blue!66] (6.137,1.8) circle(3.85pt);
\draw[fill=red!66] (6.137,2.1) circle(3.85pt);
\draw[fill=red!66] (6.137,2.4) circle(3.85pt);
\draw[fill=blue!66] (6.137,2.7) circle(3.85pt);
\draw[fill=red!66] (6.137,3) circle(3.85pt);
\draw[fill=blue!66] (6.137,3.3) circle(3.85pt);


\draw [gray!66] plot [smooth] coordinates { (6.135,4.257) (6.135,5) (6.137,5.3) (6.135,5.6) (6.135,5.86) };

\draw[fill=blue!66] (6.137,4.7) circle(3.85pt);

\draw[fill=red!66] (6.137,5.1) circle(3.85pt);
\draw[fill=red!66] (6.137,5.52) circle(3.85pt);
\draw[fill=blue!66] (6.137,6) circle(3.85pt);

\draw [gray!66] plot [smooth] coordinates { (6.13,6.03) (6.,6) (5.7,6) (5.4,6) (5.1,6) (4.7,6) (4.4,6) (4,6) (3.7,6) (3.3,6) (2.37,6) };

\draw[fill=blue!66] (6.14,6) circle(3.85pt);

\draw[fill=red!66] (5.7,6) circle(3.85pt);
\draw[fill=red!66] (5.35,6) circle(3.85pt);
\draw[fill=blue!66] (5.,6) circle(3.85pt);
\draw[fill=red!66] (4.695,6) circle(3.85pt);

\draw[fill=red!66] (4.34,6) circle(3.85pt);
\draw[fill=blue!66] (3.96,6) circle(3.85pt);

\draw[fill=red!66] (3.6,6) circle(3.85pt);
\draw[fill=red!66] (3.29,6) circle(3.85pt);
\draw[fill=blue!66] (2.95,6) circle(3.85pt);

\draw[fill=red!66] (2.61,6) circle(3.85pt);


\draw [gray!66] plot [smooth] coordinates { (1.813952,6.03) (1.6012,6) (1.4,6) (1.136,6) (1.13,6) (.57,6) (.24,6) (0,6) };

\draw[fill=blue!66] (1.251791,6) circle(3.85pt);
\draw[fill=red!66] (.813147,6) circle(3.85pt);
\draw[fill=red!66] (.4271904,6) circle(3.85pt);
\draw[fill=blue!66] (0,6) circle(3.85pt);



\draw [gray!66] plot [smooth] coordinates { (0,6.03) (0,5.6) (0,5.3) (0,5) (0,4.6) (0,4) (0,3.4) (.0,2.43)  };

\draw[fill=red!66] (0,5.627) circle(3.85pt);
\draw[fill=red!66] (0,5.30748) circle(3.85pt);
\draw[fill=blue!66] (0,4.9748) circle(3.85pt);
\draw[fill=red!66] (0,4.534) circle(3.85pt);
\draw[fill=red!66] (0,4.1) circle(3.85pt);
\draw[fill=blue!66] (0,3.6748) circle(3.85pt);
\draw[fill=red!66] (0,3.24) circle(3.85pt);
\draw[fill=red!66] (0,2.848) circle(3.85pt);

\draw[fill=blue!66] (0,2.52748) circle(3.85pt);


\draw [gray!66] plot [smooth] coordinates { (0,1.8) (0,1.6) (0,1.4) (0,1.2) (0,1)   (0,0) };

\draw[fill=red!66] (0,.51848) circle(3.85pt);
\draw[fill=red!66] (0,.851848) circle(3.85pt);
\draw[fill=blue!66] (0,1.2851848) circle(3.85pt);
\end{tikzpicture}
\end{document}
  • 2
    What exactly is the question? – Benedikt Bauer Jan 26 '18 at 7:58
14

A decoration might be a good starting place:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations.pathreplacing,calc,shapes.geometric,backgrounds}
\def\drawmarker{%
  \pgfpointdiff{\pgfpointdecoratedinputsegmentfirst}
    {\pgfpointdecoratedinputsegmentlast}
  \pgfgetlastxy\x\y\pgfmathveclen{\x}{\y}\let\len=\pgfmathresult
  \pgfmathparse{int(floor(\len/(\k+\n)/\sep) * (\k+\n))}\let\m=\pgfmathresult
  \pgfmathparse{\len/\m}\let\rsep=\pgfmathresult
  \foreach \i [count=\j from -1, evaluate={\a=mod(\i, \k+\n); \b=int(\a >= \k); 
    \c=int(!(\breakstart > 0 && \i >= \breakstart && 
             \breakend > 0 && \i <=\breakend));
    \d=int(!(\breakstart > 0 && \i > \breakstart && 
             \breakend > 0 && \i <=\breakend));}] in {0,...,\m}{
    \ifnum\d=1 \ifnum\i>0
      \begin{pgfonlayer}{background}
      \path [string/.try]
        ($(\tikzinputsegmentfirst)!\j*\rsep pt!(\tikzinputsegmentlast)$) --
        ($(\tikzinputsegmentfirst)!\i*\rsep pt!(\tikzinputsegmentlast)$);
      \end{pgfonlayer}
    \fi\fi
    \ifnum\c=1
    \fill [every bead/.try, bead \b/.try]
      ($(\tikzinputsegmentfirst)!\i*\rsep pt!(\tikzinputsegmentlast)$) 
        circle [radius=\size/2];
    \fi
  }
}
\tikzset{beads/.cd,
  k/.estore in=\k, n/.estore in=\n, size/.estore in=\size, sep/.estore in=\sep,
  break start/.estore in=\breakstart, break end/.estore in=\breakend,
  break/.style args={#1-#2}{/tikz/beads/.cd,break start=#1, break end=#2},
  k=1, n=2, sep=5pt, size=3pt,  
  break start=0, break end=0, 
  /tikz/.cd,
  beads/.style={
    /tikz/beads/.cd, #1, /tikz/.cd, postaction={
    decoration={
      reverse path, show path construction,
      lineto code=\drawmarker, closepath code=\drawmarker
    }, decorate}},
  string/.style={draw=gray, thin},
  bead 0/.style={fill=blue!66}, bead 1/.style={fill=red!66},
}
\begin{document}
\tikz\foreach \s [count=\q from 1] in {3,...,6}
  \node [beads={k=\q, break=3-4}, regular polygon, regular polygon sides=\s, minimum size=3cm]
    at (0,-\s*3) {};
\end{document}

enter image description here

  • 1
    Wow. Very beautiful +1. – Sebastiano Jan 26 '18 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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