如何让这些代码更具表现力?在 tikz 中追踪线条

如何让这些代码更具表现力?在 tikz 中追踪线条

如何让这些代码更加具有表现力??

\begin{tikzpicture}[scale=.8, font=\footnotesize]
    \begin{axis}[domain=-1:15, xmin=-1, xmax=13, ymin=-1, ymax=14, axis y line=center, axis x line=middle]  


    \node[purple,visible on=<2->] (O) [below left] at (axis cs:0,0) {$0$};

        \draw [fill, purple,visible on=<3->] (axis cs: 0,10) circle [radius=3pt];
        \draw [fill, purple,visible on=<3->] (axis cs: 10,0) circle [radius=3pt];
        \node [visible on=<4>] at (axis cs: 6,10) {Connect the points};
        \addplot +[mark=none,fill,opacity=3, blue,visible on=<4->,thick,<->,domain=-1:11] {10-x}  node[pos=0] (blue) {};
        \node[right = of blue,visible on=<5->] () {\color{blue}\footnotesize {$x+y=10$}};

        \node[purple,visible on=<5->] (B) [above right] at (axis cs:8,5) {\Large It's Easy!};
    \end{axis}
    \end{tikzpicture}

我正在使用上述代码在 beamer 中生成“如何为学童构建一条线?”的一个小例子。

如何才能使这些代码更具表现力?

例如,如果我可以通过追踪将点 (10,0) 连接到 (0,10),那么这很容易实现,而不仅仅是在下一张幻灯片中显示线。

欢迎提出建议吗?

我是否应该使用动画?或者有任何简单的方法可以做到这一点?

我得到的是这个...... 在此处输入图片描述

答案1

只是一个使用铅笔和尺子的想法铅笔、尺子和圆规的符号

在此处输入图片描述

首先,我采用了 Harish 代码并进行了修改:

\documentclass[tikz,border=0cm]{standalone}
\usepackage{tikz}

\tikzset{
    pencil/.pic={
        \fill[gray!50] (0,4) -- (0.4,4) -- (0.4,0) --(0.3,-0.15) -- (0.2,0) -- (0.1,-0.14) -- (0,0) -- cycle;
      \draw[color=white] (0.2,4) -- (0.2,0);
      \fill[red] (0,3.5) -- (0.2,3.47) -- (0.4,3.5) -- (0.4,4) arc(30:150:0.23cm);
      \fill[brown!40] (0,0) -- (0.2,-0.8)node[coordinate,pos=0.75](a){} -- (0.4,0)node[coordinate,pos=0.25](b){} -- (0.3,-0.15) -- (0.2,0) -- (0.1,-0.14) -- cycle;
      \fill[red] (a) -- (0.2,-0.8) -- (b) -- cycle;
    },
    ruler/.pic={
            \begin{scope}[rotate=0, transform shape]
            \draw (-0.2,0) rectangle (10.2,1);
            %% Upper divisions
            \foreach \x in {0,1,...,10}{
            \draw (\x,1) -- (\x,0.8)node[below,scale=0.4]{\x};
            }
            \foreach \x in {0.1,0.2,...,9.9}{
            \draw (\x,1) -- (\x,0.925);
            }
            \foreach \x in {0.5,1,...,9.5}{
            \draw (\x,1) -- (\x,0.85);
            }
                \end{scope}
    }
}   
\begin{document}
        \begin{tikzpicture}
        \draw pic[]{ruler=10cm};
        \end{tikzpicture}
        \begin{tikzpicture}
        \draw pic[]{pencil};
        \end{tikzpicture}
\end{document}

我曾尝试使用铅笔和尺子作为pics内部beamer演示文稿,但我买不起(主要是由于比例问题),所以我最终将其转换为外部图形,并将其包含在演示文稿\includegraphicsnode

之前演示的代码是:

\documentclass{beamer}
\usepackage{pgfplots}
\usetikzlibrary{positioning}

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    }
}    

\begin{document}

\begin{frame}[fragile]{}
\begin{tikzpicture}[scale=.8, font=\footnotesize]
    \begin{axis}[domain=-1:15, xmin=-1, xmax=13, ymin=-1, ymax=14, axis y line=center, axis x line=middle, clip =false]  

    \node[purple,visible on=<2->] (O) [below left] at (axis cs:0,0) {$0$};
    \draw [fill, purple,visible on=<3->] (axis cs: 0,10) circle [radius=3pt];
    \draw [fill, purple,visible on=<3->] (axis cs: 10,0) circle [radius=3pt];
    \node [visible on=<4>, inner sep=0pt, outer sep=0pt, anchor=170, rotate=-50] at (axis cs:0,10) {\includegraphics[page=1]{ruler-pencil}};

    \node [visible on=<5-8>, inner sep=0pt, outer sep=0pt, anchor=170, rotate=-37.7] at (axis cs:0,10) {\includegraphics[page=1]{ruler-pencil}};

    \node [visible on=<6>, inner sep=0pt, outer sep=0pt, anchor=south, rotate=-20] at (axis cs:-1,11) {\includegraphics[page=2,scale=.75]{ruler-pencil}};

    \node [visible on=<7>, inner sep=0pt, outer sep=0pt, anchor=south, rotate=-20] at (axis cs:4,6) {\includegraphics[page=2,scale=.75]{ruler-pencil}};

    \node [visible on=<8>, inner sep=0pt, outer sep=0pt, anchor=south, rotate=-20] at (axis cs:11,-1) {\includegraphics[page=2]{ruler-pencil}};

    \addplot +[mark=none,fill,opacity=3, red,visible on=<7>,thick,<->,domain=-1:4] {10-x}  node[pos=0] (blue) {};

    \addplot +[mark=none,fill,opacity=3, red,visible on=<8->,thick,<->,domain=-1:11] {10-x}  node[pos=0] (blue) {};

    \node[right = of blue,visible on=<9->] () {\color{red}\footnotesize {$x+y=10$}};
    \node[purple,visible on=<9->] (B) [above right] at (axis cs:8,5) {\Large It's Easy!};
    \end{axis}
\end{tikzpicture}
\end{frame}
\end{document}

我应该说,由于 x 和 y 轴刻度不同,标尺的旋转角度是通过反复试验找到的。

相关内容