Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132948 views
License: OTHER
1
\documentclass[varwidth=true, border=2pt]{standalone}
2
\usepackage{ifthen}
3
\usepackage{tikz}
4
\usetikzlibrary{calc}
5
6
\begin{document}
7
\tikzstyle{vertex}=[draw,red,fill=red,circle,
8
minimum size=10pt,inner sep=0pt]
9
\tikzstyle{edge}=[red, very thick]
10
\begin{tikzpicture}
11
\newcommand{\n}{3}
12
\foreach \y in {0, ..., \n}{
13
\pgfmathsetmacro{\loopend}{{2*\n-\y}}
14
\pgfmathsetmacro{\second}{{\y+2}}
15
\foreach \x in {\y, \second,..., \loopend}{
16
\ifthenelse{\n=\y}{\breakforeach}{}
17
\node (n-\x\y)[vertex] at (\x,\y) {};
18
19
\ifthenelse{\y=0}{}{\draw[edge] (\x,\y) -- (\x+1,\y-1);}
20
\pgfmathtruncatemacro\X{\x}
21
\ifthenelse{\X<\loopend}{\draw[edge] (\x,\y) -- (\x+2,\y);}{}
22
\ifthenelse{\X=\loopend}{}{\draw[edge] (\x,\y) -- (\x+1,\y+1);}
23
24
}
25
}
26
\end{tikzpicture}
27
\end{document}
28
29