<?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>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>
  </channel>
</rss>
