我想用 tikz 画这个,
我一直尝试使用 tikz 来实现,但没有成功,有人建议我使用 PsTricks。这是我目前所做的
\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pstricks-add}
\definecolor{DarkOceanSky}{RGB}{133,163,229}
\definecolor{DarkNavyBlue}{RGB}{0,25,63}
\definecolor{Reu}{RGB}{102,173,76}
\definecolor{Crimson}{RGB}{220, 20, 60}
%second part
\def\block{%
\foreach \x in {1,3,5,...,7}
{
\foreach \y in {1,3,5,...,7}
{%
\foreach \angle in {0,45,...,315}
{
\psrline{->}(\x,\y)(!0.10 Rand 1.4 mul add sqrt \angle\space PtoC)
}
}
}
\foreach \counter in {0,2,4,6,...,8}
{
\psline{-, linecolor=DarkNavyBlue,linewidth=1.8pt}(\counter,0)(\counter,8)
\psline{-, linecolor=DarkNavyBlue,linewidth=1.8pt}(0,\counter)(8,\counter)
}
\pscircle*[linecolor=Crimson](4,4){0.2}
}
\begin{document}
\begin{pspicture}[showgrid](19.0,8)
%\rput(12,0){\block}
\rput(11.0,0){\block}
\foreach \counter in {0,2,4,6,...,8}
{
\psline{-, linecolor=DarkNavyBlue,linewidth=1.8pt}(\counter,0)(\counter,8)
\psline{-, linecolor=DarkNavyBlue,linewidth=1.8pt}(0,\counter)(8,\counter)
}
\foreach \counter in {1,3,5,...,7}
{
\psline{-, linecolor=DarkNavyBlue,linewidth=1.0pt}(\counter,0)(\counter,8)
\psline{-, linecolor=DarkNavyBlue,linewidth=1.0pt}(0, \counter)(8,\counter)
}
\foreach \counter in {0.5,1.5,2.5,3.5,4.5,5.5,6.5,...,7.5}
{
\psline{-, linecolor=DarkNavyBlue,linewidth=1.0pt}(\counter,0)(\counter,8)
\psline{-, linecolor=DarkNavyBlue,linewidth=1.0pt}(0, \counter)(8, \counter)
}
\pscircle[linecolor=Reu](4,4){4.5}
\pscircle*[linecolor=Crimson](4,4){0.2}
%I need to draw those small arrows
\psrline{->}(1.6, 0.1)(!0.10 Rand 0.3 mul add sqrt 45 PtoC)
\end{pspicture}
\结束{文档}
我现在需要做的是创建左图上的那些小箭头。它们是微小的箭头。我愿意接受相同大小的箭头。所以基本上,箭头大小固定,方向不同。我认为这样做的方法是水平绘制一个箭头,然后以随机角度围绕中心旋转它。我不知道怎么做,也不确定这是否是正确的方法。你能帮助我吗?
答案1
\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pstricks-add}
\definecolor{DarkOceanSky}{RGB}{133,163,229}
\definecolor{DarkNavyBlue}{RGB}{0,25,63}
\definecolor{Reu}{RGB}{102,173,76}
\definecolor{Crimson}{RGB}{220,20,60}
\pstVerb{realtime srand}
\def\Grid{%
\foreach \counter in {0,2,...,8}{%
\psset{linecolor=DarkNavyBlue,linewidth=2\pslinewidth,linecap=2}
\psline(\counter,0)(\counter,8)
\psline(0,\counter)(8,\counter)
}%
}
\def\SubGrid{%
\foreach \counter in {0,.5,...,8}{%
\psset{linecolor=DarkOceanSky,linewidth=.5\pslinewidth,linecap=2}
\psline(\counter,0)(\counter,8)
\psline(0,\counter)(8,\counter)
}%
}
\def\Left{%
\SubGrid
\Grid
\foreach \x in {.25,.75,...,7.75}{%
\foreach \y in {.25,.75,...,7.75}{%
\rput{!rand 3601 mod 10 div}(\x,\y){\psline{->}(-4pt,0)(4pt,0)}
}%
}%
\pscircle[linecolor=Reu,linewidth=2\pslinewidth](4,4){4.5}
\pscircle*[linecolor=Crimson](4,4){0.2}
}
\def\Right{%
\Grid
\foreach \x in {1,3,5,...,7}{%
\foreach \y in {1,3,5,...,7}{%
\foreach \angle in {0,45,...,315}{%
\psrline{->}(\x,\y)(!0.10 Rand 1.4 mul add sqrt \angle\space PtoC)
}%
}%
}%
\pscircle*[linecolor=Crimson](4,4){0.2}
}
\begin{document}
\begin{pspicture}[showgrid=false](18,9)
\rput(.5,.5){\Left}
\rput(10,.5){\Right}
\end{pspicture}
\end{document}
答案2
应该优化小箭头的位置(因为最好依赖于网格大小而不是 TikZ 的坐标系),但这是一种双嵌套循环随机方法。
代码
\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{arrows}
\definecolor{DarkOceanSky}{RGB}{133,163,229}
\definecolor{DarkNavyBlue}{RGB}{0,25,63}
\definecolor{Reu}{RGB}{102,173,76}
\definecolor{Crimson}{RGB}{220, 20, 60}
\begin{document}
\begin{tikzpicture}[
declare function={
minorGridStep=.125cm;
majorGridStep=.5cm;
},
major grid/.style={
line width=+.018cm,
draw=DarkNavyBlue,
step=majorGridStep,
},
minor grid/.style={
line width=+.008cm,
draw=DarkNavyBlue,
step=minorGridStep
},
green circle/.style={
draw=Reu,
radius=1.1,
line width=+.008cm
},
red dot/.style={
fill=Crimson,
radius=.05
}
]
\begin{scope}
\path[minor grid] (-1,-1) grid (1,1);
\path[major grid] (-1,-1) grid (1,1);
\path[green circle] circle [];
\path[red dot] circle [];
\foreach \cRight in {0,...,15}
\foreach \cDown[
evaluate={\length=max(rnd*.9*minorGridStep,1.5\pgflinewidth)},
evaluate={\angle=rnd*360}
] in {0,...,15}
\draw[triangle 90 cap reversed-triangle 90 cap] ([shift=(\angle:-\length/2 pt)] \cRight/16*2-1+.0625,\cDown/16*2-1+.0625) -- ++ (\angle:\length pt);
\end{scope}
\end{tikzpicture}
\end{document}