<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Emiliano Morghen on Medium]]></title>
        <description><![CDATA[Stories by Emiliano Morghen on Medium]]></description>
        <link>https://medium.com/@emiliano.morghen?source=rss-921143b9e488------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8MV7MIiReMAsR7JQFpjqBg.jpeg</url>
            <title>Stories by Emiliano Morghen on Medium</title>
            <link>https://medium.com/@emiliano.morghen?source=rss-921143b9e488------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 21:28:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emiliano.morghen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Introduction to SVG morphing]]></title>
            <link>https://medium.com/@emiliano.morghen/introduction-to-svg-morphing-1b83380d1f0?source=rss-921143b9e488------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b83380d1f0</guid>
            <category><![CDATA[morphing]]></category>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[ui]]></category>
            <dc:creator><![CDATA[Emiliano Morghen]]></dc:creator>
            <pubDate>Fri, 31 Jul 2015 19:59:40 GMT</pubDate>
            <atom:updated>2015-07-31T20:09:38.846Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fMOCJLQy3cokqPmo1NgFCA.jpeg" /></figure><p><em>We are in 2015 and, at this point, we have to think a web filled with amazing animations that improve the UX.</em></p><p>Morphing isn’t just a way to add delicious detail to our web pages, but it can take them to another level of interactivity with the user and, if you were as impressed as me the first time you saw one of this animations, I think you’ll find this article interesting.</p><h3>A subject to animate</h3><p>The first thing we need to build our animation is a subject, a hourglass filled by sand could be nice and, luckily, I have one to share with you:</p><pre>&lt;svg xmlns:svg=”<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg</a>&quot; xmlns=”<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg</a>&quot; width=”64px” height=”64px” id=”svg3788&quot; version=”1.1&quot;&gt;<br> &lt;defs id=”defs3790&quot;/&gt;<br> &lt;metadata id=”metadata3793&quot;/&gt;<br> &lt;g id=”layer1&quot;&gt;<br> &lt;path d=”M10 10 54 10 44 32 54 54 10 54 20 32z” id=”glass” style=”fill:none;stroke-dasharray:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-width:8;stroke:#000&quot;/&gt;<br> &lt;path d=”M19.8 47.6 26.8 32 37.2 32 44.3 47.6z” id=”path4314&quot; style=”fill-opacity:1;fill:#000&quot;/&gt;<br> &lt;path d=”M19.8 16.4 26.8 32 37.2 32 44.3 16.4z” id=”path4316&quot; style=”fill-opacity:1;fill:#000&quot;/&gt;<br> &lt;/g&gt;<br>&lt;/svg&gt;</pre><p>This code will generate a hourglass filled by sand, but this paths will be useful when we’ll have to define the step from an animation’s statement to another.</p><p>Generally the code created by the editor (like Inkscape or Illustrator) is more complex and filled with useless tags like sodipodi and other. To clean them you can use an online editor that works just fine.<br><a href="http://petercollingridge.appspot.com/svg-editor">Here you can find the SVG Editor</a></p><h3>Make it ready</h3><p>Once we have a clean subject we need to project the animation.<br>The first thing we need to know is that when we morph something we move vertices from one point to another through defined time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*BbsVDv8FDS16NH7kW0KGhw.gif" /><figcaption>Moving vertices explained.</figcaption></figure><p>Now that we know how the animation will look like, we’ll need to tell the computer how to do it.</p><h4>SMIL, a powerful tool</h4><p>To make this animation real, we are going to use SMIL, so let’s start with some basic tags and their properties.</p><p>In SMIL we have just three main tags: animate, animateTransform and animateMotion. These tags can be placed inside and outside of an element in the following ways:</p><pre>&lt;!-- Inside the element --&gt;<br>&lt;path id=”my_circle”&gt;<br>  &lt;animate [...] /&gt;<br>&lt;/path&gt;</pre><pre>&lt;!-- Outside the element --&gt;<br>&lt;path id=&quot;my_circle&quot; [...] &lt;/path&gt;<br>&lt;animate xlink:href=&quot;#my_circle&quot; [...] /&gt;</pre><p>Using “xlink:href” — property we can easily link an animation to an element.</p><p>As we said, we need to move our vertices from one point to another. Inside an SVG element there are some properties and, with SMIL, we need to specify what we’re going to change and in order to do that we can use “attibuteName” property.<br>“d” property defines our vertices so we’re going to change that.</p><p>We also need to define where this vertices will go, but how?</p><p>By focusing on our svg file, we can see three different paths, the first one is our “glass” and we’ll bring it to life later, the remaining two paths are our two sand-steps.<br>In fact, with this paths we made half of the job. By placing their coordinates into the “from” and “to” properties of our animation we can get something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*D0NvVS3ZBU8h_Dz-tbbO7g.gif" /></figure><p>But this is not what we wanted! So what’s the problem?<br>We need to add two more vertices at our path to give the feeling that the sand is falling down.<br>After we successfully made this changes, our svg code will look like the following:</p><pre>&lt;svg xmlns:svg=”<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg</a>&quot; xmlns=”<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg</a>&quot; width=”64px” height=”64px” id=”svg3788&quot; version=”1.1&quot;&gt;<br> &lt;defs id=”defs3790&quot;/&gt;<br> &lt;metadata id=”metadata3793&quot;/&gt;<br> &lt;g id=”layer1&quot;&gt;<br> &lt;path d=”M10 10 54 10 44 32 54 54 10 54 20 32z” id=”glass” style=”fill:none;stroke-dasharray:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-width:8;stroke:#000&quot;/&gt;<br> &lt;path d=”M19.8 47.6 26.8 32 37.2 32 44.3 47.6z” id=”sand” style=”fill-opacity:1;fill:#000&quot;&gt;<br> &lt;animate attributeName=”d” from=”M19.8 16.4 26.8 32 37.2 32 44.3 16.4z” to=”M19.8 47.6 26.8 32 37.2 32 44.3 47.6z “ dur=”.5s” repeatCount=”indefinite”/&gt;<br> &lt;/path&gt;<br> &lt;/g&gt;<br>&lt;/svg&gt;</pre><p><strong><em>Note</em></strong><em>: The number of vertices inside the “from” and “to” have to be the same.</em></p><p>Or, instead of staring at the code, look at the image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*YKNAMabmi5hTXG-UanYhCQ.gif" /></figure><h4>Make it beautiful</h4><p>Most of the work is done, now we need just a bit of Javascript and SMIL to make it rotate.</p><p>The first thing we’re going to do is to add a 180° rotation of the all group “g”. To do that we’re going to use the “animateTransform” tag, let’s see how:</p><pre>&lt;svg xmlns:svg=”<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg</a>&quot; xmlns=”<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg</a>&quot; width=”64px” height=”64px” id=”svg3788&quot; version=”1.1&quot;&gt;<br> &lt;defs id=”defs3790&quot;/&gt;<br> &lt;metadata id=”metadata3793&quot;/&gt;<br> &lt;g id=”layer1&quot;&gt;<br> &lt;path d=”M10 10 54 10 44 32 54 54 10 54 20 32z” id=”glass” style=”fill:none;stroke-dasharray:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-width:8;stroke:#000&quot;/&gt;<br> &lt;path d=”M 19.8,16.4 26.8,32 26.8,32 37.2,32 37.2,32 44.3,16.4 z” id=”sand” style=”fill-opacity:1;fill:#000&quot;&gt;<br> &lt;animate id=”sandA” attributeName=”d” from= “M 19.8,47.6 26.8,32 26.8,32 37.2,32 37.2,32 44.3,47.6 z” to=” M 26.8,32 26.8,32 19.8,16.4 44.3,16.4 37.2,32 37.2,32 z” dur=”0.18s” begin=”rotate.begin + .3s” fill=”freeze” restart=”whenNotActive”/&gt;<br> &lt;/path&gt;<br> &lt;/g&gt;<br> &lt;animateTransform id=”rotate” xlink:href=”#layer1&quot; attributeName=”transform” type=”rotate” restart=”whenNotActive” fill=”freeze” from=”0 32 32&quot; to=”180 32 32&quot; dur=”.3s” begin=”click” restart=”whenNotActive”/&gt;<br>&lt;/svg&gt;</pre><p>Oh oh, there’s lots of new properties now, some of them are easy to understand, other are not.</p><p>Take a look a the “begin” of the element called: sandA (sand animation, yeah I’m not so creative). With SMIL we can start an animation at the start of another and, if needed, we can add a delay.</p><p>We need to add some Javascript too because we have to modify the transformation in order to make a complete rotation after two times. That things cannot be achieved easily with SMIL, but with just few lines, we can get a fantastic result.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FEmilianoMorghen%2Fembed%2FpJqEoG%3Fheight%3D600%26slug-hash%3DpJqEoG%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FEmilianoMorghen%2Fpen%2FpJqEoG%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c1b618e21f2dfb5f1f6a6de0727ceac/href">https://medium.com/media/3c1b618e21f2dfb5f1f6a6de0727ceac/href</a></iframe><h3>Conclusion</h3><p>It is very easy to create these animations and, after a bit of training, you can create beautiful and amazing effects.</p><p>I found some problems at the beginning because I didn’t know what tool to use… Now I’m comfortable with Brackets (to edit the svg file and write the animation) and Inkscape.</p><p>Hope you’ll find this useful and don’t forget to train yourself, <strong>why don’t you try to animate the icon of a hamburger menu in order to gain some experience?</strong></p><p>For any trouble feel free to ask.</p><p>Cheers,<br>Emiliano Morghen.</p><p><em>Thanks to Kevin Midolo for correcting some of my mistakes.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b83380d1f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>