[Tex/LaTex] Tikz picture using two “foreach” loops

foreachtikz-pgf

I am making a picture using foreach. MWE is appended below

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

 \foreach \x in {0,...,5}
    \draw [DodgerBlue](\x,-1) circle (0.25);

\foreach \x in {0,...,5}
    \draw [-latex,red](\x,-1) -- (\x,-1.5);

\foreach \x in {0,...,5}
    \draw [-latex,DarkGreen](\x,-1) -- (\x,-0.5);

\draw [ultra thin] (5,-0.5) -- (0,-1);

\end{tikzpicture}

\end{document}

The resulting picture is attached below

enter image description here

Now what I want is that the green arrows on the top should be limited by the black line diagonal line. That is for the first circle there should be no green arrow, and its length should increase until it becomes equal to the red arrow in the last circle. How can this be done using foreach using the variable \y. Is there a way such that the intersection of the black diagonal line with the green arrows can be used to limit the length of the green arrows to the desired values? Or is there any other way to achieve this?

Best Answer

In case you do not want to do analytic computations (or if you do not have a simple parametrization for the line).

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}

 \foreach \x in {0,...,5}
    \draw [DodgerBlue](\x,-1) circle (0.25);

\foreach \x in {0,...,5}
    \draw [-latex,red](\x,-1) -- (\x,-1.5) ;

\draw [ultra thin] (5,-0.5) coordinate(aux0)  -- (0,-1) coordinate(aux1);

\foreach \x in {1,...,5}
    \draw [-latex,DarkGreen] (\x,-1) coordinate(aux2) (\x,-0.5) coordinate(aux3)
    (aux2) -- (intersection cs:first line={(aux2)--(aux3)}, 
    second line={(aux0)--(aux1)});


\end{tikzpicture}

\end{document}

enter image description here

To make @ArtificialStupidity happy (?) one loop...

\documentclass[border=3.14mm]{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw [ultra thin] (5,-0.5) coordinate(aux0)  -- (0,-1) coordinate(aux1);
\foreach \x in {0,...,5}
   { \draw [DodgerBlue](\x,-1) circle (0.25);
    \draw [-latex,red](\x,-1) -- (\x,-1.5) ;
    \unless\ifnum\x=0%    
    \draw [-latex,DarkGreen] (\x,-1) coordinate(aux2) (\x,-0.5) coordinate(aux3)
    (aux2) -- (intersection cs:first line={(aux2)--(aux3)}, 
    second line={(aux0)--(aux1)});
    \fi
    }
\end{tikzpicture}
\end{document}