Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2024
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 2.12 KB | None | 0 0
  1. \documentclass[tikz,border=3mm]{standalone}
  2. \usepackage[svgnames]{xcolor}
  3. \usetikzlibrary{shapes}
  4.  
  5. \tikzset{triangle path/.style={%
  6.   regular polygon, regular polygon sides=3,
  7.   minimum size=2cm, inner sep=0pt, outer sep=0pt},
  8. triangle draw/.style={%
  9.   draw=gray, regular polygon, regular polygon sides=3,
  10.   minimum size=2cm, inner sep=0pt, outer sep=0pt}
  11. }
  12.  
  13. \newcommand{\drawgrid}[1]{
  14. \foreach \i [count=\row from 0, remember=\row as \lastrow (initially 0)] in {0,...,#1}{
  15.    \foreach \j [count=\column from 0, remember=\column as \lastcolumn (initially 0)] in {0,...,\i}{
  16.        \ifnum\row=0
  17.            \node[triangle draw](0-0){};
  18.        \else
  19.            \ifnum\column=0
  20.                \node[triangle draw, anchor=north](\row-0) at (\lastrow-0.corner 2) {};
  21.            \else
  22.                \node[triangle draw, anchor=north](\row-\column) at (\lastrow-\lastcolumn.corner 3) {};
  23.            \fi
  24.        \fi}}
  25. }
  26.  
  27. \newcommand{\viewgrid}[1]{
  28. \foreach \i [count=\row from 0, remember=\row as \lastrow (initially 0)] in {0,...,#1}{
  29.    \foreach \j [count=\column from 0, remember=\column as \lastcolumn (initially 0)] in {0,...,\i}{
  30.        \ifnum\row=0
  31.            \node[triangle path](0-0){0-0};
  32.        \else
  33.            \ifnum\column=0
  34.                \node[triangle path, anchor=north](\row-0) at (\lastrow-0.corner 2) {\row-0};
  35.            \else
  36.                \node[triangle path, anchor=north](\row-\column) at (\lastrow-\lastcolumn.corner 3) {\row-\column};
  37.            \fi
  38.        \fi}}
  39. }
  40.  
  41. \begin{document}
  42. \begin{tikzpicture}
  43. % draw the triangular grid
  44. \drawgrid{5}
  45. \end{tikzpicture}
  46.  
  47. \begin{tikzpicture}
  48. % draw the triangular path
  49. \viewgrid{5}
  50. \end{tikzpicture}
  51.  
  52. \begin{tikzpicture}
  53. % draw the triangular grid
  54. \drawgrid{5}
  55.  
  56. % draw the little ship
  57. \begin{scope}[draw=black, very thick, fill=CornflowerBlue]
  58. \filldraw[fill opacity=0.5] (5-2.corner 2)--(4-0.corner 1)--(4-1.corner 1)--
  59.         (2-1.corner 1)--(3-2.corner 3)--(4-4.corner 1)--(5-4.corner 2)--cycle;
  60.  
  61. \draw (4-1.corner 1) -- (4-3.corner 1) (4-2.corner 1)--(2-1.corner 1);
  62. \end{scope}
  63. \end{tikzpicture}
  64.  
  65. \end{document}
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement