Twirl
A slowly rotating displacement map stirs a flower picture into a swirl, with a mirrored reflection below.
What you are seeing
A pink flower and a smaller purple flower on green stems against a blue sky with soft clouds, framed in a rectangle on black with a fading reflection below. Once started, the petals and clouds bend and flow as a swirl slowly turns across the picture.
How it works
The map starts as an identity gradient, red for x and green for y, then gets dragged through a set of vortices. Feeding it to feDisplacementMap bends the picture along those swirls.
The original rotated the map through an feImage element reference, which Firefox does not render. Here the filter sits on a group that rotates while the picture inside counter-rotates, so only the distortion turns.
A use element repeats the whole clipped group upside down, and a gradient fades it into a reflection.
History
Published on October 4, 2009.
Source
/filterEffects/twirl.svg
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 800 800" id="root" style="background:black">
<title>Twirl</title>
<desc>A drawn pink flower against a blue sky with a fading mirror reflection below. Clicking the picture, or pressing Enter or Space, starts a slowly rotating swirl distortion that bends the flower and sky.</desc>
<defs>
<desc>
/* ============================================================================
* Author: Erik Dahlström
* License terms: see svg-wow.org
* CC0 http://creativecommons.org/publicdomain/zero/1.0/
* Restoration: photo replaced by original artwork and displacement map
* regenerated. Firefox does not render feImage references to elements, so
* the map is loaded as a file and rotated by turning the filter's user
* space while the picture counter-rotates. The clip is now a clipPath.
* =========================================================================== */
</desc>
<filter id="disp" filterUnits="userSpaceOnUse" x="-140" y="-140" width="920" height="920" color-interpolation-filters="sRGB" primitiveUnits="userSpaceOnUse">
<feImage id="dmap" x="-80" y="-80" width="800" height="800" preserveAspectRatio="none" xlink:href="../res/1.0/images/DisplacementMap640dist.png" result="dmapimage"/>
<feDisplacementMap in="SourceGraphic" in2="dmapimage" scale="50" xChannelSelector="R" yChannelSelector="G" result="dist"/>
</filter>
<clipPath id="clipframe"><rect id="clip" x="96" y="136" width="520" height="400"/></clipPath>
<linearGradient id="fadegrad" x2="0" y2="1">
<stop stop-color="black" stop-opacity="0.6" offset="0"/>
<stop stop-color="black" stop-opacity="1" offset="1"/>
</linearGradient>
</defs>
<g transform="translate(60 60)">
<g id="im" clip-path="url(#clipframe)" style="cursor:pointer">
<g filter="url(#disp)">
<animateTransform id="spin" attributeName="transform" type="rotate" begin="indefinite" values="0 320 320;360 320 320" dur="30s" repeatCount="indefinite"/>
<image xlink:href="../res/1.0/images/twirl-flower.jpg" width="640" height="640">
<animateTransform id="counterspin" attributeName="transform" type="rotate" begin="spin.begin" values="0 320 320;-360 320 320" dur="30s" repeatCount="indefinite"/>
</image>
</g>
</g>
<use xlink:href="#im" transform="scale(1,-1) translate(0 -1140)" pointer-events="none"/>
<rect fill="url(#fadegrad)" width="100%" height="140" y="600" pointer-events="none"/>
<!-- ends the reflection on viewports taller than the viewBox -->
<rect fill="black" width="100%" height="420" y="739" pointer-events="none"/>
</g>
<text id="hint" x="400" y="150" style="font:15px sans-serif; fill:#bbb; text-anchor:middle">Click the picture to start the twirl</text>
<script><![CDATA[
(function() {
var started = false;
function start()
{
if(started)
return;
started = true;
document.getElementById("spin").beginElement();
document.getElementById("hint").setAttribute("display", "none");
}
document.getElementById("im").addEventListener("click", start);
document.addEventListener("keydown", function(evt) {
if(evt.key === "Enter" || evt.key === " ")
{
evt.preventDefault();
start();
}
});
})();
]]></script>
</svg>
/filterEffects/twirl.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Twirl | SVG Wow!</title>
<meta name="description" content="A rotating displacement map bends a flower picture into a slow swirl, using feDisplacementMap and SMIL.">
<style>html,body{margin:0;height:100%;background:#111;color:#ddd;font:15px/1.45 system-ui,-apple-system,"Segoe UI",sans-serif}body{display:flex;flex-direction:column;min-height:100%}header{display:flex;flex-wrap:wrap;gap:4px 16px;align-items:baseline;padding:10px 16px}h1{font-size:18px;margin:0;color:#fff}p{margin:0;color:#aaa}a{color:#ffc14d}iframe{flex:1;width:100%;min-height:320px;border:0;background:#000;display:block}</style>
</head>
<body>
<header>
<h1>Twirl</h1>
<p>Erik Dahlström, 2009. Click the picture to start the twirl.</p>
<p><a href="/gallery/twirl/">Gallery page</a> · <a href="twirl.svg">Open the SVG</a></p>
</header>
<iframe src="twirl.svg" title="Twirl demo"></iframe>
</body>
</html>