[Tex/LaTex] how to draw these shapes

tikz-pgf

I would like to draw the following picture where I can color text, shapes and the lines. The shapes are triangles and stars.

enter image description here

So far, what I have done is

\documentclass[12pt]{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\draw[step=.5cm,gray!20, very thin] (-2,-2) grid (8,8);
\draw[thick,->] (0,0) -- (7,0) node[anchor=north west] {x};
\draw[thick,->] (0,0) -- (0,7) node[anchor=south east] {y};

\coordinate (O) at (2,1);
\coordinate (A) at (2,2);
\coordinate (B) at (3,1.5);
\draw[line width=.2mm, fill=red] (O)--(A)--(B)--cycle;

\coordinate (O) at (1,1.8);
\coordinate (A) at (1,2.8);
\coordinate (B) at (2,2.3);
\draw[line width=.2mm, fill=black] (O)--(A)--(B)--cycle;

\end{tikzpicture}

\end{document}

So, the output is enter image description here

Best Answer

Adjust the stars as you wish:

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
  \begin{tikzpicture}
    [
      my star/.append style={star, draw, star points=4, minimum height=10mm, star point ratio=2.5}
    ]

    \draw[step=.5cm,gray!20, very thin] (-2,-2) grid (8,8);
    \draw[thick,->] (0,0) -- (7,0) node[anchor=north west] {x};
    \draw[thick,->] (0,0) -- (0,7) node[anchor=south east] {y};

    \coordinate (O) at (2,1);
    \coordinate (A) at (2,2);
    \coordinate (B) at (3,1.5);
    \draw[line width=.2mm, fill=red] (O)--(A)--(B)--cycle;

    \coordinate (O) at (1,1.8);
    \coordinate (A) at (1,2.8);
    \coordinate (B) at (2,2.3);
    \draw[line width=.2mm, fill=black] (O)--(A)--(B)--cycle;

    \foreach \i/\j/\k [count=\ijno] in {{6,-1}/blue/a,{1.5,5}/yellow/b,{2.5,4.5}/green/c,{4.5,4}/cyan/d,{5.5,3.5}/orange/e}
    \node (star \ijno) [my star, fill=\j, label=\k] at (\i) {};

    \path [draw] (1.5,2.3)
      edge node [left] {text} (star 2.center)
      edge node [below right] {text} (star 4.center);
    \path [draw] (2.5,1.5)
      edge node [right, pos=.75] {text} (star 3.center)
      edge node [below right] {text} (star 5.center)
      edge node [below left, pos=.6] {text} (star 1.center);

  \end{tikzpicture}

\end{document}

stars and triangles

Update

As Pier Paolo says, if you would like the lines to be drawn 'behind' the shapes, the easiest way is to draw the triangles as nodes and to drop the .center anchor whose sole purpose was to draw the lines in front of the star nodes.

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
  \begin{tikzpicture}
    [
      my star/.append style={star, draw, star points=4, minimum height=10mm, star point ratio=2.5},
      my triangle/.append style={isosceles triangle, draw, minimum height=10mm},
    ]

    \draw[step=.5cm,gray!20, very thin] (-2,-2) grid (8,8);
    \draw[thick,->] (0,0) -- (7,0) node[anchor=north west] {x};
    \draw[thick,->] (0,0) -- (0,7) node[anchor=south east] {y};

    \foreach \i/\j [count=\ijno] in {{1.5,2.3}/magenta,{2.5,1.5}/purple}
      \node (triangle \ijno) [my triangle, fill=\j] at (\i) {};

    \foreach \i/\j/\k [count=\ijno] in {{6,-1}/blue/a,{1.5,5}/yellow/b,{2.5,4.5}/green/c,{4.5,4}/cyan/d,{5.5,3.5}/orange/e}
      \node (star \ijno) [my star, fill=\j, label=\k] at (\i) {};

    \path [draw] (triangle 1)
      edge node [left] {text} (star 2)
      edge node [below right] {text} (star 4);
    \path [draw] (triangle 2)
      edge node [right, pos=.75] {text} (star 3)
      edge node [below right] {text} (star 5)
      edge node [below left, pos=.6] {text} (star 1);

  \end{tikzpicture}

\end{document}

lines behind shapes...