![如何在一张图片上随机放置问号?](https://linux22.com/image/350717/%E5%A6%82%E4%BD%95%E5%9C%A8%E4%B8%80%E5%BC%A0%E5%9B%BE%E7%89%87%E4%B8%8A%E9%9A%8F%E6%9C%BA%E6%94%BE%E7%BD%AE%E9%97%AE%E5%8F%B7%EF%BC%9F.png)
我想在一张图片上以随机大小和随机旋转角度放置几个问号,我做不到,如有任何建议我将不胜感激。
\documentclass[tikz,border=5pt]{article}
\usepackage{graphicx}
\usepackage{picture}
\usepackage{eso-pic}
\usepackage[first=1,last=1000]{lcg}
\usepackage{calc}
\begin{document}
\pagestyle{empty}
\centering
\includegraphics{librarys}
\def\wordlist{\textquestiondown,\textquestiondown,\textquestiondown,\textquestiondown,\textquestiondown}
\makeatletter
\newlength{\randx} \newlength{\randy} % Coordinates of the next word should be saved as random generator produces one number
\AddToShipoutPictureBG*{
\@for\TempVar:=\wordlist\do{%
\rand \setlength{\randx}{\paperwidth*\ratio{\value{rand}mm}{1000mm}} % Set random x position
\rand \setlength{\randy}{\paperheight*\ratio{\value{rand}mm}{1000mm}} % Set random y position
\rand % Generate new random to use as angle
\put(\randx,\randy){\makebox(0,0)[c]{\rotatebox{\value{rand}}{\TempVar}}}% Show next word
}
}
\end{document}
答案1
以下是使用 tikz 的示例。请注意,由于记住图片缓存内容,您可能需要删除辅助文件以强制其重新定位。
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}
\fill[blue] (0,0) circle (5);
\end{tikzpicture}
\begin{tikzpicture}[remember picture,overlay]
% I'll just use letters
\foreach \letter in {A,B,C,D,E}{
\pgfmathsetmacro\randA{random()}
\coordinate (A) at ($(current page.north west)!\randA!(current page.north east)$);
\pgfmathsetmacro\randB{random()}
\coordinate (B) at ($(current page.north west)!\randB!(current page.south west)$);
\coordinate (C) at ($(A |- B)$);
\typeout{A: \randA; B: \randB}
\node at (C) {\Huge \letter};
}
\end{tikzpicture}
\end{document}