Draw a symmetric alien head
3,299
Solution 1
In simple cases like this you could just use a pic and mirror it.
\documentclass[tikz,border=3.14mm]{standalone}
\definecolor{maincolorMedium}{HTML}{a757b2}%
\begin{document}
\begin{tikzpicture}[pics/lhead/.style={code={
\draw[fill=maincolorMedium,even odd rule] (0,0) -- (-3,-4) -- (-3,-1) arc(270:0:3) (-3,0) rectangle (-1,2);}}]
\draw[dashed] (-6.5,-4.5) grid (6.5,5.5);
\path[fill opacity=0.4] (0,0) pic{lhead} pic[xscale=-1]{lhead};
\end{tikzpicture}
\end{document}
Solution 2
As a mathematical figure, it's a poor match.
But as an alien head in the style of Cthulhu, I think it gives the OP's a run for the money.
\documentclass{article}
\usepackage{graphicx,xcolor,stackengine}
\begin{document}
\bgroup
\savestack\halfhead{\Huge\stackinset{c}{3pt}{c}{23pt}{%
\color{red!15}\rule{7pt}{7pt}}{\scalebox{10}{,}}\kern-19pt}
\halfhead\reflectbox{\halfhead}
\egroup
\end{document}
Solution 3
A pstricks code:
\documentclass[border = 5pt, svgnames]{standalone}
\usepackage{pstricks}
\usepackage{auto-pst-pdf}% to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TeXLive, MacTeX)
\begin{document}
\begin{pspicture}[showgrid](-6.5, -6.5)(6.5, 3.5)
\psset{linewidth=0.6pt, linecolor=Plum, fillstyle=solid, fillcolor=white}
\pscustom[fillstyle=solid, fillcolor=Plum, opacity=0.4]{%
\psarc(-3,0){3}{0}{270}\psline(-3,-6)(0,-2)(3,-6)
\psarc(3,0){3}{-90}{180} }%
\psframe[](-3,-2)(-1,0)\psframe[](1,-2)(3,0)
\end{pspicture}
\end{document}
Solution 4
\documentclass[pstricks,border=4mm]{standalone}
\begin{document}
\def\Path{\psline(0,0)(-3,-4)(-3,-1)\psarcn(-3,2){3}{270}{0}\psframe(-3,0)(-1,2)}
\begin{pspicture}[showgrid](-6,-4)(6,5)
\pscustom[fillstyle=eofill,fillcolor={[HTML]{a757b2}},opacity=0.4]{%
\Path\moveto(0,0)\code{-1 1 scale}\Path}
\end{pspicture}
\end{document}
Solution 5
Just another customizable template with PSTricks. It will be useful for others who look for non-alien head.
\documentclass[pstricks,border=12pt,12pt]{standalone}
\def\obj{%
\psline(0,0)(-1,0)(-2,1)(-3,0)(-3,-2)(0,-2)
\moveto(0,-3)
\psline(-4,-3)(-4,1)(-3,4)(-2,2)(0,2)
\psframe(2.5,1.5)(3.25,2.5)
\pscircle(3,1){.2}}
\begin{document}
\begin{pspicture}[showgrid=b](-5,-5)(5,5)
\pscustom[fillstyle=eofill,fillcolor=red]{\obj\reversepath\scale{-1 1}\obj}
\end{pspicture}
\end{document}
Related videos on Youtube
Author by
N3buchadnezzar
Updated on August 01, 2022Comments
-
N3buchadnezzar over 1 year
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}
-
Admin over 4 yearsfillcolor={[HTML]{a757b2}} Where can we find? (I think it is a new feature)
-
user187802 over 4 yearsDocumentation of
xcolor
-
Erlkoenig over 4 yearsIt's worth mentioning that the "even odd rule" produces the squares by making a path with a hole, i.e. the squares are truly transparent.
-
Admin over 4 years@Erlkoenig Yes, this is the intention behind this. Otherwise the grid will be covered, as in Bernhard's answer below.
-
Erlkoenig over 4 yearsRight, just wanted to make it clear in case anyone wonders how it works.
-
Admin over 4 years@Erlkoenig Thanks!