我有以下代码:
\documentclass{standalone}
\usepackage[portuguese, shorthands=off]{babel}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{xfp}
\usepackage{pgfplots}
\usepackage{tkz-euclide}
\begin{document}
\foreach \i in {1,...,5}{
\foreach \j in {1,...,5}{
\begin{tikzpicture}
\clip (-4.,-4.) rectangle (4.,4.);
\draw[help lines,step=1,densely dotted, gray!80] (-3,-3) grid (3,3);
\draw[->,-latex',line width=1pt] (-3,0) -- (3,0) node[right]{$x$};
\draw[->,-latex',line width=1pt] (0,-3) -- (0,3) node[above]{$y$};
\foreach \a in {1,...,\i}{
\foreach \b in {1,...,\j}{
\draw[fill=blue,draw=blue] ({\a-3},{\b-3}) circle (1pt);
}
}
\end{tikzpicture}
}
}
\end{document}
我的目的是为插入的每个点创建一个不同的图形。我想按以下顺序逐一绘制这些点:
(-2,-2), (-2,-1) .... (-2,2)
-> 下一个
(-1,-2), (-1,-1),....,(-1,2)
-> 下一个
(0,-2), (0,-1),...,(0,2)
-> 下一个 .....
(2,-2), (2,-1),...,(2,2)
。
在每个新图形中,我想保留上一次迭代中生成的点。
我怎样才能调整我的代码来实现这一点?
答案1
\documentclass[tikz, border=2mm]{standalone}
%\usepackage[portuguese, shorthands=off]{babel}
%\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows}
%\usepackage{xfp}
%\usepackage{pgfplots}
%\usepackage{tkz-euclide}
\begin{document}
\foreach \i in {0,...,24}{
\begin{tikzpicture}
\clip (-4.,-4.) rectangle (4.,4.);
\draw[help lines,step=1,densely dotted, gray!80] (-3,-3) grid (3,3);
\draw[->,-latex',line width=1pt] (-3,0) -- (3,0) node[right]{$x$};
\draw[->,-latex',line width=1pt] (0,-3) -- (0,3) node[above]{$y$};
\foreach \a in {0,...,\i}
\draw[fill=blue,draw=blue] ({int(\a/5)-2},{mod(\a,5)-2}) circle (1pt);
\end{tikzpicture}
}
\end{document}