Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass[tikz,border=3mm]{standalone}
- \usepackage[svgnames]{xcolor}
- \usetikzlibrary{shapes}
- \tikzset{triangle path/.style={%
- regular polygon, regular polygon sides=3,
- minimum size=2cm, inner sep=0pt, outer sep=0pt},
- triangle draw/.style={%
- draw=gray, regular polygon, regular polygon sides=3,
- minimum size=2cm, inner sep=0pt, outer sep=0pt}
- }
- \newcommand{\drawgrid}[1]{
- \foreach \i [count=\row from 0, remember=\row as \lastrow (initially 0)] in {0,...,#1}{
- \foreach \j [count=\column from 0, remember=\column as \lastcolumn (initially 0)] in {0,...,\i}{
- \ifnum\row=0
- \node[triangle draw](0-0){};
- \else
- \ifnum\column=0
- \node[triangle draw, anchor=north](\row-0) at (\lastrow-0.corner 2) {};
- \else
- \node[triangle draw, anchor=north](\row-\column) at (\lastrow-\lastcolumn.corner 3) {};
- \fi
- \fi}}
- }
- \newcommand{\viewgrid}[1]{
- \foreach \i [count=\row from 0, remember=\row as \lastrow (initially 0)] in {0,...,#1}{
- \foreach \j [count=\column from 0, remember=\column as \lastcolumn (initially 0)] in {0,...,\i}{
- \ifnum\row=0
- \node[triangle path](0-0){0-0};
- \else
- \ifnum\column=0
- \node[triangle path, anchor=north](\row-0) at (\lastrow-0.corner 2) {\row-0};
- \else
- \node[triangle path, anchor=north](\row-\column) at (\lastrow-\lastcolumn.corner 3) {\row-\column};
- \fi
- \fi}}
- }
- \begin{document}
- \begin{tikzpicture}
- % draw the triangular grid
- \drawgrid{5}
- \end{tikzpicture}
- \begin{tikzpicture}
- % draw the triangular path
- \viewgrid{5}
- \end{tikzpicture}
- \begin{tikzpicture}
- % draw the triangular grid
- \drawgrid{5}
- % draw the little ship
- \begin{scope}[draw=black, very thick, fill=CornflowerBlue]
- \filldraw[fill opacity=0.5] (5-2.corner 2)--(4-0.corner 1)--(4-1.corner 1)--
- (2-1.corner 1)--(3-2.corner 3)--(4-4.corner 1)--(5-4.corner 2)--cycle;
- \draw (4-1.corner 1) -- (4-3.corner 1) (4-2.corner 1)--(2-1.corner 1);
- \end{scope}
- \end{tikzpicture}
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement