使用 TikZ 制作“Countryball”漫画。如何为带有不同条纹的 3D 对象添加阴影?

使用 TikZ 制作“Countryball”漫画。如何为带有不同条纹的 3D 对象添加阴影?

乡村球(如果我没记错的话波兰球)是一部网络漫画,内容是粗俗的政治笑话,我觉得其中一些笑话很搞笑。从某种意义上说,这个想法类似于球形牛简化主角是国家,代表人物的颜色与各自国旗的颜色相同。这些人物是球体、椭圆体或蛋形物体(以色列、新加坡、哈萨克斯坦和尼泊尔除外)。此外,还有一些(完全值得怀疑的)“规则”,例如:

  1. 球体不可能完美
  2. 没有四肢,没有瞳孔……
  3. 旗帜等的不同颜色之间没有界线。

乡村球看起来像。长话短说,我想知道是否可以使用 TikZ 实现这一点。所以这是我的第一次尝试。我根据代码这个问题为了让这个球的眼睛与一面旗帜(希望不存在)相关联:

\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing,patterns}
\pgfdeclaredecoration{penciline}{initial}{
    \state{initial}[width=+\pgfdecoratedinputsegmentremainingdistance,
    auto corner on length=1mm,]{
        \pgfpathcurveto%
        {% From
            \pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}
                      {\pgfdecorationsegmentamplitude}
        }
        {%  Control 1
        \pgfmathrand
        \pgfpointadd{\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}{1pt}}
                    {\pgfqpoint{-\pgfdecorationsegmentaspect
                     \pgfdecoratedinputsegmentremainingdistance}%
                               {\pgfmathresult\pgfdecorationsegmentamplitude}
                    }
        }
        {%TO 
        \pgfpointadd{\pgfpointdecoratedinputsegmentlast}{\pgfpoint{.3pt}{.4pt}}
        }
    }
    \state{final}{}
}

\begin{document}


\begin{tikzpicture}[decoration=penciline, decorate]
%\draw (-2, 1.5) rectangle (2, -1.5);
\begin{scope}
\clip (-0.8, 0) ellipse (1 and 3);
%\clip ( 1, 0) ellipse (1 and 4);
\clip ( 0.5, 0) circle (1);
\fill[color=yellow!85!black] (-2,1.5)
rectangle (2,-1.5);
\end{scope}
\begin{scope}
\clip (1.8, 0) ellipse (1 and 3);
%\clip ( 1, 0) ellipse (1 and 4);
\clip ( 0.5, 0) circle (1);
\fill[color=red!75!black] (-2,1.5)
rectangle (2,-1.5);
\end{scope}
    \draw[
      decoration={random steps,segment length=.3cm,amplitude=.05cm},
      decorate,
      rounded corners=.13cm, ultra thick
    ] (.5, 0) circle (.95);
   % right eye 
   \draw[decorate,fill=white, thick] (0.85,.23) ellipse (.22 and .08);
   % left eye 
   \draw[decorate,fill=white, thick] (0.02,.23) ellipse (.22 and .08);
\end{tikzpicture}

\end{document}

虽然不指望能得到漂亮的球,但我的代码一点也不令人满意。它产生了这个

在此处输入图片描述

正如你所见,圆圈并没有闭合。

问题:有人可以修复这个圆圈并制作出一个更逼真的球吗?

3D 实现

我首先尝试了 3D。我唯一实现的就是“不存在”的球形。这是代码

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\pgfmathsetseed{42}


\usepackage{tikz}
\usetikzlibrary{calc,fadings,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\filldraw[ball color=red,decoration={random steps,segment length=.7cm,amplitude=.1cm},decorate,rounded corners=.3cm,ultra thick] (0,0) circle (8.5);
\end{tikzpicture}
\end{document}

问题:如何独立地为各半球着色(“垂直”或“水平”),或者更一般地,如何为不同颜色的条纹(通常为 3 种)着色?

在此处输入图片描述

答案1

好的,这里的技巧是使用path picture并剪切每个条带的路径,然后对全部的路径图片区域让剪辑“完成所有工作”。然后所有内容都可以绑定到键中。

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing}
\newcount\countryballcolorcount
\newif\ifcountryballhorizontal
\tikzset{sketch/.style={%
  rounded corners=.15cm, 
  ultra thick,
  decoration={%
    random steps,
    segment length=0.7cm,
    amplitude=0.1cm,
    pre=lineto, pre length=0.1cm,
    post=lineto, post length=.1cm
  },
  decorate},
  country ball colors/.store in=\countryballcolors,
  country ball horizontal/.is if=countryballhorizontal,
  country ball/.style={#1,
    path picture={%
      \countryballcolorcount=0\relax
      \csname pgfutil@for\endcsname\c:=\countryballcolors\do{%
       \advance\countryballcolorcount by1\relax
      }%
      \foreach \c [count=\i from 0] in \countryballcolors{
        \begin{scope}
          \ifnum\i>0
            % Clip the part of the picture to be shaded.
            \ifcountryballhorizontal
              \clip (path picture bounding box.south west) --
                ($(path picture bounding box.north west)!{\i/\countryballcolorcount}!(path picture bounding box.south west)$)    
                decorate {% sketch is still the prevailing decoration
                  -- ($(path picture bounding box.north east)!{\i/\countryballcolorcount}!(path picture bounding box.south east)$)
                }
                --  (path picture bounding box.south east) -- cycle;
            \else
              \clip (path picture bounding box.south east) --
                ($(path picture bounding box.south west)!{\i/\countryballcolorcount}!(path picture bounding box.south east)$)    
                decorate {% sketch is still the prevailing decoration
                  -- ($(path picture bounding box.north west)!{\i/\countryballcolorcount}!(path picture bounding box.north east)$)
                }
                --  (path picture bounding box.north east) -- cycle;
            \fi
          \fi
          % Shade the *entire* picture
          \path [shading=ball, ball color=\c]
            (path picture bounding box.south west)
            rectangle
            (path picture bounding box.north east);
       \end{scope}
    }
  }
}}
\begin{document}

\begin{tikzpicture}

\draw [sketch, country ball={country ball colors={yellow!85!black, white, red!75!black}}]
  (0,0) circle [radius=5];
\draw [sketch, country ball={country ball horizontal, country ball colors={yellow!85!black, white, red!75!black}}]
  (0,-11) circle [radius=5];
\draw [sketch, country ball={country ball colors={yellow!85!black, white, red!75!black, green!50!black, blue!75!black}}]
  (0,-22) circle [radius=5];

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容