Draw several rectangles

tikz-pgf

I want to draw 50 rectangles with height 3 & breadth 1. There should be space among these rectangles. Also I want to fill with blue color for rectangle number 1,5,7,10, 16, 22,
with green color for 2, 14, 35, 44,46, others with red color.

Is there any easy way using \foreach statement in Tikz? Or is there any other easy way?
I tried like this:

\begin{figure}[!htb]
    \centering 
    \scalebox{0.32}{
        \begin{tikzpicture}
            
        

    \foreach \x in {0, 1, ..., 50 }
          \draw (\x,0) rectangle (\x,10);
          %\draw [draw=black] (\x,4) rectangle (0.5,0);
          %\draw (\x,0) rectangle (0.5,4);

        %\draw [Stealth-Stealth, color = blue, thin] (\x, 0.3) -- (\x, 6.8);
        
        
            
    \end{tikzpicture}
    }
    \caption{}
    
\end{figure}

Best Answer

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \x in {1,...,50}
\fill[red] (1.1*\x,3) rectangle (1.1*\x+1,0);
\foreach \x in {1,5,7,10,16,22}
\fill[blue] (1.1*\x,3) rectangle (1.1*\x+1,0);
\foreach \x in {2,14,35,44,46}
\fill[green] (1.1*\x,3) rectangle (1.1*\x+1,0);
\end{tikzpicture}
\end{document}

A stipe of 50 colored rectangles