<?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>SAPessi &#187; JavaScript</title>
	<atom:link href="http://sapessi.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://sapessi.com</link>
	<description>Perfection of means and confusion of aims...</description>
	<lastBuildDate>Wed, 10 Aug 2011 07:36:04 +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>Draggable directions with Google Maps APIs</title>
		<link>http://sapessi.com/2010/03/draggable-directions-with-google-maps-apis/</link>
		<comments>http://sapessi.com/2010/03/draggable-directions-with-google-maps-apis/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 11:51:20 +0000</pubDate>
		<dc:creator>Stefano Buliani</dc:creator>
				<category><![CDATA[My Works]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WWW]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[Directions]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Maps]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sapessi.com/?p=358</guid>
		<description><![CDATA[I love calculating driving directions on Google Maps and then drag the blue line marking my directions to change the route. Everything is updated automatically on the page and the directions are re-calculated to go through the new point I defined. I&#8217;ve been playing around with the Google Maps APIs recently and imagine my disappointment [...]<!-- Easy AdSense V2.82 -->
<!-- Post[count: 2] -->
<div class="ezAdsense adsense adsense-leadout" style="text-align:center;margin:12px;"><script type="text/javascript"><!--
google_ad_client = "pub-8456780651289352";
/* 468x60, created 11/24/09 */
google_ad_slot = "7140896000";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<!-- Easy AdSense V2.82 -->

]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;source=sapessi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I love calculating driving directions on Google Maps and then drag the blue line marking my directions to change the route. Everything is updated automatically on the page and the directions are re-calculated to go through the new point I defined.</p>
<p>I&#8217;ve been playing around with the <a href="http://code.google.com/apis/maps/" target="_blank">Google Maps APIs</a> recently and imagine my disappointment when I found out that Google does not allow directions calculated through the APIs to be dragged around.</p>
<p>Not put off by this I decided to try and replicate the directions-dragging myself. How hard can it be?<br />
As it turns out. Very, at least if you want to make it look as smooth as Google&#8217;s own solution.</p>
<p>When generating directions Google Maps adds a <a href="http://code.google.com/apis/maps/documentation/reference.html#GPolyline" target="_blank">GPolyline</a> element overlay to your map. You can set the returned line to be editable but this makes an awful lot of vertices appear on it, which makes reading your directions quite hard. Even so, once you dragged one of this vertices around you are not editing the route but just changing the shape of the line.</p>
<p>Mine is not a complete solution and I&#8217;m interested in feedback and ideas on how to improve it.</p>
<p>First off calculate your directions:</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;">map <span class="sy0">=</span> <span class="kw2">new</span> google.<span class="me1">maps</span>.<span class="me1">Map2</span><span class="br0">&#40;</span>document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&#8216;map_canvas&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw2">var</span> wayPoints <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
wayPoints.<span class="me1">push</span><span class="br0">&#40;</span>startPoint.<span class="me1">getLatLng</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
wayPoints.<span class="me1">push</span><span class="br0">&#40;</span>endPoint.<span class="me1">getLatLng</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="kw2">var</span> myDir <span class="sy0">=</span> <span class="kw2">new</span> google.<span class="me1">maps</span>.<span class="me1">Directions</span><span class="br0">&#40;</span>map<span class="br0">&#41;</span><br />
myDir.<span class="me1">loadFromWaypoints</span><span class="br0">&#40;</span>wayPoints<span class="sy0">,</span> <span class="br0">&#123;</span> travelMode<span class="sy0">:</span> G_TRAVEL_MODE_DRIVING <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>This will calculate your driving directions and plot a GPolyline on your map. The line is easily accessible in the GDirections object once the directions are calculated. To intercept this I have decided to use the <strong>addoverlay</strong> event on the GMap object. This event is triggered every time something is plotted over the map (says on the tin).</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;">google.<span class="me1">maps</span>.<span class="me1">Event</span>.<span class="me1">addListener</span><span class="br0">&#40;</span>myDir<span class="sy0">,</span> <span class="st0">&quot;addoverlay&quot;</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> dirLine <span class="sy0">=</span> myDir.<span class="me1">getPolyline</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// Get the polyline from the directions object</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>At this point we can ask the APIs to make the GPolyline editable. This will make the vertices appear on the line and make then draggable. As I said before this only changes the shape of the line and doesn&#8217;t actually affect your directions object. Luckily the GPolyline comes with a nifty event called <strong>lineupdated</strong>.<br />
This is triggered once the user has finished dragging a vertex. By intercepting this we can look through the vertices and know what&#8217;s been changed on the line and where the vertex has been moved to.<br />
In order to do this we must also know the previous position of the vertices (latitude and longitude) to be able to compare the old and the new &#8220;edited&#8221; line.<br />
Another challenge is the fact that the <a href="http://code.google.com/apis/maps/documentation/reference.html#GDirections" target="_blank">GDirections</a> object can accept only so many waypoints (25 if I&#8217;m not wrong). Which means we&#8217;ll have to add only the vertex that has changed to the directions and not all of them.</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;"><span class="co1">// In the addoverlay event also save the original vertices of the line</span><br />
<span class="kw2">var</span> origLine <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&amp;</span>lt<span class="sy0">;</span> dirLine.<span class="me1">getVertexCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
origLine.<span class="me1">push</span><span class="br0">&#40;</span>dirLine.<span class="me1">getVertex</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="co1">// DONE saving vertices</span></p>
<p><span class="co1">// Now intercept the lineupdated event and add the new waypoints</span><br />
google.<span class="me1">maps</span>.<span class="me1">Event</span>.<span class="me1">addListener</span><span class="br0">&#40;</span>dirLine<span class="sy0">,</span> <span class="st0">&quot;lineupdated&quot;</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
routePoints <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&amp;</span>lt<span class="sy0">;</span> dirLine.<span class="me1">getVertexCount</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> savedPoint <span class="sy0">=</span> origLine<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">;</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>savedPoint <span class="sy0">||</span> <span class="br0">&#40;</span>savedPoint.<span class="me1">lat</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">!=</span> dirLine.<span class="me1">getVertex</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">lat</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp<span class="sy0">;&amp;</span>amp<span class="sy0">;</span> savedPoint.<span class="me1">lng</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">!=</span> dirLine.<span class="me1">getVertex</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">lng</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
routePoints.<span class="me1">push</span><span class="br0">&#40;</span>dirLine.<span class="me1">getVertex</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="co1">// Now we remove the previous directions and recalculate the route</span><br />
map.<span class="me1">removeOverlay</span><span class="br0">&#40;</span>dirLine<span class="br0">&#41;</span><br />
calcRoute<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>This works quite well but does not look as smooth as Google&#8217;s solution.<br />
The problem is that while you are dragging a vertex only that bit of the GPolyline moves and the rest stays in its original position. which makes the shape of your directions quite awkward while you are dragging. Unforunately the GPolyline does not come with a &#8220;startdragging&#8221; event, otherwise we could just recalculate the route every few seconds while the vertex is being dragged.</p>
<p>This is not the most elegant of solutions but it does the job.</p>
<!-- Easy AdSense V2.82 -->
<!-- Post[count: 3] -->
<div class="ezAdsense adsense adsense-leadout" style="text-align:center;margin:12px;"><script type="text/javascript"><!--
google_ad_client = "pub-8456780651289352";
/* 468x60, created 11/24/09 */
google_ad_slot = "7140896000";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<!-- Easy AdSense V2.82 -->

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;submitHeadline=Draggable+directions+with+Google+Maps+APIs&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;title=Draggable+directions+with+Google+Maps+APIs" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;title=Draggable+directions+with+Google+Maps+APIs" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;title=Draggable+directions+with+Google+Maps+APIs" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;bm_description=Draggable+directions+with+Google+Maps+APIs" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;T=Draggable+directions+with+Google+Maps+APIs" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;title=Draggable+directions+with+Google+Maps+APIs" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;title=Draggable+directions+with+Google+Maps+APIs" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Draggable+directions+with+Google+Maps+APIs+@+http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fsapessi.com%2F2010%2F03%2Fdraggable-directions-with-google-maps-apis%2F&amp;t=Draggable+directions+with+Google+Maps+APIs" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://sapessi.com/2010/03/draggable-directions-with-google-maps-apis/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Server side JavaScript with node.js</title>
		<link>http://sapessi.com/2009/11/server-side-javascript-with-node-js/</link>
		<comments>http://sapessi.com/2009/11/server-side-javascript-with-node-js/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 17:01:12 +0000</pubDate>
		<dc:creator>Stefano Buliani</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Node]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[V8]]></category>

		<guid isPermaLink="false">http://sapessi.com/?p=337</guid>
		<description><![CDATA[While skimming through my RSS feed I stumbled upon an interesting article on Ajaxian about server side JavaScript programming. I really, really enjoy writing JavaScript code so I decided to read through the article and take a look at the node.js library linked there. Node is a framework to build server-side event-driven JavaScript applications. Developed [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;source=sapessi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>While skimming through my RSS feed I stumbled upon an interesting <a href="http://ajaxian.com/archives/full-frontal-09-simon-willison-on-server-side-javascript-and-node-js" target="_blank">article on Ajaxian about server side JavaScript programming</a>.</p>
<p>I really, really enjoy writing JavaScript code so I decided to read through the article and take a look at the <a href="http://nodejs.org/" target="_blank">node.js library linked there</a>.</p>
<p><a href="http://nodejs.org" target="_blank"><img class="aligncenter size-full wp-image-339" title="node.js logo" src="http://sapessi.com/wp-content/uploads/2009/11/node_js_logo.jpg" alt="node.js logo" width="293" height="90" /></a></p>
<p>Node is a framework to build server-side event-driven JavaScript applications. Developed in C++ on top of <a href="http://en.wikipedia.org/wiki/V8_%28JavaScript_engine%29" target="_blank">Google&#8217;s V8 JavaScript engine</a> and accompanied by a set of JavaScript libraries Node seems to make building distributed (over a network), fast applications a piece of cake even for inexperienced developers.<br />
Event-driven here really is the keyword because it represent a big change in the way applications are built (and architected in your brain).</p>
<blockquote><p>Node is similar in design to and influenced by systems like Ruby&#8217;s <a href="http://rubyeventmachine.com/">Event Machine</a> or Python&#8217;s <a href="http://twistedmatrix.com/">Twisted</a>.  Node takes the event         model a bit further—it presents the event loop as a language         construct instead of as a library. In other systems there is always         a blocking call to start the event-loop.  Typically one defines         behavior through callbacks at the beginning of a script and at the         end starts a server through a blocking call like
<div class="codesnip-container" >EventMachine<span>::</span><span>run</span><span>()</span></div>
<p>. In Node there is no such         start-the-event-loop call.  Node simply enters the event loop after         executing the input script.</p></blockquote>
<p>The example below (taken from Node&#8217;s website) will make everything clear&#8230; hopefully.</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;"><span class="kw2">var</span> sys <span class="sy0">=</span> require<span class="br0">&#40;</span><span class="st0">&#8216;sys&#8217;</span><span class="br0">&#41;</span><span class="sy0">,</span><br />
&nbsp; &nbsp; &nbsp;http <span class="sy0">=</span> require<span class="br0">&#40;</span><span class="st0">&#8216;http&#8217;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>http.<span class="me1">createServer</span><span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span>req<span class="sy0">,</span> res<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; setTimeout<span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; res.<span class="me1">sendHeader</span><span class="br0">&#40;</span><span class="nu0">200</span><span class="sy0">,</span> <span class="br0">&#123;</span><span class="st0">&#8216;Content-Type&#8217;</span><span class="sy0">:</span> <span class="st0">&#8216;text/plain&#8217;</span><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; res.<span class="me1">sendBody</span><span class="br0">&#40;</span><span class="st0">&#8216;Hello World&#8217;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; res.<span class="me1">finish</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; <span class="br0">&#125;</span><span class="sy0">,</span> 2000<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">listen</span><span class="br0">&#40;</span>8000<span class="br0">&#41;</span><span class="sy0">;</span><br />
sys.<span class="me1">puts</span><span class="br0">&#40;</span><span class="st0">&#8216;Server running at http://127.0.0.1:8000/&#8217;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>Can you see the beauty?!</p>
<p>I have only one worry. This is an open-source effort. The community behind it on Google groups is just 181 members strong (so far). What if node.js suddenly stops being the cool thing and the community disappears.</p>
<p>As much as I love writing JavaScript and I can really see the value in what they are building I&#8217;ll still wait until there are 100 Google Groups for node.js and a trillion members in each before using it in anything close to a production system.</p>
<p>Having said that I&#8217;m going back to writing silly node.js apps now. Well done to all the developers involved in the project and keep it up!</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;submitHeadline=Server+side+JavaScript+with+node.js&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;title=Server+side+JavaScript+with+node.js" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;title=Server+side+JavaScript+with+node.js" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;title=Server+side+JavaScript+with+node.js" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;bm_description=Server+side+JavaScript+with+node.js" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;T=Server+side+JavaScript+with+node.js" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;title=Server+side+JavaScript+with+node.js" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;title=Server+side+JavaScript+with+node.js" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Server+side+JavaScript+with+node.js+@+http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fserver-side-javascript-with-node-js%2F&amp;t=Server+side+JavaScript+with+node.js" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://sapessi.com/2009/11/server-side-javascript-with-node-js/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>SVG graphics with JavaScript</title>
		<link>http://sapessi.com/2009/11/svg-graphics-with-javascript/</link>
		<comments>http://sapessi.com/2009/11/svg-graphics-with-javascript/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 13:47:03 +0000</pubDate>
		<dc:creator>Stefano Buliani</dc:creator>
				<category><![CDATA[My Works]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WWW]]></category>
		<category><![CDATA[Charts]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RaphaelJS]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[TweetSentiment]]></category>

		<guid isPermaLink="false">http://sapessi.com/?p=327</guid>
		<description><![CDATA[When I started developing TweetSentiment I decided that the interface should have as little text as possible. Most of the information I was interested in could be displayed graphically, with a chart. So I looked at all the options available for chart generation. Backend code to generate a static image (JFreeChart or PHP) Flash object [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;source=sapessi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>When I started developing <a href="http://tweetsentiment.info" target="_blank">TweetSentiment</a> I decided that the interface should have as little text as possible. Most of the information I was interested in could be displayed graphically, with a chart.</p>
<p>So I looked at all the options available for chart generation.</p>
<ol>
<li>Backend code to generate a static image (<a href="http://www.jfree.org/jfreechart/" target="_blank">JFreeChart</a> or PHP)</li>
<li>Flash object to draw a chart retrieving the data from a URL</li>
<li>Draw charts in JavaScript directly on the client&#8217;s browser</li>
</ol>
<p>I&#8217;m not a huge fan of option one. Primarily because TweetSentiment is hosted on a tiny linux box which would not be able to handle the load for the traffic the site gets, also because it&#8217;s a static image &#8211; it&#8217;s just not very funky &#8211; no interaction possible.</p>
<p>Option two would certainly create spectacular looking charts but I have almost no experience with flash and I wasn&#8217;t about to start learning a new language/technology. Plus I&#8217;m not into browser plugins if I can avoid them.</p>
<p>JavaScript is a language I&#8217;m familiar with and I remember seeing some cool-looking charts generated with <a href="http://www.dojotoolkit.org/" target="_blank">Dojo</a>. Unfortunately for TweetSentiment I have used jquery since the most important thing for me there was DOM manipulation (and jquery is just better for that).<br />
I then started shopping around for <a href="http://jquery.com/" target="_blank">jQuery</a> plugins to generate charts. There are a few around but none of them impressed me. They just weren&#8217;t as good looking as I&#8217;d hoped nor they were interactive.</p>
<p>By coincidence I stumbled on <a href="http://raphaeljs.com/" target="_blank">RaphaelJS</a>. A JavaScript library to draw <a href="http://en.wikipedia.org/wiki/Scalable_Vector_Graphics" target="_blank">Scalable Vector Graphics</a> directly from JavaScript based on jQuery. I tested the samples on the website with a few browsers and I was happy to discover it worked just fine with all of them.</p>
<blockquote>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;"><strong>Scalable Vector Graphics</strong> (<strong>SVG</strong>) is a family of specifications of an <a style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial;" title="XML" href="/wiki/XML">XML</a>-based <a style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial;" title="File format" href="/wiki/File_format">file format</a> for describing two-dimensional <a style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial;" title="Vector graphics" href="/wiki/Vector_graphics">vector graphics</a>, both static and dynamic (i.e. interactive or <a style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial;" title="SVG animation" href="/wiki/SVG_animation">animated</a>).</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">The SVG specification is an <a style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial;" title="Open standard" href="/wiki/Open_standard">open standard</a> that has been under development by the <a style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial;" title="World Wide Web Consortium" href="/wiki/World_Wide_Web_Consortium">World Wide Web Consortium</a> (W3C) since 1999.</p>
</blockquote>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">I also discovered that there is a <a href="http://g.raphaeljs.com/" target="_blank">charting library built on top of RaphaelJS</a>, which is exactly what I was looking for. However, being a geek, I decided to go ahead and try to develop something on my own. You know, just for kicks.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">As I delved deeper into RaphaelJS I found the library to be incredibly powerful. It&#8217;s a shame that the <a href="http://raphaeljs.com/reference.html" target="_blank">documentation provided on the website</a> lets it down a bit.<br />
The most powerful bit is the ability to extend objects and attach new functions to them. Something scarcely mentioned in the available documentation.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">For example if you need to use curved lines (paths as SVG calls them) you can just defined a default function you can then call from your code simply by adding it to the <strong>el </strong>&#8220;object&#8221; in RaphaelJS</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;">Raphael.<span class="me1">el</span>.<span class="me1">curveTo</span> <span class="sy0">=</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">var</span> args <span class="sy0">=</span> Array.<span class="me1">prototype</span>.<span class="me1">splice</span>.<span class="me1">call</span><span class="br0">&#40;</span>arguments<span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> arguments.<span class="me1">length</span><span class="br0">&#41;</span><span class="sy0">,</span><br />
&nbsp; d <span class="sy0">=</span> <span class="br0">&#91;</span><span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="st0">&quot;s&quot;</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="st0">&quot;c&quot;</span><span class="br0">&#93;</span><span class="br0">&#91;</span>args.<span class="me1">length</span><span class="br0">&#93;</span> <span class="sy0">||</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">this</span>.<span class="me1">isAbsolute</span> <span class="sy0">&amp;</span>amp<span class="sy0">;&amp;</span>amp<span class="sy0">;</span> <span class="br0">&#40;</span>d <span class="sy0">=</span> d.<span class="me1">toUpperCase</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">this</span>._last <span class="sy0">=</span> <span class="br0">&#123;</span>x<span class="sy0">:</span> args<span class="br0">&#91;</span>args.<span class="me1">length</span> <span class="sy0">-</span> 2<span class="br0">&#93;</span><span class="sy0">,</span> y<span class="sy0">:</span> args<span class="br0">&#91;</span>args.<span class="me1">length</span> <span class="sy0">-</span> 1<span class="br0">&#93;</span><span class="br0">&#125;</span><span class="sy0">;</span><br />
&nbsp; <span class="kw1">return</span> <span class="kw1">this</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="br0">&#123;</span>path<span class="sy0">:</span> <span class="kw1">this</span>.<span class="me1">attrs</span>.<span class="me1">path</span> <span class="sy0">+</span> d <span class="sy0">+</span> args<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><span class="sy0">;</span></div>
</div>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">Another very useful function I found in one of their samples is the <strong>andClose() </strong>This is used to close a polygon you have started drawing with paths. No matter where you got to it will reconnect to the initial point.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;">Raphael.<span class="me1">el</span>.<span class="me1">andClose</span> <span class="sy0">=</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">return</span> <span class="kw1">this</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="br0">&#123;</span>path<span class="sy0">:</span> <span class="kw1">this</span>.<span class="me1">attrs</span>.<span class="me1">path</span> <span class="sy0">+</span> <span class="st0">&quot;z&quot;</span><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><span class="sy0">;</span></div>
</div>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">This can then be used this way using <a href="http://ejohn.org/blog/ultra-chaining-with-jquery/" target="_blank">chaining</a>.</p>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;">RaphaelJSElement.<span class="me1">lineTo</span><span class="br0">&#40;</span>x<span class="sy0">,</span> opts.<span class="me1">height</span> <span class="sy0">-</span> bottomgutter<span class="br0">&#41;</span>.<span class="me1">andClose</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">I&#8217;m still developing the chart library I used in TweetSentiment and I&#8217;m planning to publish it here with some documentation under MIT licence.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;submitHeadline=SVG+graphics+with+JavaScript&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;title=SVG+graphics+with+JavaScript" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;title=SVG+graphics+with+JavaScript" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;title=SVG+graphics+with+JavaScript" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;bm_description=SVG+graphics+with+JavaScript" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;T=SVG+graphics+with+JavaScript" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;title=SVG+graphics+with+JavaScript" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;title=SVG+graphics+with+JavaScript" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+SVG+graphics+with+JavaScript+@+http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Fsvg-graphics-with-javascript%2F&amp;t=SVG+graphics+with+JavaScript" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://sapessi.com/2009/11/svg-graphics-with-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaScript games &#8211; more thoughts on O3D</title>
		<link>http://sapessi.com/2009/10/javascript-games-more-thoughts-on-o3d/</link>
		<comments>http://sapessi.com/2009/10/javascript-games-more-thoughts-on-o3d/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 15:23:56 +0000</pubDate>
		<dc:creator>Stefano Buliani</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[WWW]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Multiplayer]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[O3D]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://sapessi.com/?p=255</guid>
		<description><![CDATA[This week I wrote a post comparing O3D and WebGL. Today I have finally spent some time playing with O3D and managed to implement some very simple applications. Now that I have a clearer understanding of what O3D can and can&#8217;t do I have given some thought to the possibility of writing videogames in JavaScript. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;source=sapessi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This week I wrote a post <a href="http://sapessi.com/2009/10/webgl-and-o3d/" target="_blank">comparing O3D and WebGL</a>.</p>
<p>Today I have finally spent some time playing with <a href="http://code.google.com/apis/o3d/" target="_blank">O3D</a> and managed to implement some very simple applications.</p>
<p>Now that I have a clearer understanding of what O3D can and can&#8217;t do I have given some thought to the possibility of writing videogames in JavaScript. As I mentioned in my previous post I can&#8217;t see myself playing something like <a href="http://fallout.bethsoft.com/index.html" target="_blank">Fallout</a> in a browser window. Nonetheless I can imagine simple multiplayer games, something like Monopoly or Risk, working this way.</p>
<p>I have developed quite a few JS applications that allowed users connected at the same time to interact with each other. It&#8217;s very simple, constant AJAX posts and gets with a server keeping the state of the interaction. Imagine something like GTalk integrated inside GMail.</p>
<p>This is all well and good when the interaction is limited to a few chat messages or coordinates of the mouse pointer on the screen, but multiplayer videogames have to shift a massive amount of data every second. When you play Gran Turismo online the position, speed and state of each player&#8217;s car must e synched across all the participants as often as possible. Add chat/voice data to that and you&#8217;ll soon realise that 30 players for one game calling your server at the same time to get and post data is just not manageable. Furthermore to ensure the timely delivery of the data to each client you are much better off pushing the data to the client rather than relying on it to call your server.</p>
<p>What O3D should add to its APIs is a <a href="http://en.wikipedia.org/wiki/DirectPlay" target="_blank">DirectPlay</a> alternative. Multiplayer support built straight into O3D. This way your JavaScript game will be able to establish peer-to-peer communication between all the clients without having to stress your servers. Simple socket communication giving the developers the ability to push data between all the peers connected.<br />
Network support by being built inside the O3D plugin could also deal with all the annoying connectivity issues such as &#8220;punching&#8221; through NATs.</p>
<p>Without properly implemented network play I don&#8217;t think we&#8217;ll ever see 3D games flourish in your browser window.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;submitHeadline=JavaScript+games+%26%238211%3B+more+thoughts+on+O3D&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;title=JavaScript+games+%26%238211%3B+more+thoughts+on+O3D" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;title=JavaScript+games+%26%238211%3B+more+thoughts+on+O3D" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;title=JavaScript+games+%26%238211%3B+more+thoughts+on+O3D" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;bm_description=JavaScript+games+%26%238211%3B+more+thoughts+on+O3D" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;T=JavaScript+games+%26%238211%3B+more+thoughts+on+O3D" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;title=JavaScript+games+%26%238211%3B+more+thoughts+on+O3D" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;title=JavaScript+games+%26%238211%3B+more+thoughts+on+O3D" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+JavaScript+games+%26%238211%3B+more+thoughts+on+O3D+@+http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fjavascript-games-more-thoughts-on-o3d%2F&amp;t=JavaScript+games+%26%238211%3B+more+thoughts+on+O3D" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://sapessi.com/2009/10/javascript-games-more-thoughts-on-o3d/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WebGL and O3D</title>
		<link>http://sapessi.com/2009/10/webgl-and-o3d/</link>
		<comments>http://sapessi.com/2009/10/webgl-and-o3d/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 13:51:36 +0000</pubDate>
		<dc:creator>Stefano Buliani</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[WWW]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[O3D]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://sapessi.com/?p=237</guid>
		<description><![CDATA[You may have read recently that Khronos is implementing something called WebGL. The objective of the project is to expose all of OpenGL ES calls to javascript. Thus allowing hardware accellerated 3d graphics within a browser. Google has also been working on an alternative, called O3D. Let&#8217;s first talk about the technical differencies between the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;source=sapessi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>You may have read recently that <a href="http://www.khronos.org/news/press/releases/khronos-webgl-initiative-hardware-accelerated-3d-graphics-internet/" target="_blank">Khronos is implementing something called WebGL</a>. The objective of the project is to expose all of OpenGL ES calls to javascript. Thus allowing hardware accellerated 3d graphics within a browser.<br />
Google has also been working on an alternative, called <a href="http://code.google.com/apis/o3d/" target="_blank">O3D</a>.</p>
<p>Let&#8217;s first talk about the technical differencies between the two projects.</p>
<p>O3D and WebGL while both trying to bring accellerated 3D graphics to the web have taken two fairly different courses. As I mentioned in the introduction to this post WebGL&#8217;s plan is just to expose to JavaScript OpenGL ES 2.0 APIs. Whereas Google&#8217;s solution is based on a browser plugin.</p>
<p>If we think about this we&#8217;ll soon realise that WebGL depends entirely on JavaScript. JavaScript, as of today, is a fairly slow language. This point was made in a <a href="http://groups.google.com/group/o3d-discuss/browse_thread/thread/7bfa31efcc03b5f6?pli=1" target="_blank">discussion thread on the O3D project website</a>.</p>
<blockquote><p>WebGL, being 100% dependent on JavaScript to do an application&#8217;s scene  graph, is going to have serious problems drawing more than a few pieces of  geometry at 60hz except in very special cases or on very fast machines. This  means WebGL requires JavaScript to:</p>
<p>*) do all parent-child matrix calculations for a transform graph.</p>
<p>*) all culling calculations (bounding box to frustum or other)</p>
<p>*) all sorting calculations for dealing with transparent objects.</p>
<p>*) all animation calculations.</p>
<p>As an example the kitty demo in O3D is doing linear  interpolations on 2710 floats to animate 170 transforms.  The point is not that the artist that created  the kitty should probably not have used 170 bones. <img src='http://sapessi.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   Rather the point is it seems unlikely that JavaScript<br />
will be able to do that anytime soon and if it can then  just add more than one kitty to pass its limits.</p></blockquote>
<p>Also we have to keep in mind that not all hardware supports OpenGL ES.</p>
<p>O3D, By virtue of being a browser plugin written in C++, so an additional (hopefully fast) abstraction layer on top of the GPU, allowed Google to define a new set of APIs to expose to JavaScript and keep us (the JavaScript developers) away from the hardware. O3D will take care of the interaction with either DirectX or OpenGL.</p>
<p>Furthermore Google has open-sourced O3D through its Google Code website. Which means we can all have a look at their code and participate in the project. This resulted in a lot of documentation being available. For a full overview of how O3D works check out the <a href="http://code.google.com/apis/o3d/docs/techoverview.html" target="_blank">technical overview</a> on the O3D project page.</p>
<p>Do you think that this is the making of a new &#8220;Standards war&#8221;? Both Google and Khronos are adamant that they are not competing. However I believe that ultimately only one project will come out as a standard. As the complexity of 3D web applications increases it is not feasible to write code for both &#8220;APIs&#8221;. The only question for me at this point is who will come out on top.</p>
<p>To answer this I would look at the audience of the two projects. OpenGL has been out in the wild for a long while and many developers of videogames, or general graphic application, are already familiar with the APIs and the way it works, therefore it would probably make sense for them to embrace WebGL.<br />
Nonetheless O3D still stands a chance. For a very simple reason. It&#8217;s the web we&#8217;re talking about.</p>
<p>Frankly I can&#8217;t see myself playing a big videogame like fallout in a browser window anytime soon. These APIs will be used to enrich web application. Some examples are already coming out using O3D. Have a look at this <a href="http://o3d.googlecode.com/svn/trunk/samples/home-configurators/homedesigner.html" target="_blank">Home Designer</a>. Can&#8217;t you already see IKEA using it.<br />
My point here is that we&#8217;re not likely to see game developers switch to the web. We&#8217;re much more likely to see web developers start working on games or application involving 3d graphics, and this is where Google wins.</p>
<blockquote><p>O3D extends application JavaScript code with an <strong>API for 3D graphics</strong>. It uses standard JavaScript event processing and callback methods.</p></blockquote>
<p>As a web developer I can keep writing JavaScript code as I&#8217;m used to without having to change the way I think to how a game developer does.</p>
<p>What do you think?</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/uofWfXOzX-g&amp;rel=0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en&amp;feature=player_embedded&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/uofWfXOzX-g&amp;rel=0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en&amp;feature=player_embedded&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;submitHeadline=WebGL+and+O3D&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;title=WebGL+and+O3D" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;title=WebGL+and+O3D" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;title=WebGL+and+O3D" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;bm_description=WebGL+and+O3D" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;T=WebGL+and+O3D" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;title=WebGL+and+O3D" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;title=WebGL+and+O3D" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+WebGL+and+O3D+@+http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fsapessi.com%2F2009%2F10%2Fwebgl-and-o3d%2F&amp;t=WebGL+and+O3D" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://sapessi.com/2009/10/webgl-and-o3d/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

