Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Countryball (if I'm not mistaken originally Polandball) is a web comic versing on crude political jokes, some of which I find hilarious. In some sense, the idea is analogous to the spherical cow simplification The protagonists are countries represented by figures tinged by the colors of the respective flag. These figures are spheres, ellipsoids or egg-like objects (excepting Israel, Singapore, Kazakhstan and –obviously– Nepal). Moreover there are some (perfectly questionable) "rules" like:

  1. Spheres cannot be perfect
  2. No limbs, no pupils …
  3. No lines between the different colors of a flag, etc.

Countryballs look like this. Long story short, I was wondering if it is possible to implement this with TikZ. So here is my first attempt. I based on the code of this question in order to make the eyes of this ball associated to a (hopefully unexisent) flag:

\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}

While it is not expected to obtain beautiful countryballs, my code is not satisfying at all. It produces this

enter image description here

As you can see, the circle doesn't close.

Question: Could somebody fix this circle and produce a more realistic ball?

3D Implementation

I first tried in 3D. The only thing I achieve is the "non-being" spherical. This is the code

\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}

Question: How to independently color the hemispheres (either "vertically" or "horizontally"), or more generally, how to color stripes (usually 3) of different colors?

enter image description here

share|improve this question
1  
The intention was to specifically miss the closing to emphasize hand drawing :p –  percusse Dec 15 '13 at 0:18

1 Answer 1

up vote 9 down vote accepted

Ok, the trick here is to use a path picture and clip the path for each strip and then shade the entire path picture area letting the clipping "do all the work". Everything can then be tied up in keys.

\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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.