# Challenge! Create aTikZ style to mimic mirror reflection (with option for curvature distortion)

When we see images that are reflected at a mirror, or at the eyes of someone, or at the water, there is some light effect that tells our brains the image we are seeing is a reflection.

Some of Escher pictures illustrate this very well: or

I'm looking for ideas or suggestions on how to create this effect using TikZ. The concept is to have a style that we could apply to an arbitrary picture to obtain the picture looking as if it were a reflection.

I'm not trying to simply mirror a TikZ picture but rather trying to make appear as if the picture is a reflection. I will post a bounty as soon as I can to reward the best answer. The MWE requirement clearly does not apply here.

• There is not far to seek: the first page of pgfmanual is a good example... – Paul Gaborit Jun 5 '14 at 0:49
• If the reflection happens on a flat surface, then the reflection will be identical to the original (except for the left-to-right inversion). All you can do to suggest a reflection is to reduce its opacity. If the reflection happens on a non-flat surface, then you are asking about distortions, not reflections (and your posted pictures suggest that this kind of reflectio is what you have in mind) – JLDiaz Jun 5 '14 at 7:36
• @JLDiaz: yes because even mirrors are not perfectly flat. – Sergio Parreiras Jun 6 '14 at 5:31
• Inspiration can be found in the pst-mirror package. I haven't tried nonlinear transformation in TikZ for this task, but it might be a way. It's written in Section 104 (Coordinate, Canvas, and Nonlinear Transformations) in the TikZ3 manual. – Malipivo Jun 7 '14 at 6:28
• I am really not sure this is best done within TeX at all. There are specialised applications for rendering these kinds of distortions and reflections and they will surely give more satisfactory results than something in TikZ. (And this is by no means to criticise what is a stupendously impressive and useful package. Just no software can do everything well. This is a time for the 'Unix' philosophy, perhaps. Paraphrasing: one tool, one job and every tool will work well; one tool, two jobs and you start making compromises.) – cfr Jun 8 '14 at 0:47

## 3 Answers

Run with latex->dvips->ps2pdf. The image must be an eps type (vector graphics):

\documentclass{article}
\usepackage{pst-mirror,graphicx}
\begin{document}

\begin{pspicture}(-5,-5)(5,5)
\psframe*(-5,-5)(5,5)
\pscircle*[linecolor=blue!50]{!7 2 sqrt div}
\psset{Rayon=7}
\pstSphereImage(5,0,0){tiger.eps}
\pstSphereGrid[linecolor=white,linewidth=0.01,grille=5,Ymin=-100,Ymax=100,Xmax=100,Xmin=-100](5,0,0)%
\end{pspicture}

\reflectbox{\includegraphics[width=4cm]{tiger}}

\end{document}


I'm posting Paul's comment as a community wiki. I would remove it if Paul decides to publish the answer himself.

This is front cover of pgfmanual and the code, well you can find it on the first page of the document! Stand alone version of the page was submitted to TeXample by Ludger Humbert. Copyright of Till Tantau I assume...

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{%
decorations.fractals%
,decorations.pathmorphing%
,shadows%
}

\begin{document}
\parindent0pt
\null
\colorlet{mintgreen}{green!50!black!50}

\thispagestyle{empty}
\vskip3cm
\vfill
\hfil
\begin{tikzpicture}[overlay]
\coordinate (front) at (0,0);
\coordinate (horizon) at (0,.31\paperheight);
\coordinate (bottom) at (0,-.6\paperheight);
\coordinate (sky) at (0,.57\paperheight);
\coordinate (left) at (-.51\paperwidth,0);
\coordinate (right) at (.51\paperwidth,0);

\shade [bottom color=blue!30!black!10,top color=blue!30!black!50]
([yshift=-5mm]horizon -|  left) rectangle (sky -| right);
\shade [bottom color=black!70!green!25,top color=black!70!green!10]
(front -| left) -- (horizon -| left)
decorate [decoration=random steps] { -- (horizon -| right) }
-- (front -| right) -- cycle;
\shade [top color=black!70!green!25,bottom color=black!25]
(front -| left) -- (horizon -| left)
decorate [decoration=random steps] { -- (horizon -| right) }
-- (front -| right) -- cycle;
\shade [top color=black!70!green!25,bottom color=black!25]
([yshift=-5mm-1pt]front -| left) rectangle ([yshift=1pt]front -| right);
\fill [black!25] (bottom -| left) rectangle ([yshift=-5mm]front -| right);

\def\nodeshadowed[#1]#2;{\node[scale=2,above,#1]{#2};\node[scale=2,
above,#1,yscale=-1,scope fading=south,opacity=0.4]{#2};}

\nodeshadowed [at={(-5,5  )},yslant=0.05]
{\Huge Ti\textcolor{orange}{\emph{k}}Z};
\nodeshadowed [at={( 0,5.3)}] {\huge \textcolor{mintgreen}{\&}};
\nodeshadowed [at={( 5,5  )},yslant=-0.05] {\Huge \textsc{PGF}};
\nodeshadowed [at={( 0,2  )}] {Manual for Version \pgftypesetversion};

\foreach \i in {0.5,0.6,...,2}
\fill [white,decoration=Koch snowflake,opacity=.9]
[shift=(horizon),shift={(rand*11,rnd*7)},scale=\i]
[double copy shadow={opacity=0.2,shadow xshift=0pt,shadow
yshift=3*\i pt,fill=white,draw=none}]
decorate {
decorate {
decorate {
(0,0) -- ++(60:1) -- ++(-60:1) -- cycle
}
}
};
\end{tikzpicture}
\vfill
\end{document}


Just for fun :-)

The code is heavily based on my answer to Help with the design of an eye in TikZ but changed the scale and colors, and added two new reflections.

As you see, the "reflection" technique here is to decrease opacity, and to distort the shapes. The skull is not distorted (this would be difficult), but since the shape to its left is interpreted by the brain as the reflection of a rectangular window, it conveys the information that the reflecting surface is non-flat (spherical ideed).

\documentclass{standalone}
\usepackage{tikz}
\usepackage{skull}
\usepackage{graphicx}
\usetikzlibrary{calc,decorations.pathmorphing}
\begin{document}

\def\eye#1{\scalebox{#1}{
\def\topedge{(-3,0) .. controls (-2,1.8) and (2,2) .. (2.3,.3)}
\def\bottomedge{(2.3,.3) .. controls (2,-2.2) and (-2,-1.2) .. (-3,0)}
\def\eyepath{\topedge -- \bottomedge --cycle;}

\begin{tikzpicture}
\clip\eyepath;
% Iris
\filldraw[color=blue!60!cyan!50!black] (-.2,.2) circle (1.4);
% Shadow on iris
\filldraw[color=blue!60!cyan!80!black] (-.3,-.1) circle (1.1);
% Iris lines
\foreach \a in {0,5,...,360}{
\pgfmathparse{25+38*rnd}
\fill[opacity=0.7, white!\pgfmathresult!blue, decoration={random steps, segment length=3pt, amplitude=1pt}, decorate, line width=1pt  ] (-.2,.2) -- ++($(\a+2*rnd:.9+0.3*rnd)$) -- ++(\a+90:2pt) -- cycle;
}
% Pupil
\fill[color=black] (-.2,.2) circle (0.6);
% Window reflection
\fill[color=white, opacity=0.7, shift={(-.4,.4)}]
(220:0.65) -- (220:1.25) to[bend left=20] (170:1.15) -- (140:0.65) to[bend right=20] (220:0.65);
% Skull reflection
\begin{scope}
\clip (-.1,.4) circle(0.9);  % Skull reflection
\node[opacity=0.4] at (-.2,-.1)
{\resizebox{20mm}{!}{\textcolor{white}{\Huge$\skull$}}};
\end{scope}
% Shadow of the eyelid
\draw[line width=8mm, draw opacity=0.1, line cap=round]\topedge;
% Eyelids
\draw[line width=4mm, red!40!white!80!black, line cap=round]\bottomedge;
\draw[line width=3mm, red!40!white!60!black, line cap=round]\topedge;
% Lacrimal
\fill[red!40!white!80!black] (-2.8,0) circle (.25);
\fill[white] (-2.7,.1) circle (.03);

\end{tikzpicture}
}}

\eye{1}
\end{document}