![如何固定乳胶中随机点的位置?](https://linux22.com/image/308195/%E5%A6%82%E4%BD%95%E5%9B%BA%E5%AE%9A%E4%B9%B3%E8%83%B6%E4%B8%AD%E9%9A%8F%E6%9C%BA%E7%82%B9%E7%9A%84%E4%BD%8D%E7%BD%AE%EF%BC%9F.png)
我在 beamer 中使用演示模式。有一个关于随机星星分布在矩形中的框架。我在该幻灯片上做了暂停效果。但是,下一帧会给我不同的随机星星分布。我怎样才能固定随机星星的位置并保持暂停效果?
\documentclass{beamer}
\mode<presentation> {
\usetheme{boxes}
\usecolortheme{rose}}
\usepackage{graphicx} % Allows including images
\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}
\begin{frame}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.7]
\filldraw[fill= blue!40, very thick,opacity=0.8] (0,0) rectangle (6,6);\pause
\draw plot [blue!80, only marks, mark=star, mark size=3, domain=0:6, samples=300] (\x,{0.5*6+0.5*rand*6});\pause
\draw[color=red!80,very thick] (2,1) circle (0.5);
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
答案1
可以找到一些解释这里。我会再做一次,因为你的例子更有趣。
\documentclass{beamer}
\usepackage{pgfplots}
\begin{document}
\makeatletter
\def\pgfmathsaveseed{\xdef\pgfmath@savedseed{\pgfmath@rnd@z}}
\def\pgfmathloadseed{\xdef\pgfmath@rnd@z{\pgfmath@savedseed}}
\def\beamerframeseed{\only<1>{\pgfmathsaveseed}\only<2->{\pgfmathloadseed}}
\begin{frame}
\beamerframeseed
\centering
\begin{tikzpicture}[scale=1.5]
\filldraw[fill= blue!40, very thick,opacity=0.8] (0,0) rectangle (6,6);\pause
\draw plot[blue!80,only marks,mark=star,mark size=3,domain=0:6,samples=60](\x,{0.5*6+0.5*rand*6});\pause
\draw plot[blue!80,only marks,mark=star,mark size=3,domain=0:6,samples=60](\x,{0.5*6+0.5*rand*6});\pause
\draw plot[blue!80,only marks,mark=star,mark size=3,domain=0:6,samples=60](\x,{0.5*6+0.5*rand*6});\pause
\draw plot[blue!80,only marks,mark=star,mark size=3,domain=0:6,samples=60](\x,{0.5*6+0.5*rand*6});\pause
\draw plot[blue!80,only marks,mark=star,mark size=3,domain=0:6,samples=60](\x,{0.5*6+0.5*rand*6});\pause
\draw[color=red!80,very thick] (2,1) circle (0.5);
\end{tikzpicture}
\end{frame}
\end{document}