triangular-5.tex 870 B

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