Liste der Anhänge anzeigen (Anzahl: 1)
Tikz: Nodes einkreisen
Hallo,
ich würde gerne in einem Viereck an bestimmte Anzahl an Nodes (quasi)zufällig verteilen, ohne dass es zu Überlappungen kommt. Ich habe das ganze jetzt einigermaßen hinbekommen, indem ich sie in einem Gitter anordne und x- und y-Komponente jeweils einen zufälligen Wert addiere.
Als zweites würde ich es gerne hinbekommen, dass immer eine bestimmte Anzahl an Nodes farbig eingekreist wird.Ich habe es mit der Fit-Library einigermaßen hinbekommen, allerdings kommt es dabei zu Überschneidungen. Ich würde es gerne hinbekommen, dass es ungefähr so wie im Bild aussieht.
Anhang 6289
Hat da vielleicht jemand eine Idee?
Viele Grüße
MC
Minimalbeispiel
Code:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{math,fit}
\begin{document}
\directlua{
r = 2
cx = {0+math.random(-r,r)/10,
1+math.random(-r,r)/10,
2+math.random(-r,r)/10,
3+math.random(-r,r)/10,
4+math.random(-r,r)/10,
0+math.random(-r,r)/10,
1+math.random(-r,r)/10,
2+math.random(-r,r)/10,
3+math.random(-r,r)/10,
4+math.random(-r,r)/10,
0+math.random(-r,r)/10,
1+math.random(-r,r)/10,
2+math.random(-r,r)/10,
3+math.random(-r,r)/10,
4+math.random(-r,r)/10}
cy = {0+math.random(-r,r)/10,
0-math.random(-r,r)/10,
0-math.random(-r,r)/10,
0-math.random(-r,r)/10,
0-math.random(-r,r)/10,
-1+math.random(-r,r)/10,
-1+math.random(-r,r)/10,
-1+math.random(-r,r)/10,
-1+math.random(-r,r)/10,
-1+math.random(-r,r)/10,
-2+math.random(-r,r)/10,
-2+math.random(-r,r)/10,
-2+math.random(-r,r)/10,
-2+math.random(-r,r)/10,
-2+math.random(-r,r)/10}
fit={1,2,3,4,5,10,6,7,11,8,12,13,9,14,15}
}
\newpage
\begin{tikzpicture}
\draw[rounded corners = 5pt](-0.75,-3.5)--(4.75,-3.5)--(4.75,0.75)--(-0.75,0.75)--cycle;
\foreach \n in {1,...,15}{
\node (\n) at (\directlua{tex.print(cx[\n])},\directlua{tex.print(cy[\n])}){x};
}
\foreach \n in {1,4,7,10,13}{
\tikzmath{%//
\nz = int(\n+1);
\nd = int(\n+2);
}%\\
\node[draw=green, fit=(\directlua{tex.print(fit[\n])}) (\directlua{tex.print(fit[\n+1])})(\directlua{tex.print(fit[\n+2])}),inner sep=0mm](FIt2) {};
}
\end{tikzpicture}
\end{document}