Tikz를 사용하여 이 다이어그램(기계 기능)을 그리는 방법은 무엇입니까?

Tikz를 사용하여 이 다이어그램(기계 기능)을 그리는 방법은 무엇입니까?

아래 다이어그램을 재현하고 싶지만 해당 모양에 대한 "코드"를 찾을 수 없습니다. 내가 살펴본 샘플 다이어그램에는 직사각형을 가리키고 있는 화살표가 있는 닫힌 직사각형이 표시되어 있습니다. 어떤 도움이라도 대단히 감사하겠습니다. 여기에 이미지 설명을 입력하세요

첨부된 내용은 Jasper가 제안한 현재 MWE입니다.

\tikzstyle{Box} = [rectangle, rounded corners, minimum width=2cm, minimum height=1.25cm, text centered, draw=blue, inner color=white, outer color=blue!30]
\tikzstyle{arrow} = [red, very thick,->,>=stealth]

\begin{center}
\begin{tikzpicture}[node distance=2.5cm]
\node (A) [Box] {\(f\)};
\node (B) [left of=A, label=below:{input}] {$x$};
\node (C) [right of=A, label=below:{output}] {$y$};
\draw [arrow] (B) -- (A);
\draw [arrow] (A) -- (C);
\end{tikzpicture}
\end{center}

답변1

모양이 없으면 다음을 만들 수 있습니다 \pic.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}

\tikzset{
    pics/machine/.style={
        code={
            \coordinate (-in) at ({-0.5*\pgfkeysvalueof{/tikz/machine/width}},0);
            \coordinate (-out) at ({0.5*\pgfkeysvalueof{/tikz/machine/width}},0);
            \coordinate (-north) at (0,{0.5*\pgfkeysvalueof{/tikz/machine/height}});
            \coordinate (-south) at (0,{-0.5*\pgfkeysvalueof{/tikz/machine/height}});
            \path[/tikz/machine/filling]
                ([shift={(-0.75em,0.5em)}]-in) 
                -- ([shift={(0,0.25em)}]-in) 
                -- ([shift={(0,-5pt)}]-north -| -in)
                arc[start angle=180, end angle=90, radius=5pt]
                -- ([shift={(-5pt,0)}]-north -| -out)
                arc[start angle=90, end angle=0, radius=5pt]
                -- ([shift={(0,0.25em)}]-out) 
                -- ([shift={(0.75em,0.5em)}]-out)
                -- ([shift={(0.75em,-0.5em)}]-out)
                -- ([shift={(0,-0.25em)}]-out) 
                -- ([shift={(0,5pt)}]-south -| -out)
                arc[start angle=360, end angle=270, radius=5pt]
                -- ([shift={(5pt,0)}]-south -| -in)
                arc[start angle=270, end angle=180, radius=5pt]
                -- ([shift={(0,-0.25em)}]-in) 
                -- ([shift={(-0.75em,-0.5em)}]-in) 
                -- cycle;
            \draw[/tikz/machine/border]
                ([shift={(-0.75em,0.5em)}]-in) 
                -- ([shift={(0,0.25em)}]-in) 
                -- ([shift={(0,-5pt)}]-north -| -in)
                arc[start angle=180, end angle=90, radius=5pt]
                -- ([shift={(-5pt,0)}]-north -| -out)
                arc[start angle=90, end angle=0, radius=5pt]
                -- ([shift={(0,0.25em)}]-out) 
                -- ([shift={(0.75em,0.5em)}]-out);
            \draw[/tikz/machine/border]
                ([shift={(0.75em,-0.5em)}]-out)
                -- ([shift={(0,-0.25em)}]-out) 
                -- ([shift={(0,5pt)}]-south -| -out)
                arc[start angle=360, end angle=270, radius=5pt]
                -- ([shift={(5pt,0)}]-south -| -in)
                arc[start angle=270, end angle=180, radius=5pt]
                -- ([shift={(0,-0.25em)}]-in) 
                -- ([shift={(-0.75em,-0.5em)}]-in);
            \node (-node) at (0,0) {#1};
        }
    },
    machine/width/.initial={3.5em},
    machine/height/.initial={2em},
    machine/filling/.style={
        left color=cyan!50!blue!25, 
        right color=cyan!50!blue!25, 
        middle color=cyan!50!blue!10
    },
    machine/border/.style={
        blue!50!cyan
    }
}

\begin{document}
\begin{tikzpicture}

    \node[label={below:{input}}] (A) at (0,0) {$x$}; 
    \pic (B) at (2,0) {machine={$f$}};
    \node[label={below:{output}}] (C) at (4,0) {$f(x)$}; 

    \draw[red, -stealth] (A) -- (B-in);  
    \draw[red, -stealth] (B-out) -- (C);  

\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보