如何使用 TikZ 绘制 Stack Overflow 图标?

如何使用 TikZ 绘制 Stack Overflow 图标?

你会如何绘制堆栈溢出带有 TikZ 的图标?

答案1

这是第一种方法:

\documentclass[tikz, border=20mm]{standalone}

\definecolor{soorange}{RGB}{244,128,36}
\definecolor{sogray}{RGB}{188,187,187}

\pgfmathsetmacro\ae{54}          % end angle
\pgfmathsetmacro\as{.25*\ae}     % start angle
\pgfmathsetmacro\ch{29}          % cup height
\pgfmathsetmacro\cw{69}          % cup width
\pgfmathsetmacro\sw{44}          % stack width
\pgfmathsetmacro\sc{43}          % stack clip
\pgfmathsetmacro\sy{17}          % stack yshift
\pgfmathsetmacro\sx{\sc+.5*\sw}  % stack xshift
\pgfmathsetmacro\eh{9}           % line width

\begin{document}

\begin{tikzpicture}[x=1mm, y=1mm,
    stack/.style={line width=9mm, soorange},
    cup/.style={line width=9mm, sogray}
    ]
    \draw[cup] (-.5*\cw,\ch) -- (-.5*\cw,0) -- (.5*\cw,0) -- (.5*\cw,\ch);
    \begin{scope}[shift={(\sx,\sy)}]
        \foreach \x in {0,\as,...,\ae}
            \draw[stack] (180-\x:\sc) -- (180-\x:\sc+\sw);
    \end{scope}
\end{tikzpicture}

\end{document}

我希望我没有违反Stack Exchange 商标使用指南!如果是的话,请告诉我。

堆栈溢出图标

答案2

  • 我已经下载了EPS 格式的官方徽标
  • 然后我用韋斯維爾将其转换为 svg:

    dvisvgm --eps so-logo.eps so-logo.svg
    
  • 然后我在 chrome 中打开了 svg,并使用“检查元素”识别出了代码中的徽标部分

    <path clip-path="url(#clip1)" d="M84.0703 -10.52V-42.0703H94.5898V0H0V-42.0703H10.5156V-10.52H84.0703Z" fill="#bbc8c8"/>
    <path clip-path="url(#clip1)" d="M21.043 -21.0352H73.625V-31.5508H21.043V-21.0352ZM68.1719 -117.867L59.7344 -111.594L91.1133 -69.4023L99.5508 -75.6797L68.1719 -117.867ZM42.0898 -92.9961L82.4922 -59.3437L89.2227 -67.4258L48.8164 -101.074L42.0898 -92.9961ZM28.8984 -69.6094L76.5625 -47.4102L81.0039 -56.9453L33.3359 -79.1445L28.8984 -69.6094ZM22.0898 -44.9727L73.5469 -34.1562L75.7109 -44.4492L24.25 -55.2617L22.0898 -44.9727Z" fill="#fe6303"/>
    
  • 因此最后使用svg.path我获得的库通过复制/粘贴徽标。

    \documentclass[tikz, border=7mm]{standalone}
    \usetikzlibrary{svg.path}
    \definecolor{org}{HTML}{FE6303}
    \definecolor{gry}{HTML}{BBC8C8}
    
    \begin{document}
      \begin{tikzpicture}[yscale=-1]
        \fill[gry] svg{M84.0703 -10.52V-42.0703H94.5898V0H0V-42.0703H10.5156V-10.52H84.0703Z};
        \fill[org] svg{M21.043 -21.0352H73.625V-31.5508H21.043V-21.0352ZM68.1719 -117.867L59.7344 -111.594L91.1133 -69.4023L99.5508 -75.6797L68.1719 -117.867ZM42.0898 -92.9961L82.4922 -59.3437L89.2227 -67.4258L48.8164 -101.074L42.0898 -92.9961ZM28.8984 -69.6094L76.5625 -47.4102L81.0039 -56.9453L33.3359 -79.1445L28.8984 -69.6094ZM22.0898 -44.9727L73.5469 -34.1562L75.7109 -44.4492L24.25 -55.2617L22.0898 -44.9727Z};
      \end{tikzpicture}
    \end{document}
    

在此处输入图片描述

澄清说明

如果有人认为设计这个标志的人是一位数学家,并且这些线条是通过简单的旋转获得的,那么他可以查看以下图片:

在此处输入图片描述

获取该图像的代码如下:

\documentclass[tikz, border=7mm]{standalone}
\usetikzlibrary{svg.path, calc, spy}
\definecolor{org}{HTML}{FE6303}
\definecolor{gry}{HTML}{BBC8C8}

\begin{document}
  \begin{tikzpicture}[spy using outlines={circle, blue, magnification=3, size=1.5cm, connect spies}]
    \begin{scope}[yscale=-1,x=1pt,y=1pt]
      \fill[gry] svg{M84.0703 -10.52V-42.0703H94.5898V0H0V-42.0703H10.5156V-10.52H84.0703Z};
      \fill[org] svg{M21.043 -21.0352H73.625V-31.5508H21.043V-21.0352ZM68.1719 -117.867L59.7344 -111.594L91.1133 -69.4023L99.5508 -75.6797L68.1719 -117.867ZM42.0898 -92.9961L82.4922 -59.3437L89.2227 -67.4258L48.8164 -101.074L42.0898 -92.9961ZM28.8984 -69.6094L76.5625 -47.4102L81.0039 -56.9453L33.3359 -79.1445L28.8984 -69.6094ZM22.0898 -44.9727L73.5469 -34.1562L75.7109 -44.4492L24.25 -55.2617L22.0898 -44.9727Z};

      % take the coordinates
      \draw[blue]
        (21.043 , -21.0352) coordinate (A1) -- (73.625 , -21.0352) coordinate (B1) (73.625 , -31.5508) coordinate (C1)-- (21.043 , -31.5508) coordinate (D1)
        (22.0898, -44.9727) coordinate (A2) -- (73.5469, -34.1562) coordinate (B2) (75.7109, -44.4492) coordinate (C2)-- (24.25  , -55.2617) coordinate (D2)
        (28.8984, -69.6094) coordinate (A3) -- (76.5625, -47.4102) coordinate (B3) (81.0039, -56.9453) coordinate (C3)-- (33.3359, -79.1445) coordinate (D3)
        (42.0898, -92.9961) coordinate (A4) -- (82.4922, -59.3437) coordinate (B4) (89.2227, -67.4258) coordinate (C4)-- (48.8164, -101.074) coordinate (D4)
        (59.7344, -111.594) coordinate (A5) -- (91.1133, -69.4023) coordinate (B5) (99.5508, -75.6797) coordinate (C5)-- (68.1719, -117.867) coordinate (D5);
      % draw the middle lines
      \begin{scope}[black, shorten >=-3cm]
        \draw ($(A1)!.5!(D1)$) -- ($(C1)!.5!(B1)$);
        \draw ($(A2)!.5!(D2)$) -- ($(C2)!.5!(B2)$);
        \draw ($(A3)!.5!(D3)$) -- ($(C3)!.5!(B3)$);
        \draw ($(A4)!.5!(D4)$) -- ($(C4)!.5!(B4)$);
        \draw ($(A5)!.5!(D5)$) -- ($(C5)!.5!(B5)$);
      \end{scope}
    \end{scope}
    % spy on the crossings
    \spy on (4.5,1) in node at (5,3);
  \end{tikzpicture}
\end{document}

相关内容