-
Notifications
You must be signed in to change notification settings - Fork 0
/
thaumagramme.sty
86 lines (75 loc) · 2.62 KB
/
thaumagramme.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
\RequirePackage{tikz}
\usetikzlibrary{shapes.geometric, calc}
\newcommand\innernode[2][]{}
\newcommand\outernode[2][]{}
\newcommand\centernode[1][]{\node[#1] at (0,0)}
\newcommand\nodeangleindex[3]{}
\makeatletter
% Define a new environment for the non-starred version
\newenvironment{thaumagramm}[1][3]{%
\begin{tikzpicture}
% Define the radius of the circles
\def\outerR{2}
\def\innerR{1.5}
% Draw the two concentric circles
\draw (0,0) circle (\outerR);
\draw (0,0) circle (\innerR);
\renewcommand\nodeangleindex[3]{
\pgfmathtruncatemacro{\nodeangle}{90-360/#1*(##2-1)}
\node[rotate=\nodeangle-90,##1] at (\nodeangle:##3)
}
\renewcommand\outernode[2][]{\nodeangleindex{##1}{##2}{1.75}}
\renewcommand\innernode[2][]{\nodeangleindex{##1}{##2}{0.8}}
% Define vertices of the polygram
\foreach \x [evaluate=\x as \nodeangle using 90-(\x-1)*360/#1] in {1,...,#1} {
\coordinate (inner\x) at (\nodeangle:\innerR);
}
% Draw each segment individually
\foreach \x in {1,...,#1} {
\pgfmathtruncatemacro{\nextx}{mod(\x,#1)+1}
\draw (inner\x) -- (inner\nextx);
}
}{
\end{tikzpicture}
}
% Define a new environment for the starred version
\newenvironment{thaumagramm*}[1][3]{%
\begin{tikzpicture}
% Define the radius of the circles
\def\outerR{2}
\def\innerR{1.5}
% Draw the two concentric circles
\draw (0,0) circle (\outerR);
\draw (0,0) circle (\innerR);
\renewcommand\nodeangleindex[3]{
\pgfmathtruncatemacro{\nodeangle}{90-360/#1*(##2-1)}
\node[rotate=\nodeangle-90,##1] at (\nodeangle:##3)
}
\renewcommand\outernode[2][]{\nodeangleindex{##1}{##2}{1.75}}
\renewcommand\innernode[2][]{\nodeangleindex{##1}{##2}{0.8}}
% Define vertices of the polygram
\foreach \x [evaluate=\x as \nodeangle using 90-(\x-1)*360/#1] in {1,...,#1} {
\coordinate (inner\x) at (\nodeangle:\innerR);
}
% Draw each segment individually
\pgfmathsetmacro{\oddedges}{mod(#1,2)}
\pgfmathsetmacro{\step}{gcd(#1, #1/2)} % Calculate step for skipping vertices
\ifnum1=\oddedges
\foreach \x in {1,...,#1} {
\pgfmathtruncatemacro{\nexttarget}{mod(\x-1+\step,#1)+1}
\draw (inner\x) -- (inner\nexttarget);
}
\else
\foreach \x in {1,...,#1} {
\pgfmathtruncatemacro{\nexttarget}{mod(\x+1,#1)+1}
\draw (inner\x) -- (inner\nexttarget);
}
\pgfmathsetmacro{\max}{#1/2+1}
% \foreach \x in {2,...,#1/2+1} {
% \pgfmathtruncatemacro{\nexttarget}{\x+1}
% \draw (inner\x) -- (inner\nexttarget);
% }
\fi
}{
\end{tikzpicture}
}