<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CodeDread Blog &#187; graphics</title>
	<atom:link href="http://www.codedread.com/blog/archives/tag/graphics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codedread.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 02 Jan 2012 15:30:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Know The Beast</title>
		<link>http://www.codedread.com/blog/archives/2010/03/22/know-the-beast/</link>
		<comments>http://www.codedread.com/blog/archives/2010/03/22/know-the-beast/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 01:07:09 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://www.codedread.com/blog/?p=757</guid>
		<description><![CDATA[[clipart]Cameron Adams decided to benchmark Flash, SVG, Canvas and HTML5 using a particle engine he created. Not surprising (to me anyway), the SVG scores were the worst of the bunch. This stands to reason: does each particle really need to be a DOM element? Nonetheless, I decided to see what I could do to make [...]]]></description>
			<content:encoded><![CDATA[<p><object type="image/svg+xml" width="100" height="100" style="float:right" data="http://codedread.com/clipart/tools.svgz">[clipart]</object><a href="http://www.themaninblue.com/writing/perspective/2010/03/22/">Cameron Adams</a> decided to benchmark Flash, SVG, Canvas and HTML5 using a particle engine he created.  Not surprising (to me anyway), the SVG scores were the worst of the bunch.  This stands to reason:  does each particle really need to be a DOM element?  Nonetheless, I decided to see what I could do to make the SVG scores suck less.  I thought I&#8217;d use it as an opportunity to also teach some techniques.</p>
<p><strong>Update: Added some browser scores for Nov 2011</strong></p>
<p><span id="more-757"></span></p>
<h3>Particle Creation</h3>
<p>Cameron initializes the particles this way:</p>
<pre>
	var domNode = document.createElementNS(SVG_NS, "circle");
	var benchmark = document.getElementById("benchmark");
	benchmark.appendChild(domNode);

	// Set initial position to middle of screen
	domNode.setAttribute("cx", x + PARTICLE_RADIUS);
	domNode.setAttribute("cy", y + PARTICLE_RADIUS);
	domNode.setAttribute("r", PARTICLE_RADIUS);

	// Set colour of element
	domNode.setAttribute("fill", COLORS[Math.floor(Math.random() * COLORS.length)]);
</pre>
<p>That is, he creates a svg:circle element, then appends it to the DOM, then modifies its attributes.  Every time an attribute is changed in the DOM it has the potential to cause a layout/render change.  Thus, it makes more sense (to me) to attach the circle to the DOM only after you&#8217;re done initializing the element (i.e. after all the setAttribute calls).</p>
<p>This doesn&#8217;t affect the frame-rate, since creation only happens at the beginning, but it might affect the startup time of the animation so I thought I&#8217;d drop it in this post.</p>
<h3>DOM Animation &#8211; the Naive Approach</h3>
<p>Next, he has a function that is called as fast as possible to animate the particles.  The animate function does a simple loop over all particles and calls a draw() function.  The particle&#8217;s draw function does this:</p>
<pre>
		// lots of other JS code here
		domNode.setAttribute("cx", nextX + PARTICLE_RADIUS);
		domNode.setAttribute("cy", nextY + PARTICLE_RADIUS);
</pre>
<p>The problem with this again is that each DOM call can cause a re-render.  This means if you have 500 particles, there are 1000 DOM calls affecting the rendering with every call to animate().  Depending on how stupid the browser is, this could be expensive.</p>
<ul>
<li><a href="http://codedread.com/browser-tests/particle/particle.xhtml">Click here to try the original demo</a></li>
</ul>
<table>
<thead>Original Results</thead>
<tr>
<th>Browser</th>
<th>Frame Rate</th>
</tr>
<tr>
<td>Firefox 3.6 (OSX)</td>
<td>1.75 fps</td>
</tr>
<tr>
<td>Firefox 3.7 Nightly (OSX)</td>
<td>1.9 fps</td>
</tr>
<tr>
<td>Firefox 8 Beta (OSX)</td>
<td><strong>3.8 fps</strong></td>
</tr>
<tr>
<td>Opera 10.10 (OSX)</td>
<td>12.5 fps</td>
</tr>
<tr>
<td>Opera 10.50 (OSX)</td>
<td>14.5 fps</td>
</tr>
<tr>
<td>IE9 Preview 1 (Win7 VM)</td>
<td>28 fps</td>
</tr>
<tr>
<td>Safari 4.0.5 (OSX)</td>
<td>32 fps</td>
</tr>
<tr>
<td>Chrome 5 Nightly (OSX)</td>
<td>40 fps</td>
</tr>
<tr>
<td>Chromium 17 Nightly (OSX)</td>
<td><strong>55 fps</strong></td>
</tr>
</table>
<h3 id="suspendredraw">Suspension</h3>
<p>My first attempt was to use suspendRedraw() and unsuspendRedraw() around the for-loop that calls particle.draw().  This is the SVG-recommended way to do a bunch of operations &#8216;off-screen&#8217; and then have the results updated in one-shot.  This <em>did</em> have an effect on Firefox&#8217;s frame rate.  </p>
<p>But it didn&#8217;t really seem to affect WebKit&#8217;s performance at all.  Looking at the WebKit source (svg/SVGSVGElement.cpp) it&#8217;s pretty easy to see why:</p>
<pre>
unsigned SVGSVGElement::suspendRedraw(unsigned /* maxWaitMilliseconds */)
{
    // FIXME: Implement me (see bug 11275)
    return 0;
}
</pre>
<p>Maybe WebKit will one day implement this and the technique will become more broadly useful. <strong>[Update Nov 2011: This has been implemented in WebKit]</strong></p>
<ul>
<li><a href="http://codedread.com/browser-tests/particle/particle-suspend.xhtml">Click here to try the demo that uses suspendRedraw</a></li>
</ul>
<table>
<thead>SuspendRedraw Results</thead>
<tr>
<th>Browser</th>
<th>Frame Rate</th>
</tr>
<tr>
<td>Firefox 3.6 (OSX)</td>
<td>3.2 fps</td>
</tr>
<tr>
<td>Firefox 3.7 Nightly (OSX)</td>
<td>3.4 fps</td>
</tr>
<tr>
<td>Firefox 8 Beta (OSX)</td>
<td><strong>8 fps</strong></td>
</tr>
<tr>
<td>Opera 10.10 (OSX)</td>
<td>8.2 fps</td>
</tr>
<tr>
<td>Opera 10.50 (OSX)</td>
<td>23.5 fps</td>
</tr>
<tr>
<td>IE9 Preview 1 (Win7 VM)</td>
<td>N/A</td>
</tr>
<tr>
<td>Safari 4.0.5 (OSX)</td>
<td>32 fps</td>
</tr>
<tr>
<td>Chrome 5 Nightly (OSX)</td>
<td>40 fps</td>
</tr>
<tr>
<td>Chromium 17 Nightly (OSX)</td>
<td><strong>45 fps</strong></td>
</tr>
</table>
<p>NOTE: IE9 Preview 1 has not implemented suspendRedraw() and the demo does not run.</p>
<h3 id="manual-offscreen">Manually Doing Off-Screen Rendering</h3>
<p>I then went and did something crazy.  </p>
<p>I added a svg:g (group) element to the particle test, added all the particles to it.  Then with each call to render, I remove the &#60;g&#62; from the DOM, call all the particle draw() functions, then re-add the &#60;g&#62; to the DOM.  </p>
<p>This had a <em>dramatic</em> effect on Firefox&#8217;s performance, but it seemed to slow down Safari and Opera.  Not sure why that would be, but I guess they have much more sensible ways of updating the rendered state of the DOM than Firefox so that removing and adding an element to the DOM becomes more expensive.</p>
<ul>
<li><a href="http://codedread.com/browser-tests/particle/particle-g.xhtml">Click here to try the demo with manual off-screen rendering</a></li>
</ul>
<table>
<thead>Manual Offscreening Results</thead>
<tr>
<th>Browser</th>
<th>Frame Rate</th>
</tr>
<tr>
<td>Safari 4.0.5 (OSX)</td>
<td>12.75 fps</td>
</tr>
<tr>
<td>Opera 10.10 (OSX)</td>
<td>14 fps</td>
</tr>
<tr>
<td>Firefox 3.6 (OSX)</td>
<td>21.5 fps</td>
</tr>
<tr>
<td>Firefox 3.7 Nightly (OSX)</td>
<td>21.5 fps</td>
</tr>
<tr>
<td>Opera 10.50 (OSX)</td>
<td>23.5 fps</td>
</tr>
<tr>
<td>IE9 Preview 1 (Win7 VM)</td>
<td>25 fps</td>
</tr>
<tr>
<td>Chrome 5 Nightly (OSX)</td>
<td>26.5 fps</td>
</tr>
<tr>
<td>Firefox 8 Beta (OSX)</td>
<td><strong>37 fps</strong></td>
</tr>
<tr>
<td>Chromium 17 Nightly (OSX)</td>
<td><strong>49 fps</strong></td>
</tr>
</table>
<h3>Conclusion</h3>
<p>This blog post is really just an attempt to share the knowledge about some of the challenges in using SVG for high-performance demos.  Basically don&#8217;t change the live DOM if you can avoid it.</p>
<p>Note that I still stand by my original statement that SVG is not the right technology for particle effects unless you need mouse interactivity.  This type of demo is much more suitable for HTML5&#8242;s &#60;canvas&#62; element.  Let&#8217;s hope IE9 also implements a GPU-accelerated version of this element too!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2010/03/22/know-the-beast/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>First Post!!1!</title>
		<link>http://www.codedread.com/blog/archives/2008/12/01/first-post1/</link>
		<comments>http://www.codedread.com/blog/archives/2008/12/01/first-post1/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 08:40:28 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2008/12/01/first-post1/</guid>
		<description><![CDATA[To help kick off the new SVG community site, I thought I&#8217;d write up a tutorial and post it there. It&#8217;s a quickie and it&#8217;s maybe a couple years out of style, but it&#8217;s got some pretty pictures: Gelcap Buttons in SVG. (Some people call these &#8216;aqua buttons&#8217;). Disclaimer: The PlanetSVG website is still largely [...]]]></description>
			<content:encoded><![CDATA[<p><object type="image/svg+xml" width="100" height="100" align="right" hspace="10" data="http://codedread.com/clipart/planetsvg.svg"><span/></object>To help kick off the new <a href="http://planetsvg.com/" title="Planet SVG">SVG community site</a>, I thought I&#8217;d write up a tutorial and post it there.  It&#8217;s a quickie and it&#8217;s maybe a couple years out of style, but it&#8217;s got some pretty pictures:  <a href="http://www.planetsvg.com/content/aqua-buttons-svg-part-1" title="Aqua-style buttons in SVG">Gelcap Buttons in SVG</a>.  (Some people call these &#8216;aqua buttons&#8217;).</p>
<p>Disclaimer:  The PlanetSVG website is still largely under construction, so please be gentle.  <a href="http://latenightpc.com/blog">Rob</a> is working on a Drupal theme and we still have to plan out the overall flow of the site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2008/12/01/first-post1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>skia</title>
		<link>http://www.codedread.com/blog/archives/2008/09/07/skia/</link>
		<comments>http://www.codedread.com/blog/archives/2008/09/07/skia/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 02:49:42 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[SVG]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2008/09/07/skia/</guid>
		<description><![CDATA[Alp Toker, one of those graphics heavy hitters, has woken up to give us a nice summary about the &#8216;skia&#8217; graphics library which Google uses for the Chrome browser. I like that it has animation and SVG awareness &#8216;out of the box&#8217;, but it probably won&#8217;t be a major player until it&#8217;s fully ported to [...]]]></description>
			<content:encoded><![CDATA[<p><object type="image/svg+xml" width="100" height="100" align="right" hspace="10" data="http://codedread.com/clipart/tools.svgz"><span/></object><a href="http://www.atoker.com/">Alp Toker</a>, one of those graphics heavy hitters, has woken up to give us a <a href="http://www.atoker.com/blog/2008/09/06/skia-graphics-library-in-chrome-first-impressions/" title="Alp Toker summarizes some of the high-level points regarding Google's new graphics library, skia">nice summary</a> about the &#8216;skia&#8217; graphics library which Google uses for the <a href="http://www.google.com/chrome" title="the Chrome Web Browser">Chrome browser</a>.  I like that it has animation and <a href="http://www.w3.org/Graphics/SVG" title="Scalable Vector Graphics">SVG</a> awareness &#8216;out of the box&#8217;, but it probably won&#8217;t be a major player until it&#8217;s fully ported to all the major desktop platforms and has matured a little.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2008/09/07/skia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Painting the Web, Having Fun</title>
		<link>http://www.codedread.com/blog/archives/2008/08/17/painting-the-web-having-fun/</link>
		<comments>http://www.codedread.com/blog/archives/2008/08/17/painting-the-web-having-fun/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 20:07:01 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2008/08/17/painting-the-web-having-fun/</guid>
		<description><![CDATA[I received a copy of Shelley Powers&#8216; new book, Painting the Web about a month ago. Sadly I was pretty busy with work and other projects so I wasn&#8217;t able to devour it as quickly as I&#8217;d hoped &#8211; though I did take a moment to squee over the fact that my SVG Support page [...]]]></description>
			<content:encoded><![CDATA[<p><object type="image/svg+xml" width="100" height="100" align="right" hspace="10" data="http://codedread.com/clipart/painting-the-web.svgz"><span/></object>I received a copy of <a href="http://burningbird.net/" title="Shelley Powers">Shelley Powers</a>&#8216; new book, <a href="http://www.amazon.com/gp/product/059651509X?ie=UTF8&#038;tag=codedread-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=059651509X">Painting the Web</a><img src="http://www.assoc-amazon.com/e/ir?t=codedread-20&#038;l=as2&#038;o=1&#038;a=059651509X" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> about a month ago.  Sadly I was pretty busy with work and other projects so I wasn&#8217;t able to devour it as quickly as I&#8217;d hoped &#8211; though I did take a moment to squee over the fact that my <a href="http://www.codedread.com/svg-support.php">SVG Support</a> page is in the book.  Ok, this review <em>might</em> be biased <img src='http://www.codedread.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  <span id="more-484"></span></p>
<p>The first thing that struck me about the book was how thick it was &#8211; clocking in at over 600 pages.  I had expected the book to be something I could take with me on the train to work each day.  However, I prefer my vertebrae unfused, so I had to be happy with reading it at night.  Maybe I should have investigated the eBook side of things&#8230;</p>
<p>The second thing I noticed:  Every image in the book is full color.  I don&#8217;t think I&#8217;ve ever seen a tech book do this, though I haven&#8217;t bought a tech book in a couple years.  Usually there will be a few glossy pages in the middle of the book that show some color plates, but not every image.  It&#8217;s a delightful surprise that must have been costly for O&#8217;Reilly.  Yet the book is actually reasonably priced at $45 USD at Border&#8217;s &#8211; even cheaper on Amazon.</p>
<p>Ok, moving on to actual content&#8230;  I&#8217;m actually only just a little over 1/3 of the way through the book and only have just begun reading the vector portions (beginning of Chapter 7).  But here are some notes/thoughts so far:</p>
<ul>
<li>I like that Ms. Powers has made it a point that the contents of this book should be accessible to everyone &#8211; even those that have no budget for graphics tools.  The focus of the book is that the web graphic artist must have fun.  In fact, this is the title of the first chapter.</li>
<li>Photography and photo manipulation are not big parts of my personal web experience, but it certainly is a wildly popular thing for a lot of people.  Chapters 3 and 4 contain a lot of info about color profiles, curves/levels, image formats, photo editors, online photo galleries (including an introduction to <a href="http://www.gallery2.org/" title="Gallery online photo application">Gallery2</a>) and more.</li>
<li>Some interesting bits about web design in Chapter 4.  I actually did not realize that Opera comes with a &#8216;mobile emulator&#8217;.  Now that I actually have a mobile data plan, I&#8217;ve begun to realize how important this is.  For example, my site will not currently load up on my mobile browser, though I wouldn&#8217;t exactly call my mobile browser &#8216;modern&#8217;.  My next theme redesign will definitely take into account the mobile web.</li>
<li>Chapter 5 discusses lots of really interesting effects (3D and aqua buttons, reflections).  By describing how these effects are generated using layers, gradients, blurs, and masks, one starts to visualize how these individual techniques can be combined to produce other effects seen on the web.</li>
<li>Chapter 6 gives us a good introduction to some vector graphic formats, including a glimpse at VRML and X3D.  I would have liked to learn a little bit more of X3D, maybe I should find some time to do that.</li>
</ul>
<p>All in all, it&#8217;s been an interesting read.  Now on to what I&#8217;m most interested in:  Vectors.  More to come&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2008/08/17/painting-the-web-having-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

