<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>SVG Wow!</title>
    <link>http://svg-wow.org/blog</link>
    <description></description>
    <pubDate>Mon, 03 Mar 2014 21:47:48 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Rotozoom video</title>
      <link>http://svg-wow.org/blog/2011/03/28/rotozoom-video</link>
      <pubDate>Mon, 28 Mar 2011 23:08:00 EDT</pubDate>
      <category><![CDATA[pattern]]></category>
      <category><![CDATA[animation]]></category>
      <category><![CDATA[video]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2011/03/28/rotozoom-video</guid>
      <description>Rotozoom video</description>
      <content:encoded><![CDATA[
<div id="description">
    <p>
        Homage to <a href="http://en.wikipedia.org/wiki/Future_Crew">Future Crew's</a> 
        <em><a href="http://en.wikipedia.org/wiki/Second_reality">Second Reality</a></em> 
        [<a href="http://www.youtube.com/watch?v=XtCW-axRJV8#t=4m24s">youtube</a>] rotozoomer effect.
    </p>
    <p>
        The music was composed by <a href="http://en.wikipedia.org/wiki/Peter_Hajba">Skaven</a> and 
        <a href="http://en.wikipedia.org/wiki/Jonne_Valtonen">Purple Motion</a> and is from the <a href="http://en.wikipedia.org/wiki/Second_reality">original demo</a>.
    </p>
    <p>
        The demo uses svg patterns and in particular the 
        <a href="http://www.w3.org/TR/SVG11/pservers.html#PatternElementPatternTransformAttribute">patternTransform</a> 
        attribute to create the rotozoom effect.
        It's based on <a href="http://mrdoob.com/lab/javascript/effects/rotozoomer/00/">this demo</a> with kind permission 
        from <a href="http://mrdoob.com">mr doob</a>.
    </p>
    <p>
        The video is old archive footage showing <a href="http://en.wikiquote.org/wiki/William_Henry_Purnell_Blandy">Vice Admiral William H.P. Blandy</a>
        giving a speech before the Bikini nuclear test. A transcription of this videoclip:
    </p>
    <q>
      The bomb will not start a chain-reaction in the water converting it all to gas and letting all 
      the ships on all the oceans drop down to the bottom. It will not blow out the bottom of the sea 
      and let all the water run down the hole. It will not destroy gravity. I am not an atomic playboy, 
      as one of my critics labeled me, exploding these bombs to satisfy my personal whim.
    </q>
    <p>
        This particular video is used since the original demo had a sample with the phrase <q>I am not an atomic playboy</q>.
    </p>
    <p>
        To play the video inside the svg pattern, an attempt is made to use the svg 
        <a href="http://www.w3.org/TR/SVGTiny12/multimedia.html#VideoElement">'video'</a> 
        element, and if that's not supported the fallback is rendering video to a html5 
        <a href="http://dev.w3.org/html5/spec/Overview.html#the-canvas-element">'canvas'</a> and inserting
        the rasterized movie frames into the svg pattern as a normal image. Technically a <a href="http://www.w3.org/TR/SVG11/extend.html#ForeignObjectElement">'foreignObject'</a>
        element with html5 <a href="http://www.w3.org/TR/SVGTiny12/multimedia.html#VideoElement">'video'</a> 
        could also have been used, however no browser was capable of displaying 
        <a href="http://www.w3.org/TR/SVG11/extend.html#ForeignObjectElement">'foreignObject'</a> elements inside a 
        pattern at the time of writing this demo (just before the SVG Open 2010 conference).
    </p>
    <p>
        The music uses the html5 <a href="http://dev.w3.org/html5/spec/Overview.html#the-canvas-element">'audio'</a> element, 
        providing three levels of fallback, first in the original <a href="http://en.wikipedia.org/wiki/ScreamTracker">ScreamTracker</a> format, 
        then as Ogg Vorbis, and as a last option as MP3. The video is also provided in three formats (webm/vp8, mp4/x264, ogg/theora), for wider compatibility.
    </p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Gandhi Quotes</title>
      <link>http://svg-wow.org/blog/2010/10/05/gandhi-quotes</link>
      <pubDate>Tue, 05 Oct 2010 18:00:00 EDT</pubDate>
      <category><![CDATA[animation]]></category>
      <category><![CDATA[ui]]></category>
      <category><![CDATA[morphing]]></category>
      <category><![CDATA[audio]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2010/10/05/gandhi-quotes</guid>
      <description>Gandhi Quotes</description>
      <content:encoded><![CDATA[
<div id="description">

    <p>
        This is more of a showcase than a demo as it assembles multiple techniques
        discussed in other blogs.
    </p>
    <p>
        The demo first uses a 'camera' to zoom and pan around quotes from
        <a href="http://en.wikipedia.org/wiki/Gandhi">Mohandas Karamchand Gandhi</a>.
        This uses the camera utility described in a different
        <a href="http://svg-wow.org/blog/2010/08/14/camera/">blog entry</a>.
    </p>
    <p>
        After the camera has lingered on each quote long enough for the viewer
        to read through it, the final dot is displayed. When all quotes have
        been read, the camera zooms out, the quotes roll out and fade out but
        the dots stay and morph in a set of pebbles in the center of the screen.
        These pebbles in turn morph into Gandhi's stylized portrait.
    </p>
    <p>
        All the animation effects are implemented using <a href="/attributions.html#yui">YUI 3</a>
        with specific SVG extensions, in particular to allow the animation of
        the <code>transform</code> attribute and the animation of the
        <code>d</code> attribute on the <code>&lt;path&gt;</code> element for
        morphing animations.
    </p>
    <p>
        Gandhi's portrait was created in Illustrator from a scan of a drawing
        made by a friend.
    </p>
    <p>
        The audio track is a guitar arrangement created specially for this demo
        by a another friend (who prefers anonymity).
    </p>
    <p>
        Gandhi's quotes were found on <a href="http://www.quotationspage.com/quotes/Mahatma_Gandhi/">
            The Quotations Page</a> web site.
    </p>
    <p>
        The font used for the text is <a href="/attributions.html#fonts">GoodDog</a>.
    </p>

    <h3>Running the demo</h3>

    <p>Click on the "Start SVG Demo" at the top of this page. Wait for the
    audio to load, then click the 'play' button when it appears.</p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Text Effects</title>
      <link>http://svg-wow.org/blog/2010/09/25/text-effects</link>
      <pubDate>Sat, 25 Sep 2010 15:22:00 EDT</pubDate>
      <category><![CDATA[yui]]></category>
      <category><![CDATA[text]]></category>
      <category><![CDATA[animation]]></category>
      <category><![CDATA[interactive]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2010/09/25/text-effects</guid>
      <description>Text Effects</description>
      <content:encoded><![CDATA[
<div id="description">
    <h3>Running the demo</h3>
    <p>
        Click the 'start svg demo' button on this page. When the page is loaded,
        you can click anywhere on the canvas to start the demo.
    </p>

    <h3>Play time!</h3>
    <p>
        I had never got around to play with SVG text as I wanted to and
        it finally happened with this demo. The demo shows how to
        access the content of SVG <code>&lt;text&gt;</code> elements and animate
        individual glyphs.
    </p>
    <p>
        The demo has a library of 'effects' which are succesively applied to
        quotes (from <a href="http://en.wikiquote.org/wiki/American_proverbs">
            http://en.wikiquote.org/wiki/American_proverbs</a>).
    </p>
    
    <h3>Breaking text into spans</h3>
    <p>
        All the effects work similarly. When applied, they first break down the
        text into a set of text spans which are then animated individually.
        The target text element (or elements, since the effect can apply to
        multiple lines of text) is (are) left unmodified and their display
        property is set to 'none'. The text spans are inserted after the
        text elemenet and are the target of the different animation effects.
        The key DOM API method used in the process of computing individual 
        glyph positions is <code>getStartPositionOfChar</code> on the
        <code>SVGTextContentElement</code> interface (see the
        <a href="http://www.w3.org/TR/2002/PR-SVG11-20021115/text.html#InterfaceSVGTextContentElement">specification</a>).
    </p>

    <p>

<div class="pygments_monokai"><pre><span class="c1">// Compute the different glyph positions and how many characters map to the</span>
<span class="c1">// same glyph position (may happen with ligatures).</span>
<span class="kd">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
    <span class="nx">pos</span> <span class="o">=</span> <span class="p">[],</span>
    <span class="nx">curPos</span><span class="p">,</span>
    <span class="nx">n</span> <span class="o">=</span> <span class="p">..</span> <span class="cm">/* textContent length */</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">n</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">p</span> <span class="o">=</span> <span class="nx">text</span><span class="p">.</span><span class="nx">getStartPositionOfChar</span><span class="p">(</span><span class="nx">i</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="nx">curPos</span> <span class="o">===</span> <span class="kc">null</span> <span class="o">||</span>
        <span class="nx">p</span><span class="p">.</span><span class="nx">x</span> <span class="o">!==</span> <span class="nx">curPos</span><span class="p">.</span><span class="nx">p</span><span class="p">.</span><span class="nx">x</span> <span class="o">||</span> <span class="nx">p</span><span class="p">.</span><span class="nx">y</span> <span class="o">!==</span> <span class="nx">curPos</span><span class="p">.</span><span class="nx">p</span><span class="p">.</span><span class="nx">y</span><span class="p">)</span> <span class="p">{</span>
        <span class="nx">curPos</span> <span class="o">=</span> <span class="p">{</span>
            <span class="nx">p</span><span class="o">:</span> <span class="p">{</span><span class="nx">x</span><span class="o">:</span> <span class="nx">p</span><span class="p">.</span><span class="nx">x</span> <span class="o">+</span> <span class="nx">dx</span><span class="p">,</span> <span class="nx">y</span><span class="o">:</span> <span class="nx">p</span><span class="p">.</span><span class="nx">y</span> <span class="o">+</span> <span class="nx">dy</span><span class="p">},</span>
            <span class="nx">n</span><span class="o">:</span> <span class="mi">1</span>
        <span class="p">};</span>
        <span class="nx">pos</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">curPos</span><span class="p">);</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
        <span class="c1">// Same position, just increase the text run length</span>
        <span class="nx">curPos</span><span class="p">.</span><span class="nx">n</span><span class="o">++</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>



    </p>

    <h3>Effects and animations</h3>
    <p>
        As in several other demos on this web site, the animations are built
        by extending the <a href="http://developer.yahoo.com/yui/3/">YUI 3</a>
        JavaScript and CSS library to support SVG. The code also uses a
        concept of <code>Effect</code> to encapsulate a number of related
        animations so that they can be manipulated as a single abstraction.
        For example, the 'opacity-swipe' effect has one animation on the
        'fill-opacity' of each glyph, each animation starts when the previous
        one ends and the user can run the effect which internally starts the
        first animation, causing the whole animation chain to run. Likewise,
        the user can use the <code>onBegin</code> and <code>onEnd</code> events
        on the effect object to invoke specific code when the effect starts or
        ends.
    </p>
    <p>
        The following code snippet shows how the 'opacity-swipe' effect
        applies to the different text spans.
    </p>
    <p>

<div class="pygments_monokai"><pre><span class="c1">// ...</span>

<span class="c1">// toGlyphSpans is a utility method to break down the text in multiple</span>
<span class="c1">// elements.</span>
<span class="kd">var</span> <span class="nx">spans</span> <span class="o">=</span> <span class="nx">toGlyphSpans</span><span class="p">(</span><span class="nx">text</span><span class="p">),</span>
    <span class="nx">n</span> <span class="o">=</span> <span class="nx">spans</span><span class="p">.</span><span class="nx">length</span><span class="p">,</span>
    <span class="nx">s</span><span class="p">,</span>
    <span class="nx">a</span><span class="p">,</span>
    <span class="nx">anims</span> <span class="o">=</span> <span class="p">[];</span>

<span class="c1">// duration, offset and easing a defined somewhere else in the code.s</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">n</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">s</span> <span class="o">=</span> <span class="nx">spans</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
    <span class="nx">a</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Animate</span><span class="p">({</span>
        <span class="nx">node</span><span class="o">:</span> <span class="nx">s</span><span class="p">,</span>
        <span class="nx">from</span><span class="o">:</span> <span class="p">{</span><span class="s1">&#39;fill-opacity&#39;</span><span class="o">:</span> <span class="mi">0</span><span class="p">},</span>
        <span class="nx">to</span><span class="o">:</span> <span class="p">{</span><span class="s1">&#39;fill-opacity&#39;</span><span class="o">:</span> <span class="mi">1</span><span class="p">},</span>
        <span class="nx">duration</span><span class="o">:</span> <span class="nx">duration</span><span class="p">,</span>
        <span class="nx">easing</span><span class="o">:</span> <span class="nx">easing</span>
    <span class="p">});</span>
    <span class="nx">anims</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">a</span><span class="p">);</span>
<span class="p">}</span>

<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">n</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
     <span class="nx">anims</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">onBegin</span><span class="p">(</span><span class="nx">anims</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">i</span> <span class="o">*</span> <span class="nx">offset</span><span class="p">);</span>
<span class="p">}</span>

<span class="c1">// The Effect utility provides a way to manipulate a group of animations</span>
<span class="c1">// as a single entity.</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">Effect</span><span class="p">(</span><span class="nx">anims</span><span class="p">);</span>
</pre></div>



    </p>
    <h3>Music and Font</h3>

    <p>
        Music by <a href="/attributions.html#text-effects-audio">Roger Kidd</a>
        (with all my thanks).
    </p>

    <p>
        The font used in this demo is "GoodDog" and can be found on
        <a href="http://www.fontsquirrel.com/">Font Squirrel</a>. See the
        <a href="/attributions.html">attributions</a> page.
    </p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>picture-shuffle</title>
      <link>http://svg-wow.org/blog/2010/09/18/picture-shuffle</link>
      <pubDate>Sat, 18 Sep 2010 18:00:00 EDT</pubDate>
      <category><![CDATA[css3]]></category>
      <category><![CDATA[yui]]></category>
      <category><![CDATA[canvas]]></category>
      <category><![CDATA[animation]]></category>
      <category><![CDATA[html5]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2010/09/18/picture-shuffle</guid>
      <description>picture-shuffle</description>
      <content:encoded><![CDATA[
<div id="description">
    <h3>Running the demo</h3>

    <p>
        Click the 'start svg demo' button on this page. When the page is loaded,
        you can click on one of the picture stacks at the bottom. The stack
        will be dispatched to form a full picture. You can click anywhere on the
        image to fold it back into a stack.
    </p>

    <h3>Creating a polaroid collage from picture cut-outs</h3>

    <p>
        The idea for this demo came from my son Romain who came back from an
        Adobe Photoshop course he was taking. Romain showed me a polaroid collage effect
        he had created. The effect was quite nice, similar to some you can
        find on the web if you look for 
        <a href="http://www.photoshopessentials.com/photo-effects/polaroids/">Photoshop polaroid effect</a>.
        Of course, being an SVG geek, I thought about how this could be done
        in SVG, and I started hacking away a few days before the
        SVG Open 2010 conference where this demo was first shown.
    </p>

    <p>
        I also decided that I wanted the demo to go a little beyond what
        people do in photoshop, where the content of the Polaroid collage is
        perfectly aligned, which helps readability but is a bit unrealistic. I
        wanted the individual images to be slightly missaligned, as they would
        be if you had a real stack of Polaroids that you were assembling into
        a collage.
    </p>

    <h3>From idea to implementation</h3>

    <p>
        For this to be easier than in Photoshop, the demo had to let the code
        just point to an image and then automatically slice it up in
        individual Polaroids that would be assembled into the collage.
    </p>

    <p>
        I first used a full SVG solution, using the
        <a href=""><code>&lt;pattern&gt;</code></a> element. It did the job
        functionally. Unfortunately, most implementations (except Safari),
        could not handle the number of <code>&lt;pattern&gt;</code> elements
        that had to be created. The performance problem got worse when a
        drop shadow effect got added to the individual Polaroids and in some
        cases (i.e., browsers which do not support SVG filter effects), the
        drop shadow was simply not an option.
    </p>
    <p>
        So, I had to turn to something else.
    </p>

    <h3>Canvas to the rescue</h3>

    <p>
        The solution that I ended up implementing uses a mix of SVG and Canvas,
        and I think it is a great example of how the two technologies complement
        each other.
    </p>
    <p>
        Canvas is used to create the Polaroids and render the right
        content from the original picture, border and drop shadow as illustrated
        bellow.
    </p>

    <table>
        <tr>
            <td>
    <img src="/picture-shuffle/desired-result.png" alt="desired result" title="desired result"/>
    <p class="figure-legend">Figure 1: desired result</p>
            </td>
            <td>
    <img src="/picture-shuffle/one-polaroid.png" alt="one polaroid" title="one polaroid" />
    <p class="figure-legend">Figure 2: one Polaroid</p>
            </td>
    </tr>
    <tr>
        <td>
    <img src="/picture-shuffle/offscreen-rendering.png" alt="offscreen rendering" title="offscreen rendering" />
    <p class="figure-legend">Figure 3: offscreen rendering: content, border and drop shadow.</p>
        </td>
    </tr>
    </table>
    <p>

<div class="pygments_monokai"><pre><span class="c1">// Canvas where the image to slice up is rendered once.</span>
<span class="kd">var</span> <span class="nx">imgCanvas</span> <span class="o">=</span> <span class="p">...;</span>

<span class="c1">// Canvas an context where each Polaroid &#39;snapshot&#39; is drawn.</span>
<span class="kd">var</span> <span class="nx">snapshotCanvas</span> <span class="o">=</span> <span class="p">...,</span>
    <span class="nx">snapshotContext</span> <span class="o">=</span> <span class="nx">snapshotCanvas</span><span class="p">.</span><span class="nx">getContext</span><span class="p">(</span><span class="s1">&#39;2d&#39;</span><span class="p">);</span>

<span class="cm">/**</span>
<span class="cm"> * Renders a snapshot of the image with the polaroidSize and centered on</span>
<span class="cm"> * (cx, cy) with a rotation of r degrees. Some random noise is added to these</span>
<span class="cm"> * values to create a more realistic rendering.</span>
<span class="cm"> *</span>
<span class="cm"> * @param cx the exact image center on the x-axis</span>
<span class="cm"> * @param cy the exact image center on the y-axis</span>
<span class="cm"> * @param r the exact rotation, for a perfect picture alignment</span>
<span class="cm"> */</span>
<span class="kd">function</span> <span class="nx">snapshot</span> <span class="p">(</span><span class="nx">cx</span><span class="p">,</span> <span class="nx">cy</span><span class="p">,</span> <span class="nx">r</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="mf">0.01</span><span class="p">;</span> <span class="c1">// alignmentRoughness</span>
    <span class="kd">var</span> <span class="nx">ar</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="nx">p</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="nx">p</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">())</span> <span class="o">*</span> <span class="nx">r</span><span class="p">,</span>
        <span class="nx">acx</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="nx">p</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="nx">p</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">())</span> <span class="o">*</span> <span class="nx">cx</span><span class="p">,</span>
        <span class="nx">acy</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="nx">p</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="nx">p</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">())</span> <span class="o">*</span> <span class="nx">cy</span><span class="p">;</span>

    <span class="nx">snapshotCtx</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span>
    <span class="nx">snapshotCtx</span><span class="p">.</span><span class="nx">clearRect</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">polaroidSize</span><span class="p">.</span><span class="nx">width</span><span class="p">,</span> <span class="nx">polaroidSize</span><span class="p">.</span><span class="nx">height</span><span class="p">);</span>
    <span class="nx">snapshotCtx</span><span class="p">.</span><span class="nx">translate</span><span class="p">(</span><span class="nx">polaroidSize</span><span class="p">.</span><span class="nx">width</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">polaroidSize</span><span class="p">.</span><span class="nx">height</span> <span class="o">/</span><span class="mi">2</span><span class="p">);</span>
    <span class="nx">snapshotCtx</span><span class="p">.</span><span class="nx">rotate</span><span class="p">(</span><span class="o">-</span><span class="nx">ar</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">PI</span> <span class="o">/</span> <span class="mi">180</span><span class="p">);</span>
    <span class="nx">snapshotCtx</span><span class="p">.</span><span class="nx">translate</span><span class="p">(</span><span class="o">-</span><span class="nx">acx</span><span class="p">,</span> <span class="o">-</span><span class="nx">acy</span><span class="p">);</span>
    <span class="nx">snapshotCtx</span><span class="p">.</span><span class="nx">drawImage</span><span class="p">(</span><span class="nx">imgCanvas</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
    <span class="nx">snapshotCtx</span><span class="p">.</span><span class="nx">restore</span><span class="p">();</span>
<span class="p">}</span>

<span class="c1">// Use further code to render the border and drop shadow.</span>
</pre></div>



    </p>
    <p>Once each
        Polaroid is created, it is transfered to an SVG <code>&lt;image&gt;</code>
        element like so:
    </p>
        <p>

<div class="pygments_monokai"><pre><span class="kd">var</span> <span class="nx">canvas</span> <span class="o">=</span> <span class="p">..;</span> 

<span class="c1">// Draw content, border and drop shadow into canvas</span>
<span class="c1">// ...</span>

<span class="c1">// Convert canvas content to a dataURL</span>
<span class="kd">var</span> <span class="nx">dataURL</span> <span class="o">=</span> <span class="nx">canvas</span><span class="p">.</span><span class="nx">toDataURL</span><span class="p">();</span>

<span class="c1">// Set the dataURL on an SVG &amp;lt;image&amp;gt;</span>
<span class="kd">var</span> <span class="nx">image</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="nx">svgNS</span><span class="p">,</span> <span class="s1">&#39;image&#39;</span><span class="p">);</span>
<span class="nx">image</span><span class="p">.</span><span class="nx">setAttributeNS</span><span class="p">(</span><span class="nx">xlinkNS</span><span class="p">,</span> <span class="s1">&#39;href&#39;</span><span class="p">,</span> <span class="nx">dataURL</span><span class="p">);</span>
</pre></div>



    </p>

    <h3>Animating with YUI SVG Extensions</h3>
    <p>
        Like for many other demos on this web site, the animations are created
        with <a href="/attributions.html#yui">YUI</a>
        SVG Extensions. There is an animation of the <code>transform</code>
        attribute for each
        <code>&lt;image&gt;</code> element.
        The same animation is used both to dispatch the image from
        the stack to its position and to fold it back into the stack. This
        is done by using the 
        <a href="http://developer.yahoo.com/yui/3/api/Anim.html#config_reverse">
            <code>reverse</code></a> animation property.
    </p>
    <p>

<div class="pygments_monokai"><pre><span class="c1">// Reverses the animation when it ends: change its &#39;direction&#39; and</span>
<span class="c1">// also adjust its duration, depending on whether it is dispatching</span>
<span class="c1">// or folding back. The duration is in the [0.15, 0.30] seconds range</span>
<span class="c1">// for folding back and in the [0.25, 0.5] for dispatching.</span>
<span class="kd">function</span> <span class="nx">getReverseHandler</span> <span class="p">(</span><span class="nx">a</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
        <span class="nx">a</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;reverse&#39;</span><span class="p">,</span> <span class="o">!</span><span class="nx">a</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;reverse&#39;</span><span class="p">));</span>

        <span class="k">if</span> <span class="p">(</span><span class="nx">a</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;reverse&#39;</span><span class="p">)</span> <span class="o">===</span> <span class="kc">true</span><span class="p">)</span> <span class="p">{</span>
            <span class="nx">a</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;duration&#39;</span><span class="p">,</span> <span class="mf">0.15</span> <span class="o">+</span> <span class="mf">0.15</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">());</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
            <span class="nx">a</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;duration&#39;</span><span class="p">,</span> <span class="mf">0.25</span> <span class="o">+</span> <span class="mf">0.25</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">());</span>
        <span class="p">}</span>
    <span class="p">};</span>
<span class="p">}</span>

<span class="c1">// Iterate over all the images created from the canvas dataURLs</span>
<span class="k">while</span> <span class="p">(</span><span class="nx">image</span> <span class="o">!==</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span>
    <span class="c1">// ...</span>
    <span class="nx">anim</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">sw</span><span class="p">.</span><span class="nx">animation</span><span class="p">.</span><span class="nx">Animate</span><span class="p">({</span>
        <span class="nx">node</span><span class="o">:</span> <span class="nx">image</span><span class="p">,</span>
        <span class="nx">from</span><span class="o">:</span> <span class="p">{</span>
            <span class="nx">transform</span><span class="o">:</span> <span class="p">{</span>
                <span class="nx">r</span><span class="o">:</span> <span class="nx">c</span><span class="p">.</span><span class="nx">r</span> <span class="o">+</span> <span class="mi">90</span><span class="p">,</span>
                <span class="nx">tx</span><span class="o">:</span> <span class="nx">stackPosition</span><span class="p">.</span><span class="nx">x</span> <span class="o">+</span> <span class="mi">10</span> <span class="o">-</span> <span class="mi">20</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">(),</span>
                <span class="nx">ty</span><span class="o">:</span> <span class="nx">stackPosition</span><span class="p">.</span><span class="nx">y</span> <span class="o">+</span> <span class="mi">10</span> <span class="o">-</span> <span class="mi">10</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span>
            <span class="p">}</span>
        <span class="p">},</span>
        <span class="nx">to</span><span class="o">:</span> <span class="p">{</span>
            <span class="nx">transform</span><span class="o">:</span> <span class="p">{</span><span class="nx">r</span><span class="o">:</span> <span class="nx">c</span><span class="p">.</span><span class="nx">r</span><span class="p">,</span> <span class="nx">tx</span><span class="o">:</span> <span class="nx">c</span><span class="p">.</span><span class="nx">cx</span><span class="p">,</span> <span class="nx">ty</span><span class="o">:</span> <span class="nx">c</span><span class="p">.</span><span class="nx">cy</span><span class="p">}</span>
        <span class="p">},</span>
        <span class="nx">transformTemplate</span><span class="o">:</span> <span class="s2">&quot;translate(#tx, #ty) rotate(#r) &quot;</span> <span class="o">+</span>
                           <span class="s2">&quot;translate(&quot;</span> <span class="o">+</span> <span class="p">(</span><span class="o">-</span><span class="nx">c</span><span class="p">.</span><span class="nx">cx</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;,&quot;</span> <span class="o">+</span> <span class="p">(</span><span class="o">-</span><span class="nx">c</span><span class="p">.</span><span class="nx">cy</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span><span class="p">,</span>
        <span class="nx">duration</span><span class="o">:</span> <span class="mf">0.25</span> <span class="o">+</span> <span class="mf">0.25</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">(),</span>
        <span class="nx">easing</span><span class="o">:</span> <span class="nx">Y</span><span class="p">.</span><span class="nx">Easing</span><span class="p">.</span><span class="nx">easeOutStrong</span>
    <span class="p">});</span>
    <span class="c1">// ..</span>
    <span class="nx">anim</span><span class="p">.</span><span class="nx">onEnd</span><span class="p">(</span><span class="nx">getReverseHandler</span><span class="p">(</span><span class="nx">anim</span><span class="p">));</span>
    <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>



    </p>
    <p>
        Note how the end handler also changes the animation's duration, so that
        folding back the pictures is faster than dispatching them. There is
        also some randomness used on the animation duration to give the
        effect a more realistic feel.
    </p>

    <h3>SVG and Canvas: Great complements</h3>

    <p>
        This demo showed how SVG and Canvas can be both used advantageously:
        Canvas is used to slice images and create pre-rendered Polaroids with
        their border and drop shadows while SVG is used to easily manage
        interactivity and animation on individual <code>&lt;image&gt;</code>
        elements. It is great that we have a way to move pixel data from
        Canvas to SVG with the dataURL. It would be even better if there
        was an API to directly move pixel data between Canvas and SVG without
        having to go through 
        <a href="http://en.wikipedia.org/wiki/Base64">Base64</a> encoding which is wasteful in memory and
        performance.
    </p>

    <h3>Small use of <code>&lt;foreignObject&gt;</code></h3>

    <p>
        The instructions on the demo area are displayed by embeding HTML
        content inside a <code>&lt;foreignObject&gt;</code> element.
    </p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Graffitis</title>
      <link>http://svg-wow.org/blog/2010/09/06/graffitis</link>
      <pubDate>Mon, 06 Sep 2010 18:44:00 EDT</pubDate>
      <category><![CDATA[css3]]></category>
      <category><![CDATA[canvas]]></category>
      <category><![CDATA[yui]]></category>
      <category><![CDATA[animation]]></category>
      <category><![CDATA[html5]]></category>
      <category><![CDATA[interactive]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2010/09/06/graffitis</guid>
      <description>Graffitis</description>
      <content:encoded><![CDATA[
<div id="description">

    <h3>Running the demo</h3>

    <p>
        Click the 'start svg demo' on the page. When the page is loaded, it
        has the following header:
    </p>
        <img src="/graffitis/graffitis-header.png"/>

    <p>
        You can do several things (which are explained later on):
    </p>
    <ul>
        <li>
            select one of the predefined graffitis following the
            'On blackbook' label and see them
            rendered with SVG and Canvas. There are two predefined graffitis:
            one is
            <a href="http://000000book.com/data/12526">'draw'</a> from an 
            unknown contributor and the other one
            is <a href="http://000000book.com/data/161">'katsu'</a> from Katsu.
        </li>
        <li>select the random link and see an random graffiti from
            the  <a href="http://000000book.com/">http://000000book.com/ (black book)</a>
            graffiti repository.</li>
        <li>select the 'record' button and click and drag in the
            black drawing area to draw strokes. To start a new stroke, release
            the mouse and the click and drag to draw the new stroke. When you
            are done recording the graffiti, you can select the 'play' button
            to see it rendered with SVG and Canvas
        </li>
        <li>
            export the graffiti as SVG when clicking on the 'show SVG' button.
        </li>
        <li>
            see the graffiti's GML source when clicking on the 'show GML' button.
        </li>
        <li>
            show an alternate rendering of the graffiti using the 'overlay'
            filter by clicking on the 'show brick overlay' button.
        </li>
    </ul>
    <p>The 'spray paint' check box turns the Canavs rendering on or off.</p>
    

    <h3>Graffitis and the Graffiti Markup Language (GML)</h3>
    
    <p>
        <a href="http://en.wikipedia.org/wiki/Graffitis">Graffitis</a> go from
        the simplest scribbles to the most sophisticated artwork, as you can
        see on <a href="http://www.flickr.com/photos/tags/graffiti/show/">Flickr</a>
        for example.
    </p>
    <p>
        There is amazing work done to capture graffiti
        drawing and render them with computers graphics.
        Some renderings are absolutely stunning, as
        the work done by <a href="http://graffitianalysis.com/">Chris
            Sugrue and Evan Roth</a> shows.
    </p>
    <p>
        The graffiti data is captured in the 
        <a href="http://graffitianalysis.com/gml/">Graffiti Markup Language</a>,
        GML. 
        <a href="http://000000book.com/">http://000000book.com/ (black book)</a> is a
        repository of GML graffitis. Graffitis can be created with applications
        such as
        <a href="http://fffff.at/fattag-deluxe-katsu-edition/">FatTagKatsu</a>
        for the iPhone to draw tags and upload them to the Blackbook repository.
    </p>

    <h3>Using SVG and Canvas together</h3>

    <p>
        This demo uses and manipulates GML JSON data to render and animate
        tags in the blackbook tags repository.
        The graffiti data is turned into a number of SVG <code class="code" >&lt;path&gt;</code>
        objects and the 'drawing' effect is simply done by animating the
        <code class="code" >stroke-dashoffset</code> on the different path elements.
        The <code class="code" >getTotalLength</code> method on the
        <a href="http://www.w3.org/TR/SVG/paths.html#InterfaceSVGPathElement">SVGPathElement interface</a> provides the length for each
        path and lets the code compute the proper <code class="code" >stroke-dashoffset</code>
        value. This is illustrated in the following figure.
    </p>
    
    <img class="illustration" src="/graffitis/graffiti-stroke.png" width="600" height="300" />

    <p>
        The rendering also uses the <a href="http://dev.w3.org/html5/canvas-api/canvas-2d-api.html">Canvas API</a>
        to draw particles of paint as the stroke gets rendered. The particles are sprayed based on the
        speed of the pen as it moves along the graffiti. The canvas with the particles is
        part of the SVG tree, as a child of a <code class="code" >foreignObject</code> element,
        which demonstrates how well the two rendering models can be combined.
    </p>
    <p>
        The demonstration also shows how to simply create a GML file: when the
        user selects the 'record' button, he/she can the draw on the canvas and
        then select the 'play' button when done. This will render the rendering
        of the captured GML content.
    </p>

    <h3>An 'overlay' filter effect lurking in a corner</h3>
    <p>
        Finally, the demonstration illustrates an overlay filter effect.
        The overlay compositing rule does not come directly in SVG as
        it is not part of the
        <a href="http://www.w3.org/TR/SVG/filters.html#feBlendElement">
            <code class="code" >&lt;feBlend&gt;</code>
        </a> modes. However, it is possible
        (even though a bit computation intensive) to create an overlay by
        combining the 'multiply' and 'screen' modes of <code class="code" >&lt;feBlend&gt;</code>.
        This is a bit of a sophisticated filter which I'll further describe
        in a separate demo decicated to just that filter.
    </p>

    <h3>An ugly hack also lurking</h3>

    <p>
        Several implementations (Firefox 3.6, Safari 5.0 and Chrome 6.0) have a
        bug at the time of this writing and fail to correctly render stroke line
        joins when the path points are closer than the stroke width. The code
        contains an ugly hack to get the
        visually correct result. The hack consists in adding
        circles at the point poisitions to make sure the line joins are properly
        rounded. This is ugly because it adds to the DOM load (many
        <code>&lt;circle&gt;</code> elements are added) and slows down the
        animation.
    </p>
    <p>
        The page header uses the <a href="/attributions.html#hvdPeace">HVD-Peace</a>
        font.
    </p>
    
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Bokeh</title>
      <link>http://svg-wow.org/blog/2010/08/22/bokeh</link>
      <pubDate>Sun, 22 Aug 2010 18:00:00 EDT</pubDate>
      <category><![CDATA[css3]]></category>
      <category><![CDATA[animation]]></category>
      <category><![CDATA[webfonts]]></category>
      <category><![CDATA[filters]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2010/08/22/bokeh</guid>
      <description>Bokeh</description>
      <content:encoded><![CDATA[
<div id="description">
    <p>
        <a href="http://en.wikipedia.org/wiki/Bokeh">Bokeh</a> effects,
        which in simple terms is in-focus objects in front of an out-of-focus or blurred background, 
        come in many different forms, as you can
        see on <a href="http://www.flickr.com/search/?q=bokeh">Flickr</a>
        for example.
    </p>
    <p>
        In this demo some circles are generated by javascript. The circles
        are added to the background, given some nice colors and blurred a bit
        to create a faux bokeh effect.
    </p>
    <p>
        As you will notice from reloading the demo, the position of each circle 
        is random, and the radius depends on the distance from the center of the svg image. 
        The further away from the center a circle is the larger the radius. 
        The computed radii are then used for dividing the circles into three different blur levels.
        
        Finally the color of the each circles depend on its computed position. 
        <a href="http://www.w3.org/TR/css3-color/#hsl-color">CSS3 hsl color syntax</a>
        is used to provide every circle with a fill-color that is similar to all the nearby circles. 
    </p>
    <p>
        After the circles have been generated they
        are added to the background group element which happens to have a 
        <a href="http://www.w3.org/TR/SVGTiny12/painting.html#BufferedRenderingProperty">'buffered-rendering'</a> 
        attribute set to <span class="attr-val">'static'</span>.
    </p>
    <p>
        The <a href="http://www.w3.org/TR/SVGTiny12/painting.html#BufferedRenderingProperty">'buffered-rendering'</a> 
        attribute tells the browser it's probably a 
        good idea to cache the rendering of that subtree. In essence it's like
        having the same thing as a pre-rendered raster image, but with the added
        benefits that SVG provides. E.g if you ever need 
        to resize or update the subtree you can, just remove the 
        <a href="http://www.w3.org/TR/SVGTiny12/painting.html#BufferedRenderingProperty">'buffered-rendering'</a>
        attribute and it will behave as normal again. In browsers that don't
        support <a href="http://www.w3.org/TR/SVGTiny12/painting.html#BufferedRenderingProperty">'buffered-rendering'</a> 
        the SVG rendering will be unaffected by the attribute.
    </p>
    <p>
        To see the effect of <a href="http://www.w3.org/TR/SVGTiny12/painting.html#BufferedRenderingProperty">'buffered-rendering'</a>
        click the svg image and the text will animate on top of the background.
    </p>
    <p>
        The demo uses the <a href="/attributions.html#fonts">Vitamin</a>
        font.
    </p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Pointilizer</title>
      <link>http://svg-wow.org/blog/2010/08/22/pointilizer</link>
      <pubDate>Sun, 22 Aug 2010 18:00:00 EDT</pubDate>
      <category><![CDATA[canvas]]></category>
      <category><![CDATA[animation]]></category>
      <category><![CDATA[raphaeljs]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2010/08/22/pointilizer</guid>
      <description>Pointilizer</description>
      <content:encoded><![CDATA[
<div id="description">
    <p>
    	This example shows a combination of html5 canvas and svg.
    </p>
    <p>
    	First, a raster image is processed by canvas and javascript to extract part of the pixel data as an array of points, relative size and color.
    	The result is then passed to a small javascript function that uses the <a href="http://raphaeljs.com/">Raphaël framework</a> to render the result, which in theory provides support
    	all the way back to IE6. However, since the demo needs support for canvas to get any interesting results, you'll need at least IE9.
    	The animation is done by the API provided by <a href="http://raphaeljs.com/">Raphaël</a>, which is much less rich than what SVG in itself is. However, it shows that 
    	it's easy to animate vector graphics even in browsers that don't yet support SVG's declarative animation elements.
    </p>
    <p>
    	It's easy to extract the points data from raster images, it's wrapped into a utility function called <code>sw.tools.pointilize</code> which is provided by
    	<a href="/res/3.0/scripts/tools/pointilizer.js">pointilizer.js</a>.
    	You provide an options array and a callback function. Here's an example of how it can look:
    </p>
    <p>

<div class="pygments_monokai"><pre><span class="nx">sw</span><span class="p">.</span><span class="nx">tools</span><span class="p">.</span><span class="nx">pointilize</span><span class="p">({</span>
    <span class="nx">url</span><span class="o">:</span> <span class="s2">&quot;somephoto.jpg&quot;</span><span class="p">,</span>
    <span class="nx">output</span><span class="o">:</span> <span class="s2">&quot;points&quot;</span><span class="p">,</span> 
    <span class="nx">points</span><span class="o">:</span> <span class="mi">1000</span><span class="p">,</span>
    <span class="nx">threshold</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span> 
    <span class="nx">width</span><span class="o">:</span> <span class="mi">480</span><span class="p">,</span>
    <span class="nx">height</span><span class="o">:</span> <span class="mi">360</span><span class="p">,</span>
 <span class="p">},</span>
 <span class="kd">function</span><span class="p">(</span><span class="nx">result</span><span class="p">)</span> <span class="p">{</span>
    <span class="c1">// your callback function</span>
    <span class="k">if</span> <span class="p">(</span><span class="nx">result</span><span class="p">.</span><span class="nx">data</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="c1">// do something with the data</span>
    <span class="p">}</span>
<span class="p">});</span>
</pre></div>



    </p>
    <p>
    	The <code>result.data</code> that is passed back depends on the output format, if you pass "svg" instead it'll be a string that is the serialized svg image. The string can be
    	inserted into the DOM by using <code>DOMParser</code> or <code>element.innerHTML</code>. <code>DOMParser</code> is supported by all browsers except IE, and parses a string
    	into a DOM, it can handle both html and XML documents. The <code>element.innerHTML</code> setter which is defined in HTML5 is available on all browsers, but at the time of
    	writing shows differences in how it handles XML input, and deployed older browsers will not handle the svg elements correctly. It's recommended to not rely on one single
    	way, but instead gracefully fall back and handle such differences in the javascript code, testing for the functionality and not for a particular browser.
    	Following that advise will provide you the best level of compatibility for your content.
    </p>
    <p>
    	Note that for the canvas data extraction to work you need to host the image and the script on the same domain, since the browsers generally throw a security exception if
    	you try to read pixels from images that were from another domain.
    </p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Camera</title>
      <link>http://svg-wow.org/blog/2010/08/14/camera</link>
      <pubDate>Sat, 14 Aug 2010 18:00:00 EDT</pubDate>
      <category><![CDATA[interactivity]]></category>
      <category><![CDATA[camera]]></category>
      <category><![CDATA[animation]]></category>
      <category><![CDATA[yui]]></category>
      <category><![CDATA[audio]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2010/08/14/camera</guid>
      <description>Camera</description>
      <content:encoded><![CDATA[
<div id="description">

    <h3>Running the demo</h3>

    <p>Click on the "Start SVG Demo" at the top of this page. After the loading
    message disappears, click in the display area to start the demo.</p>

    <h3>Using the camera metaphore to script zoom and pan</h3>

    <p>
        Sometimes, we only think of animation as moving objects, changing their
        sizes, positions or other properties. This demo shows that we can also
        create animation effects by moving a 'camera' around.
    </p>
    <p>
        The camera effect is  created
        by animating the 
        <a href="http://www.w3.org/TR/SVG/coords.html#TransformAttribute">transform</a>
        on a target <a href="http://www.w3.org/TR/SVG/struct.html#Groups"><code>&lt;g&gt;</code></a> in the SVG content,
        which creates the illusion of a camera moving over the group of
        elements contained in the target group.
    </p>
    
    <h4>Camera utility</h4>
    <p>
        The demo uses a small utility
        <a href="../res/3.0/scripts/tools/camera.js">camera.js</a> which
        makes it easy to create this type of effect.
    </p>
    <p>
        Following is a sample of how to instantiate, configure and start
        the camera with the <code>action</code> method.
    </p>

    <p>

<div class="pygments_monokai"><pre><span class="kd">var</span> <span class="nx">cameraTarget</span> <span class="o">=</span> <span class="nx">Y</span><span class="p">.</span><span class="nx">one</span><span class="p">(</span><span class="s1">&#39;#cameraTarget&#39;</span><span class="p">),</span> <span class="c1">// Uses YUI 3.0 for DOM access.</span>
    <span class="nx">Easing</span> <span class="o">=</span> <span class="nx">Y</span><span class="p">.</span><span class="nx">Easing</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">defaultInterpolators</span> <span class="o">=</span> <span class="p">{</span>
    <span class="nx">zoom</span><span class="o">:</span> <span class="nx">Easing</span><span class="p">.</span><span class="nx">easeNone</span><span class="p">,</span>
    <span class="nx">direction</span><span class="o">:</span> <span class="nx">Easing</span><span class="p">.</span><span class="nx">easeBothStrong</span> <span class="p">,</span>
    <span class="nx">position</span><span class="o">:</span> <span class="nx">Easing</span><span class="p">.</span><span class="nx">easeBothStrong</span>
<span class="p">};</span>
<span class="kd">var</span> <span class="nx">camera</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">sw</span><span class="p">.</span><span class="nx">tools</span><span class="p">.</span><span class="nx">Camera</span><span class="p">({</span>
    <span class="nx">target</span><span class="o">:</span> <span class="nx">cameraTarget</span><span class="p">,</span> <span class="c1">// The element containing the content to navigate over</span>
    <span class="nx">viewport</span><span class="o">:</span> <span class="p">{</span><span class="nx">width</span><span class="o">:</span> <span class="mi">800</span><span class="p">,</span> <span class="nx">height</span><span class="o">:</span> <span class="mi">600</span><span class="p">},</span> <span class="c1">// The camera&#39;s viewport</span>
    <span class="nx">frameLength</span><span class="o">:</span> <span class="mi">10</span><span class="p">,</span>  <span class="c1">// Controls the camera&#39;s movement speed.</span>
    <span class="nx">position</span><span class="o">:</span> <span class="p">{</span><span class="nx">x</span><span class="o">:</span> <span class="mi">243</span><span class="p">,</span> <span class="nx">y</span><span class="o">:</span> <span class="mi">68</span><span class="p">},</span> <span class="c1">// The camera&#39;s initial position</span>
    <span class="nx">direction</span><span class="o">:</span> <span class="mi">90</span><span class="p">,</span> <span class="c1">// The camera angle</span>
    <span class="nx">zoom</span><span class="o">:</span> <span class="mi">7</span> <span class="c1">// The camera&#39;s zoom level.</span>
    <span class="p">});</span>

    <span class="nx">camera</span><span class="p">.</span><span class="nx">addTravelSegments</span><span class="p">([{</span>
        <span class="nx">name</span><span class="o">:</span> <span class="s2">&quot;wherever&quot;</span><span class="p">,</span>
        <span class="nx">position</span><span class="o">:</span> <span class="p">{</span><span class="nx">x</span><span class="o">:</span> <span class="mi">243</span><span class="p">,</span> <span class="nx">y</span><span class="o">:</span> <span class="mi">384</span><span class="p">},</span>
        <span class="nx">direction</span><span class="o">:</span> <span class="mi">90</span><span class="p">,</span>
        <span class="nx">zoom</span><span class="o">:</span> <span class="mi">7</span><span class="p">,</span>
        <span class="nx">runLength</span><span class="o">:</span> <span class="mi">1000</span><span class="p">,</span>
        <span class="nx">interpolators</span><span class="o">:</span> <span class="nx">defaultInterpolators</span>
    <span class="p">},</span> <span class="p">{</span>
        <span class="nx">name</span><span class="o">:</span> <span class="s2">&quot;you&quot;</span><span class="p">,</span>
        <span class="nx">position</span><span class="o">:</span> <span class="p">{</span><span class="nx">x</span><span class="o">:</span> <span class="mi">440</span><span class="p">,</span> <span class="nx">y</span><span class="o">:</span> <span class="mi">368</span><span class="p">},</span>
        <span class="nx">direction</span><span class="o">:</span> <span class="mi">180</span><span class="p">,</span>
        <span class="nx">zoom</span><span class="o">:</span> <span class="mf">1.6</span><span class="p">,</span>
        <span class="nx">runLength</span><span class="o">:</span> <span class="mi">2000</span><span class="p">,</span>
        <span class="nx">interpolators</span><span class="o">:</span> <span class="nx">defaultInterpolators</span>
    <span class="p">},</span> <span class="p">...</span> <span class="c1">// More camera positions</span>
<span class="p">});</span>

<span class="nx">camera</span><span class="p">.</span><span class="nx">action</span><span class="p">();</span>
</pre></div>



    </p>

    <p>
        The following figure illustrates how the zoom level, direction and
        position specify the successive positions of the camera over the
        composition.
    </p>

    <img class="illustration" src="/camera/camera-positions.png" width="600" />

    <h3>Attributions</h3>

    <p>Many thanks to <a href="/attributions.html#wherever-audio">Roger Kidd</a> for
    creating this demo's rythmic arrangment.</p>

</div>
]]></content:encoded>
    </item>
    <item>
      <title>Alternate Stylesheets</title>
      <link>http://svg-wow.org/blog/2010/08/14/alternate-stylesheets</link>
      <pubDate>Sat, 14 Aug 2010 18:00:00 EDT</pubDate>
      <category><![CDATA[style]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2010/08/14/alternate-stylesheets</guid>
      <description>Alternate Stylesheets</description>
      <content:encoded><![CDATA[
<div id="description">

    <h3>Running the demo</h3>

    <p>Click on the "Start SVG Demo" at the top of this page. Then, in the
    demo page, select the name of the alternate stylesheet to apply </p>
    <p>
        Click on the 'start svg demo' button on this page. Then select one of
        the links next to the 'select stylesheet' prompt to to enable
        the desired stylesheet (and disable the others).
    </p>

    <h3>Applying CSS styles to SVG and HTML from one stylesheet</h3>

    <p>
        SVG is fully stylable with CSS and features like
        <a href="http://www.alistapart.com/articles/alternate/">alternate
        stylesheets</a> apply. This demo shows a web page with both HTML and
        SVG content. At the top of the page, the user can select one of the
        available stylesheets which gets enabled while the others are disabled.
        This mechanisme is generally useful to allow users to select a prefered
        style, for example chosing high contrast if needed for accessibility
        reason.
    </p>
    <p>
        The demo shows how the style of SVG graphical element is subject to
        CSS styles, just like any other HTML element is and that the same
        stylesheet can naturally be used to style both SVG and HTML content.
    </p>
    <p>
        The key to turning stylesheets on or off is to change the
        <code>disabled</code> property on the <code>&lt;link&gt;</code>
        element referencing the stylesheets like so:
    </p>
    <p>

<div class="pygments_monokai"><pre><span class="kd">var</span> <span class="nx">link</span> <span class="o">=</span> <span class="p">...;</span> <span class="c1">// e.g., from document.getElementsByTagName(&quot;link&quot;);</span>
<span class="nx">link</span><span class="p">.</span><span class="nx">disabled</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span> <span class="c1">// Enables the stylesheet</span>
<span class="p">....</span>
<span class="nx">link</span><span class="p">.</span><span class="nx">disabled</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span> <span class="c1">// Disables the stylesheet</span>
</pre></div>



    </p>
    <p>
        The code for turning stylesheets on and off was inspired by the example
        found at <a href="http://www.alistapart.com/articles/alternate/">A list
        appart</a>.
    </p>


</div>
]]></content:encoded>
    </item>
    <item>
      <title>Mustache</title>
      <link>http://svg-wow.org/blog/2009/10/04/mustache</link>
      <pubDate>Sun, 04 Oct 2009 15:00:00 EDT</pubDate>
      <category><![CDATA[interactive]]></category>
      <guid isPermaLink="true">http://svg-wow.org/blog/2009/10/04/mustache</guid>
      <description>Mustache</description>
      <content:encoded><![CDATA[
<div id="description">
    <p>
        This demo shows how to create an interactive svg webapp. Place a beard/mustache on a photo of your choice.
    </p>
    
    <h3>Running the demo</h3>
    <p>
        Hover the bottom part of the photo to show the palette of available face enhancements, and drag the one of your choice
        from the palette to the photo. 
    </p>
    <p>
        When an item is selected it can be rotated by pressing the right- or left-arrow key. To scale an item press
        up- or down-arrow key to zoom in or out respectively. To rotate/scale in smaller steps hold down the shiftkey at the
        same time.
        
        To remove an item, select it and then press backspace or delete.
    </p>
    <p>
        You can also add your own photo by clicking the "Add photo" button in the palette, as well as save
        the result to a data uri. Per default the saved svg file only links to the photo, but it's also possible to save a standalone file by following 
        <a href="/mustache/beard.svg#save=standalone">this link</a> (note that big photos can take a bit of time to export, and your browser may appear frozen during the encoding phase).
    </p>
    <p>See <a href="/attributions.html">attributions</a> about
        the resources used in this demo.
    </p>
</div>
]]></content:encoded>
    </item>
  </channel>
</rss>
