I am trying to draw the following "symmetrical alien head":
Using the mirror code from Can we mirror a part in tikz? I was able to produce the following result
While the result looks good I am not particularly happy with the code, as I had to juggle a lot of coordinates and a lot of manual adjustments had to be made. In particular
- Is there an easier way to remove the white squares from the figure while still keeping the transparent background?
- Can one make one half of the face and then mirror or across
x=6? I tried this, but it was only possible with the coordinates not the fill functions.
Other solutions using TikZ, Asymptote, MetaPost, PSTricks are also welcome.
\documentclass[border=2mm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all} % on charge tous les objets
\definecolor{maincolorMedium}{HTML}{a757b2}%
\makeatletter
\tikzset{
mirror/.code={\pgfutil@in@{--}{#1}\ifpgfutil@in@\tikz@trans@mirror#1\@nil
\else\tikz@scan@one@point\pgftransformmirror#1\relax\fi},
ymirror/.code={\pgfutil@ifnextchar(\tikz@trans@ymirror@coordinate\tikz@trans@ymirror@simple#1\@nil},
xmirror/.code={\pgfutil@ifnextchar(\tikz@trans@xmirror@coordinate\tikz@trans@xmirror@simple#1\@nil}}
\def\tikz@trans@mirror#1--#2\@nil{%
\pgfextract@process\pgf@trans@mirror@A{\tikz@scan@one@point\pgfutil@firstofone#1}%
\pgfextract@process\pgf@trans@mirror@B{\tikz@scan@one@point\pgfutil@firstofone#2}%
\pgftransformMirror{\pgf@trans@mirror@A}{\pgf@trans@mirror@B}}
\def\pgftransformxmirror#1{\pgfmathparse{2*(#1)}\pgftransformcm{-1}{0}{0}{1}{\pgfqpoint{+\pgfmathresult pt}{+0pt}}}
\def\pgftransformymirror#1{\pgfmathparse{2*(#1)}\pgftransformcm{1}{0}{0}{-1}{\pgfqpoint{+0pt}{+\pgfmathresult pt}}}
\def\tikz@trans@ymirror@simple#1\@nil{
\pgfmathparse{#1}\let\tikz@temp\pgfmathresult
\ifpgfmathunitsdeclared
\pgftransformymirror{\tikz@temp pt}%
\else
\pgf@process{\pgfpointxy{0}{\tikz@temp}}%
\pgftransformymirror{+\the\pgf@y}%
\fi}
\def\tikz@trans@xmirror@simple#1\@nil{
\pgfmathparse{#1}\let\tikz@temp\pgfmathresult
\ifpgfmathunitsdeclared
\pgftransformxmirror{\tikz@temp pt}%
\else
\pgf@process{\pgfpointxy{\tikz@temp}{0}}%
\pgftransformxmirror{+\the\pgf@x}%
\fi}
\def\tikz@trans@xmirror@coordinate#1\@nil{\tikz@scan@one@point\pgfutil@firstofone#1\pgftransformxmirror{+\the\pgf@x}}
\def\tikz@trans@ymirror@coordinate#1\@nil{\tikz@scan@one@point\pgfutil@firstofone#1\pgftransformymirror{+\the\pgf@y}}
\def\pgftransformmirror#1{%
\pgfpointnormalised{#1}%
\pgf@xa=\pgf@sys@tonumber\pgf@y\pgf@x
\pgf@xb=\pgf@sys@tonumber\pgf@x\pgf@x
\pgf@yb=\pgf@sys@tonumber\pgf@y\pgf@y
\multiply\pgf@xa2\relax
\pgf@xc=-\pgf@yb\advance\pgf@xc\pgf@xb
\pgf@yc=-\pgf@xb\advance\pgf@yc\pgf@yb
\edef\pgf@temp{{\the\pgf@xc}{+\the\pgf@xa}{+\the\pgf@xa}{+\the\pgf@yc}}%
\expandafter\pgf@transformcm\pgf@temp{\pgfpointorigin}}
\def\pgftransformMirror#1#2{%
\pgfextract@process\pgf@trans@mirror@A{#1}%
\pgfextract@process\pgf@trans@mirror@B{#2}%
\pgfextract@process\pgf@trans@mirror@g{\pgfpointdiff{\pgf@trans@mirror@A}{\pgf@trans@mirror@B}}%
\pgftransformshift{\pgf@trans@mirror@A}%
\pgftransformmirror{\pgf@trans@mirror@g}%
\pgftransformshift{\pgfpointscale{-1}{\pgf@trans@mirror@A}}}
\makeatother
\begin{document}
\begin{tikzpicture}
\def\opa{0.4}
\tkzInit[xmin=-0.5,xmax=12.5, ymin=-0.5,ymax=9.5]
% Draw dashed grid
\begin{scope}[dashed]
\tkzGrid
\end{scope}
% Def points
\tkzDefPoint(3,0){A}
\tkzDefPoint(3,3){B}
\tkzDefPoint(6,4){C}
\tkzDefPoint(6,6){D}
% Define the white squares
\tkzDefPoint(5,4){e1}\tkzDefPoint(5,6){e2}\tkzDefSquare(e1,e2) \tkzGetPoints{e3}{e4}
\begin{scope}[xmirror=6]
\tkzDefPoint(3,0){A1}
\tkzDefPoint(3,3){B1}
\tkzDefPoint(5,4){f1}\tkzDefPoint(5,6){f2}
\end{scope}
\tkzDefSquare(f2,f1) \tkzGetPoints{f3}{f4}
% Fill the figure
\tkzFillPolygon[color=maincolorMedium,opacity=\opa](A,e4,C)
\tkzFillPolygon[color=maincolorMedium,opacity=\opa](A1,f3,C)
\tkzFillPolygon[color=maincolorMedium,opacity=\opa](e1,f1,f2,e2)
\tkzFillSector[color=maincolorMedium,opacity=\opa](e3,D)(B)
\tkzFillSector[color=maincolorMedium,opacity=\opa](f4,B1)(D)
% Perform the outline
\tkzDrawArc[color=black,thick](e3,D)(B)
\tkzDrawArc[color=black,thick](f4,B1)(D)
\tkzDrawSquare[thick](e1,e2)\tkzDrawSquare(f2,f1)
\tkzDrawSegments[thick](B,A A,C C,A1 A1,B1)
\end{tikzpicture}
\end{document}






