TikZ 绘制视错觉图合集

发布于 2023-02-02 22:06:54

下面是从 tikz.net 摘录的视错觉的图合集:

缺失的三角形:

image.png

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
% definition of the pieces, just to show that in
% both configurations the same ones are used
\newcommand{\bluetriangle}[1][]{
  \draw[fill=blue,#1]
       (0,0)--( 8,0)--( 8,3)--cycle;}
\newcommand{\yellowtriangle}[1][]{
  \draw[fill=yellow,#1]
       (8,3)--(13,3)--(13,5)--cycle;}
\newcommand{\redpolygon}[1][]{
  \draw[fill=red,#1]
       (8,0)--(13,0)--(13,2)--(10,2)--(10,1)--(8,1)--cycle;}
\newcommand{\greenpolygon}[1][]{
  \draw[fill=green,#1]
       (8,1)--(10,1)--(10,2)--(13,2)--(13,3)--(8,3)--cycle;}
\begin{tikzpicture}[x=0.5cm,y=0.5cm,thick]
% the grid
  \draw[help lines,step=1] (-1,-1) grid (14,12);
% the complete triangle
    \bluetriangle
    \yellowtriangle
    \redpolygon
    \greenpolygon
% the missing square triangle
  \begin{scope}[yshift=3cm]
    \bluetriangle  [shift={( 5, 2)}]
    \yellowtriangle[shift={(-8,-3)}]
    \redpolygon    [shift={( 0, 0)}]
    \greenpolygon  [shift={(-3,-1)}]
  \end{scope}
% the solution (uncomment next line and close in)
%    \draw[very thin,red] (0,0)--(13,5) {[yshift=3cm] (0,0)--(13,5)};
\end{tikzpicture}
\end{document}

圆圈的大小

image.png

\documentclass[tikz,border=10pt]{standalone}
\newcommand{\centercircle}{\filldraw (0,0) circle(0.5);}
\begin{document}
%% definition of the circle in the center, just to show 
%% that in both configurations the same one is used
\begin{tikzpicture}
%% surrounded by big circles (looks smaller)
  \centercircle
  \foreach \a in {1,...,5}
    \filldraw (90+360/5*\a:1.8) circle(1);
%% surrounded by small circles (looks bigger)
  \begin{scope}[xshift=5cm]
    \centercircle
    \foreach \a in {1,...,5}
    \filldraw (90+360/5*\a:0.8) circle(0.2);
  \end{scope}
\end{tikzpicture}
\end{document}

变化的颜色

image.png

\documentclass[tikz,border=10pt]{standalone}
%% definition of the central band, just to show 
%% that in both configurations the same color is used
\newcommand{\colorband}[1][]{%
  \foreach \a in {0.2,0.6,...,4}
    \draw[line width=0.2cm,#1] (\a,1)--(\a,2);}
%% definition of the remaining part
\newcommand{\stripes}[1][]{%
  \foreach \b in {0,0.4,...,4}
    \draw[line width=0.2cm,#1] (\b,0)--(\b,3);}
\newcommand{\middlestripes}[1][]{%
  \foreach \b in {0.2,0.6,...,4}
    \draw[line width=0.2cm,#1] (\b,0)--(\b,1)(\b,2)--(\b,3);}
\begin{document}
\begin{tikzpicture}
%% red band, orange and magenta perception
  \colorband[red]
  \stripes[yellow]
  \middlestripes[blue]
  \begin{scope}[xshift=6cm]
    \colorband[red]
    \stripes[blue]
    \middlestripes[yellow]
  \end{scope}
  \begin{scope}[yshift=4cm]
%% green band, lime and cyan perception
    \colorband[green]
      \stripes[yellow]
      \middlestripes[blue]
    \begin{scope}[xshift=6cm]
      \colorband[green]
      \stripes[blue]
      \middlestripes[yellow]
    \end{scope}
  \end{scope}
\end{tikzpicture}
\end{document}

咖啡墙错觉

image.png

\documentclass[tikz,border=10pt]{standalone}
\newcommand{\cafestrip}[1][]{%
  \foreach \a in {1,...,6}
    {\draw[gray,very thick,fill=black,#1] (2*\a-1,0) rectangle(2*\a,1)  ;
     \draw[gray,very thick,fill=white,#1] (2*\a,0)   rectangle(2*\a+1,1);}
}
\begin{document}
\begin{tikzpicture}
%% the horizontal lines appear to slope
  \foreach \b/\c in {1/0,2/3,3/0,4/-3,5/0,6/3}
    \cafestrip[xshift=\c mm,yshift=\b cm];
\end{tikzpicture}
\end{document}

永远追不到的黑点

image.png

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
%% perception of black dots in the white circles
  \filldraw[black] (0,0) rectangle(12,9);
  \foreach \a in {1,...,7}
    \draw[line width=3mm,gray] (\a*1.5,0)--(\a*1.5,9);
  \foreach \b in {1,...,5}
    \draw[line width=3mm,gray] (0,\b*1.5)--(12,\b*1.5);
  \foreach \a in {1,...,7}
    \foreach \b in {1,...,5}
      \fill[white] (\a*1.5,\b*1.5) circle(0.2121);
\end{tikzpicture}
\end{document}
0 条评论

发布
问题