<?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>Mozilla Hacks - the Web developer blog &#187; Canvas</title>
	<atom:link href="http://hacks.mozilla.org/category/canvas/feed/" rel="self" type="application/rss+xml" />
	<link>http://hacks.mozilla.org</link>
	<description>hacks.mozilla.org</description>
	<lastBuildDate>Wed, 08 Feb 2012 22:52:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating thumbnails with drag and drop and HTML5 canvas</title>
		<link>http://hacks.mozilla.org/2012/02/creating-thumbnails-with-drag-and-drop-and-html5-canvas/</link>
		<comments>http://hacks.mozilla.org/2012/02/creating-thumbnails-with-drag-and-drop-and-html5-canvas/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 14:00:28 +0000</pubDate>
		<dc:creator>Janet Swisher</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Featured Demo]]></category>
		<category><![CDATA[FileAPI]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=11119</guid>
		<description><![CDATA[HTML5 Canvas is a very cool feature. Seemingly just an opportunity to paint inside the browser with a very low-level API you can use it to heavily convert and change image and video content in the document. Today, let&#8217;s take a quick look at how you can use Canvas and the FileReader API to create [...]]]></description>
			<content:encoded><![CDATA[<p>HTML5 Canvas is a very cool feature. Seemingly just an opportunity to paint inside the browser with a very low-level API you can use it to heavily convert and change image and video content in the document. Today, let&#8217;s take a quick look at how you can use Canvas and the FileReader API to create thumbnails from images dropped into a browser document.</p>
<p>The <a href="https://github.com/codepo8/canvasthumber">final code is available on GitHub</a> and you can see an <a href="http://thewebrocks.com/demos/canvasthumber/">online demo here</a>. There is also a screencast available on YouTube:</p>
<p><iframe width="500" height="284" src="http://www.youtube.com/embed/cYN45FixIgI?rel=0" frameborder="0" allowfullscreen></iframe></p>
<h2>Step 1: Getting the files into the browser</h2>
<p>The first step to resize images in the browser is to somehow get them. For this, we can just add an element in the page and assign drag and drop event handlers to it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">s.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'dragover'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span> evt <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  evt.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
s.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'drop'</span><span style="color: #339933;">,</span> getfiles<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Notice that we only prevent the default behaviour when we drag things over the element. This is to prevent the browser from just showing the images when we drag them in. </p>
<p>The <code>getfiles()</code> function then does the hard work of reading all the files in and sending them on to the functions that do the resizing and image generation:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> getfiles<span style="color: #009900;">&#40;</span> ev <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> files <span style="color: #339933;">=</span> ev.<span style="color: #660066;">dataTransfer</span>.<span style="color: #660066;">files</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> files.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> files.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> i<span style="color: #339933;">--</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> file <span style="color: #339933;">=</span> files<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> file.<span style="color: #660066;">type</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'image'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
      <span style="color: #003366; font-weight: bold;">var</span> reader <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> FileReader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      reader.<span style="color: #660066;">readAsDataURL</span><span style="color: #009900;">&#40;</span> file <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      reader.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span> ev <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> ev.<span style="color: #660066;">target</span>.<span style="color: #660066;">result</span><span style="color: #339933;">;</span>
        img.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        imagetocanvas<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> thumbwidth<span style="color: #339933;">,</span> thumbheight<span style="color: #339933;">,</span> crop<span style="color: #339933;">,</span> background <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  ev.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The <code>drop</code> event gives us a property called <code>dataTransfer</code> which contains a list of all the files that have been dropped. We make sure that there was at least one file in the drop and then iterate over them.</p>
<p>If the file type was not an image (or in other words the type property of the file does not contain the string &#8220;image&#8221;) we don&#8217;t do anything with the file and continue the loop.</p>
<p>If the file is an image we instantiate a new <code>FileReader</code> and tell it to read the file as a Data URL. When the reader successfully loaded the file it fires its <code>onload</code> handler.</p>
<p>In this handler we create a new image and set its <code>src</code> attribute to the <code>result</code> of the file transfer. We then send this image to the <code>imagetocanvas()</code> function with the parameters to resize (in the demo these come from the form):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> imagetocanvas<span style="color: #009900;">&#40;</span> img<span style="color: #339933;">,</span> thumbwidth<span style="color: #339933;">,</span> thumbheight<span style="color: #339933;">,</span> crop<span style="color: #339933;">,</span> background <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  c.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> thumbwidth<span style="color: #339933;">;</span>
  c.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> thumbheight<span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> dimensions <span style="color: #339933;">=</span> resize<span style="color: #009900;">&#40;</span> img.<span style="color: #660066;">width</span><span style="color: #339933;">,</span> img.<span style="color: #660066;">height</span><span style="color: #339933;">,</span> thumbwidth<span style="color: #339933;">,</span> thumbheight <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> crop <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    c.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> dimensions.<span style="color: #660066;">w</span><span style="color: #339933;">;</span>
    c.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> dimensions.<span style="color: #660066;">h</span><span style="color: #339933;">;</span>
    dimensions.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    dimensions.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> background <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'transparent'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    cx.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> background<span style="color: #339933;">;</span>
    cx.<span style="color: #660066;">fillRect</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> thumbwidth<span style="color: #339933;">,</span> thumbheight <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  cx.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span> 
    img<span style="color: #339933;">,</span> dimensions.<span style="color: #660066;">x</span><span style="color: #339933;">,</span> dimensions.<span style="color: #660066;">y</span><span style="color: #339933;">,</span> dimensions.<span style="color: #660066;">w</span><span style="color: #339933;">,</span> dimensions.<span style="color: #660066;">h</span> 
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  addtothumbslist<span style="color: #009900;">&#40;</span> jpeg<span style="color: #339933;">,</span> quality <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This function gets the desired thumbnail size and resizes the canvas to these dimensions. This has the added benefit of wiping the canvas so that no old image data would be added to our thumbnail. We then resize the image to fit into the thumbnail using a <code>resize()</code> function. You can see for yourself what this one does in the source code, it just means the image gets resized to fit. The function returns an object with the width and the height of the new image and the x and y position where it should be positioned onto the canvas. </p>
<p>If we don&#8217;t want the full-size thumbnail but instead crop it we resize the canvas accordingly and reset x and y to 0.</p>
<p>If the user requested a background we fill the canvas with the colour. After that we put the image on the canvas with the x and y coordinates and the new width and height. </p>
<p>This takes care of creating a new thumbnail on the canvas, but we haven&#8217;t got it as an image in the document yet. To this end, we call  <code>addtothumbslist()</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> addtothumbslist<span style="color: #009900;">&#40;</span> jpeg<span style="color: #339933;">,</span> quality <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> thumb <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      url <span style="color: #339933;">=</span> jpeg <span style="color: #339933;">?</span> c.<span style="color: #660066;">toDataURL</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'image/jpeg'</span> <span style="color: #339933;">,</span> quality <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> c.<span style="color: #660066;">toDataURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  thumb.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> url<span style="color: #339933;">;</span>
  thumb.<span style="color: #660066;">title</span> <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span> url.<span style="color: #660066;">length</span> <span style="color: #009966; font-style: italic;">/ 1000 * 100 ) /</span> <span style="color: #CC0000;">100</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' KB'</span><span style="color: #339933;">;</span>
  o.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span> thumb <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This one creates a new image and checks if the users wanted a JPG or PNG image to be created. PNG images tend to be better quality but also bigger in file size. If a JPG was requested we call the canvas&#8217; <code>toDataURL()</code> method with two parameters: the requested JPEG mime type and the quality of the image (ranging between 0 and 1 with 1 being best quality). If a PNG is wanted, we can just call <code>toDataURL()</code> without any parameters as this is the default.</p>
<p>We set the <code>src</code> of the image to the  generated url string and add a title showing the size of the image in KB (rounded to two decimals). All that is left then is to add the thumb to the output element on the page.</p>
<p>That&#8217;s it, you can now drag and drop images into the browser to generate thumbnails. Right now, we can only save them one at a time (or if you have some download add-ons all at once). Would be fun to add <a href="gildas-lormeau.github.com/zip.js/">Zip.js</a> to the mix to offer them as a zip. I dare you! :)</p>
<p>More reading:</p>
<ul>
<li><a href="https://developer.mozilla.org/en/DragDrop/Drag_and_Drop">Drag and Drop</a> on MDN</a></li>
<li><a href="https://developer.mozilla.org/en/DOM/FileReader">FileReader</a> on MDN</a></li>
<li><a href="https://developer.mozilla.org/en/HTML/Canvas">Canvas</a> on MDN</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2012/02/creating-thumbnails-with-drag-and-drop-and-html5-canvas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Interview: Nikhil Suresh on Building His Winning Canvas Demo</title>
		<link>http://hacks.mozilla.org/2012/01/interview-nikhil-suresh-on-building-his-winning-canvas-demo/</link>
		<comments>http://hacks.mozilla.org/2012/01/interview-nikhil-suresh-on-building-his-winning-canvas-demo/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 05:36:48 +0000</pubDate>
		<dc:creator>Janet Swisher</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Dev Derby]]></category>
		<category><![CDATA[Gaming]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=11033</guid>
		<description><![CDATA[Editor&#8217;s Note: Back in November, Nikhil Suresh (@nklsrh2) from Sydney, Australia, won the MDN Developer Derby with his distinctive, non-violent 2-person shooter game Bouncy and the Apple. We thought it&#8217;d be fun to learn a little more about Nikhil and what inspires him. Congratulations Nikhil, and thanks for your thoughtful words about Mozilla. We&#8217;re honored [...]]]></description>
			<content:encoded><![CDATA[<p><em>Editor&#8217;s Note: Back in <a href="https://developer.mozilla.org/demos/devderby/2011/november/">November</a>, <a href="https://developer.mozilla.org/en-US/profiles/nklsrh/">Nikhil Suresh</a> (<a href="http://www.twitter.com/nklsrh2">@nklsrh2</a>) from Sydney, Australia, won the <a href="https://developer.mozilla.org/en-US/demos/devderby">MDN Developer Derby</a> with his distinctive, non-violent 2-person shooter game <a href="https://developer.mozilla.org/en-US/demos/detail/bouncy-and-the-apple">Bouncy and the Apple</a>. We thought it&#8217;d be fun to learn a little more about Nikhil and what inspires him.<br />
Congratulations Nikhil, and thanks for your thoughtful words about Mozilla. We&#8217;re honored to showcase your demo.</em><br />
<a href="http://hacks.mozilla.org/2012/01/interview-nikhil-suresh-on-building-his-winning-canvas-demo/nikhil-5/" rel="attachment wp-att-11058"><img src="http://hacks.mozilla.org/wp-content/uploads/2012/01/nikhil4-250x374.jpg" alt="Nikhil Suresh" title="nikhil" width="250" height="374" class="alignright size-medium wp-image-11058" /></a><br />
<strong>Tell us about developing <em>Bouncy and the Apple</em> and where your idea came from?</strong></p>
<p>I really wanted my demo to stand out from the crowd, so it had to possess a singular feature that would impress. Since my passion is game development, I decided to implement game controller support in whatever game I would build for the Derby. I built Bouncy to be a twin-stick shooter which would stand out as a demo for the <a href="https://wiki.mozilla.org/GamepadAPI">Mozilla Gamepad API</a> as well as Canvas.</p>
<p>Usually, I tend to stay away from violence in my games, so it was a bit difficult at first (a ‘shooter’ without any violence!)</p>
<p>Incidentally, it was the Mozilla mascots that inspired me to draw Bouncy (the spikes in the hair were directly from the brown dude with the hat!): </p>
<p><a href="http://www.mozilla.org/en-US/firefox/brand/"><img src="http://hacks.mozilla.org/wp-content/uploads/2012/01/illustrations-characters-500x364.png" alt="Mozilla Brand Toolkit images" title="illustrations-characters" width="500" height="364" class="aligncenter size-large wp-image-11093" /></a></p>
<p><strong><br />
How did you get started coding and hacking?</strong></p>
<p>Funnily enough, it started in Microsoft PowerPoint, where I realized I could &#8216;hyperlink&#8217; from a slide to any other one. I then created a quiz game, not unlike the TV show &#8216;Who wants to be a Millionaire?.&#8217; From that, I moved onto Visual Basic (in which I became Microsoft-Certified in 2008) C# and XNA, and eventually began learning JavaScript (after playing around with the Processing language).</p>
<p><strong>What was your first computer?</strong></p>
<p>I don’t really remember much about my first computer, except the fact it had a Pentium II, which was not powerful enough to run some of the new games I wanted to play.<br />
<strong><br />
What games do you play the most these days?</strong></p>
<p>On the console, I prefer racing games like <a href="http://www.formula1-game.com/uk/">F1 2011</a> and <a href="http://www.gran-turismo.com/">Gran Turismo</a>. On the PC, I like to play indie games like <a href="http://supercratebox.com ">Super Crate Box</a> and <a href="http://finalformgames.com/jamestown/">Jamestown</a>. I also love Valve games like Portal.</p>
<p><strong>Are you working on another demo or any other cool projects you want to share?</strong></p>
<p>I&#8217;m currently participating in the <a href="http://www.pokki.com/1up/">Pokki 1UP game development competition</a>, with a friend. We are building a 2D/3D arcade game called BLASTR:ARENA. It uses <a href="http://en.wikipedia.org/wiki/WebGL">WebGL</a> for 3D graphics and <a href="https://developer.mozilla.org/en/Canvas_tutorial">Canvas</a> for the 2D fallback.</p>
<p><a href="http://hacks.mozilla.org/2012/01/interview-nikhil-suresh-on-building-his-winning-canvas-demo/11-2-2/" rel="attachment wp-att-11066"><img src="http://hacks.mozilla.org/wp-content/uploads/2012/01/11-21-500x281.png" alt="Blastrs Game in development " title="Blastrs screengrab" width="500" height="281" class="aligncenter size-large wp-image-11066" /></a></p>
<p><strong>You mentioned that you recently graduated from high school? What&#8217;s next for you?</strong></p>
<p>I have just enrolled in the Bachelor of Engineering (Software) course at the University of New South Wales. During my degree, I will also be developing games part-time, hopefully for a chance at breaking into the gamedev industry.</p>
<p><strong>When you think about HTML5 and new Web technologies what are you most excited about?</strong></p>
<p>As my game clearly demonstrates, HTML5 and other web technologies provide the browser the ability to render other traditional applications obsolete, replacing them with a unified system which can serve as the basis for anything from games to word processors.</p>
<p>As I’m most interested in game development, the introduction of the <a href="https://hacks.mozilla.org/2012/01/using-the-fullscreen-api-in-web-browsers/">Fullscreen</a> and <a href="https://developer.mozilla.org/en/API/Gamepad/Using_Gamepad_API">Gamepad APIs</a>, as well as performance increases in WebGL and Canvas give the Web a greater chance of overthrowing consoles as an effective game platform.</p>
<p><strong>Anybody else who helped you with Bouncy and the Apple whom you&#8217;d like to give a shout out to?</strong> </p>
<p>My aunt, who had come over for a holiday, was a fantastic source of inspiration and ideas, so it was a great feeling to finally play <a href="http://www.youtube.com/watch?v=TOTi1fPWVeA&#038;feature=player_embedded">the finished game</a> with her on the big screen. I’d also like to thank my parents for letting me stick to my plans, even if I skipped dinner and stayed up until 1AM on some nights. I’m also grateful to my brother for putting up with my endless repeating game music. </p>
<p><strong>You mentioned that you&#8217;re a big fan of Mozilla&#8217;s work on the Open Web. Can you say something more about why you think that&#8217;s important?</strong></p>
<p>I think Mozilla is a fantastic, one-of-a-kind organisation since it works and innovates solely with the well-being of the Web and its users in mind. With such an open and direct goal, it means everyone, from the users to the developers, benefit from the development of Mozilla products and technologies.<br />
Also, Mozilla’s work on HTML, CSS, Javascript and other web technology is for the mutual benefit of all, fostering the advancement of the open Web as a mainstream platform of the present and future generations.</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2012/01/interview-nikhil-suresh-on-building-his-winning-canvas-demo/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Congratulations November Dev Derby Winners</title>
		<link>http://hacks.mozilla.org/2012/01/congratulations-november-dev-derby-winners/</link>
		<comments>http://hacks.mozilla.org/2012/01/congratulations-november-dev-derby-winners/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 01:09:50 +0000</pubDate>
		<dc:creator>Havi Hoffman</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Dev Derby]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=10721</guid>
		<description><![CDATA[Canvas is a new HTML5 element which creates a digital &#8220;drawing board.&#8221; A web developer can use one of these drawing boards along with some JavaScript to create simple shapes, graphs, animations, interactive games, and more. Recently, eighteen creative minds showed us just how powerful and important Canvas is by sharing their work in the [...]]]></description>
			<content:encoded><![CDATA[<p>Canvas is a new HTML5 element which creates a digital &#8220;drawing board.&#8221; A web developer can use one of these drawing boards along with some JavaScript to create simple shapes, graphs, animations, interactive games, and more. Recently, eighteen creative minds showed us just how powerful and important Canvas is by sharing their work in the <a href="https://developer.mozilla.org/en-US/demos/devderby/2011/november/" title="November Dev Derby - Canvas">November Dev Derby</a>. </p>
<p><a href="https://developer.mozilla.org/en-US/demos/devderby/"><img alt="" src="http://hacks.mozilla.org/wp-content/uploads/2011/07/logo-devderby.png" title="Mozilla Demo Studio presents Dev Derby on MDN" class="aligncenter" width="335" height="96" /></a></p>
<p>Once again, this was a fairly close race, so join us in congratulating the winners:<br />
<a href="https://developer.mozilla.org/en-US/demos/devderby/2011/november/" title="November Dev Derby - Canvas"><img src="http://hacks.mozilla.org/wp-content/uploads/2012/01/devderby-november-2011-winners1.png" alt="" title="devderby-november-2011-winners" width="500" height="204" class="alignnone size-full wp-image-10772" /></a></p>
<p><strong>1st Place:</strong> <a href="https://developer.mozilla.org/en-US/demos/detail/bouncy-and-the-apple">Bouncy and the Apple &#8211; Canvas</a> by <a href="https://developer.mozilla.org/en-US/profiles/nklsrh/">nklsrh</a><br />
<strong>2nd Place:</strong> <a href="https://developer.mozilla.org/hu/demos/detail/rob-in-soundland">Rob in Soundland</a> by <a href="https://developer.mozilla.org/hu/profiles/michal.b/">michal.b</a><br />
<strong>3rd Place:</strong> <a href="https://developer.mozilla.org/en-US/demos/detail/vandalism">Vandalism</a> by <a href="https://developer.mozilla.org/en-US/profiles/tuxie/">tuxie</a></p>
<p><strong>Runners-up:</strong><br />
<a href="https://developer.mozilla.org/en-US/demos/detail/jump-the-wall">Jump the Wall</a> by <a href="https://developer.mozilla.org/en-US/profiles/avnishkgaur/">avnishkgaur</a><br />
<a href="https://developer.mozilla.org/en-US/demos/detail/cirplosion">Cirplosion</a> by <a href="https://developer.mozilla.org/en-US/profiles/Awesome/">Awesome</a></p>
<p>Thanks to everyone who participated in the November and December Dev Derbies!  We love your demos. In the days ahead, we&#8217;ll be rounding up the votes on December&#8217;s <a href="https://developer.mozilla.org/en-US/demos/devderby/2011/december/" title="December Dev Derby">IndexedDB submissions</a>. Now&#8217;s the time to get your January Orientation demos built and submitted. Can&#8217;t wait to give them a spin (or a tilt).</p>
<p><strong><em>REMINDER: We recently updated our <a href="https://developer.mozilla.org/en-US/demos/devderby/rules" title="Dev Derby rules">Dev Derby rules</a> to allow developers to participate in multiple contests until they win 1st place.</em></strong>  That means if you&#8217;ve submitted awesome demos and come up short in the past, you still have a chance to win that top spot in future Dev Derbies&#8230; so keep those demos coming!</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2012/01/congratulations-november-dev-derby-winners/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>People of HTML5: Joe Lambert unshredding images in Canvas</title>
		<link>http://hacks.mozilla.org/2011/11/people-of-html5-joe-lambert-unshredding-images-in-canvas/</link>
		<comments>http://hacks.mozilla.org/2011/11/people-of-html5-joe-lambert-unshredding-images-in-canvas/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 16:22:19 +0000</pubDate>
		<dc:creator>Chris Heilmann</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[People of HTML5]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[imagemanipulation]]></category>
		<category><![CDATA[joelambert]]></category>
		<category><![CDATA[unshredder]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=10343</guid>
		<description><![CDATA[Today we have a quickie for you: Joe Lambert, a web developer from Southampton, England working for Rareloop took on the Instagram engineering challenge of un-shredding a shredded image but instead of using server-side code, he used HTML5 canvas. Here&#8217;s a screencast of his solution to the problem: And here we are in a quick [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://hacks.mozilla.org/wp-content/uploads/2011/11/joelambert.jpg" width="150" alt="Joe Lambert" style="float:left;padding:0 5px 5px 0;">Today we have a quickie for you: <a href="http://blog.joelambert.co.uk/">Joe Lambert</a>, a web developer from Southampton, England working for Rareloop took on the <a href="http://instagram-engineering.tumblr.com/post/12651721845/instagram-engineering-challenge-the-unshredder">Instagram engineering challenge of un-shredding a shredded image</a> but instead of using server-side code, he used HTML5 canvas. Here&#8217;s a screencast of <a href="http://www.joelambert.co.uk/unshred/">his solution to the problem</a>:</p>
<p><video controls width="100%" controls preload="none" poster="http://cf.cdn.vid.ly/4l1c3l/poster.jpg"><source src="http://cf.cdn.vid.ly/4l1c3l/mp4.mp4" type="video/mp4"><source src="http://cf.cdn.vid.ly/4l1c3l/webm.webm" type="video/webm"><source src="http://cf.cdn.vid.ly/4l1c3l/ogv.ogv" type="video/ogg"><a target='_blank' href='http://vid.ly/4l1c3l'><img src='http://cf.cdn.vid.ly/4l1c3l/poster.jpg' width="500"></a></video></p>
<p>And here we are in a quick interview, chatting about how he approached the problem and why he used web technologies:</p>
<p><video controls width="100%" controls preload="none" poster="http://cf.cdn.vid.ly/0t8x3o/poster.jpg"><source src="http://cf.cdn.vid.ly/0t8x3o/mp4.mp4" type="video/mp4"><source src="http://cf.cdn.vid.ly/0t8x3o/webm.webm" type="video/webm"><source src="http://cf.cdn.vid.ly/0t8x3o/ogv.ogv" type="video/ogg"><a target='_blank' href='http://vid.ly/0t8x3o'><img src='http://cf.cdn.vid.ly/0t8x3o/poster.jpg' width="500"></a></video></p>
<h2>1) The specs of the competition said you can use Python, Ruby or C++ and you went instead for JavaScript and Canvas. Why?</h2>
<p>JavaScript is my language of choice and what I use most of the time. I also find it the most fun as its easy to post your creations online and show people immediately, no downloads or dependencies to worry about. I wasn&#8217;t really looking to get hired by Instagram so adhering strictly to the rules wasn&#8217;t a big deal. Essentially it was an appealing problem that I thought could be solved in a browser, so wanted to prove that was the case.</p>
<p>I actually knew from the start that creating the algorithm to unshred the image was only half of what I wanted to do. That in itself was going to be a challenge and quite satisfying to solve but I really wanted to get to a point where I could make the slices move into the right place. I wouldn&#8217;t have been able to create this effect as quickly in any other environment.</p>
<h2>2) How did you approach the problem of unshredding the images? Did you do similar things before? What is the logic you use?</h2>
<p>I wasn&#8217;t too worried about the most efficient algorithm so I just started by thinking about how a human might solve this type of problem. I&#8217;ve played around with image data a little before but nothing that would have been directly useful to this particular problem. </p>
<p>If I were solving this in the physical world I&#8217;d start by picking up a slice at random then pick up each other shredded slice and see if it looked like it fitted to the left or right of the piece in my hand. I&#8217;d then repeat this till the image was back to its original state. </p>
<p>This gave an indication of the kind of structure my code should have, I just needed to work out how to computationally measure whether two strips ought to be next to one another. For this I just compared the pixels closest to each edge and measured the euclidean distance between the colour values. It seemed to work pretty well!</p>
<h2>3) I see you are not using typed arrays in your solution yet. It seems to perform well the way it is now, do you think they&#8217;d make a difference?</h2>
<p>I&#8217;m not sure, efficiency wasn&#8217;t high on my priorities for this challenge so I didn&#8217;t really look to optimise it but as you mention it seems to perform quite well. I haven&#8217;t tried the algorithm with larger images but I suspect it would perform not so well.</p>
<h2>4) What was the feedback so far? Has Instagram contacted you?</h2>
<p>The feedback has been really positive, especially via Twitter. I think generally the competition has had quite a high profile which certainly helped. </p>
<p>Instagram haven&#8217;t been in contact yet but it would be good to hear from them. I suspect they&#8217;re focusing on all the people who used the recommended languages </p>
<h2>5) Seeing how easy this was can you see other challenges with images and canvas? Could you think of ways how to make it easier for developers, for example by extending the API?</h2>
<p>The way you access pixel data in Canvas is a little complicated, it might be useful to have some helper functions to let you get access to a single pixel via X/Y coordinates. I ended up writing a little helper function to do this for this challenge, I&#8217;m going to try get the code up on GitHub shortly so this might be of use for others.</p>
<p>It would also have been useful to have been able to call <code>toDataURL()</code> on a <code>CanvasPixelArray</code> object. My implementation used the DOM and CSS3 transitions to move the images into their correct places after the algorithm had solved the order, being able to access a Data URI for each slice would have be handy.</p>
<p>If you want to chat with Joe, he is available on Twitter as <a href="https://twitter.com/joelambert">@joelambert</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/11/people-of-html5-joe-lambert-unshredding-images-in-canvas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://cf.cdn.vid.ly/4l1c3l/mp4.mp4" length="3105011" type="video/mp4" />
<enclosure url="http://cf.cdn.vid.ly/4l1c3l/webm.webm" length="3308392" type="video/webm" />
<enclosure url="http://cf.cdn.vid.ly/4l1c3l/ogv.ogv" length="2734792" type="video/ogg" />
<enclosure url="http://cf.cdn.vid.ly/0t8x3o/mp4.mp4" length="38959359" type="video/mp4" />
<enclosure url="http://cf.cdn.vid.ly/0t8x3o/webm.webm" length="39531417" type="video/webm" />
<enclosure url="http://cf.cdn.vid.ly/0t8x3o/ogv.ogv" length="19489380" type="video/ogg" />
		</item>
		<item>
		<title>Mozilla hacks Weekly, November 24th 2011</title>
		<link>http://hacks.mozilla.org/2011/11/mozilla-hacks-weekly-november-24th-2011/</link>
		<comments>http://hacks.mozilla.org/2011/11/mozilla-hacks-weekly-november-24th-2011/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 12:44:29 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Mozilla Hacks Weekly]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=10284</guid>
		<description><![CDATA[It&#8217;s Thursday, folks, and it means our Developer Engagement Team at Mozilla has some reading tips for you! Weekly links November 24th 2011 If there is anything you think we should read or know about, don&#8217;t hesitate to post a comment, contact us on Twitter or through any other mean. The picks this week are: [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s Thursday, folks, and it means our Developer Engagement Team at Mozilla has some reading tips for you!</p>
<p><span id="more-10284"></span></p>
<h2>Weekly links November 24th 2011</h2>
<p>If there is anything you think we should read or know about, don&#8217;t hesitate to post a comment, contact us on Twitter or through any other mean.<br />
The picks this week are:</p>
<h3>Christian Heilmann</h3>
<div class="team-member">
	<img src="http://hacks.mozilla.org/wp-content/uploads/2011/08/chris-heilmann.jpg" alt="A picture of Christian Heilmann"> HTML5rocks has <a href="http://www.html5rocks.com/en/tutorials/cors/">a simple CORS tutorial</a>.</p>
<p>    If you want to read more tips or discuss the web with Christian, he&#8217;s available on Twitter as <a href="http://twitter.com/codepo8">@codepo8</a>.
</div>
<h3>Havi Hoffman</h3>
<div class="team-member">
    <img src="http://hacks.mozilla.org/wp-content/uploads/2011/08/havi-hoffman.jpg" alt="A picture of Havi Hoffman"> Read it and weep: <a href="http://www.themorningnews.org/article/home-for-the-holiday-tech-support">Home for the Holidays Tech Support</a> &#8211; Will you be called upon to “fix the Internet” or help your dad root his new tablet?</p>
<p>    Havi can be found on Twitter as <a href="http://twitter.com/freshelectrons">@freshelectrons</a>
</div>
<h3>Janet Swisher</h3>
<div class="team-member">
    <img src="http://hacks.mozilla.org/wp-content/uploads/2011/08/janet-swisher.jpeg" alt="A picture of Janet Swisher"> <a href="http://www.kameleoon.com/">Kameleoon</a> is a web application that lets non-coding designers tweak an existing website’s design, and then generates the modified HTML and CSS for them. You can also use it for A/B testing of different designs.</p>
<p>    If you want to read more tips or discuss the web with Janet, she&#8217;s available on Twitter as <a href="http://twitter.com/jmswisher">@jmswisher</a>.
</div>
<h3>Jeff Griffiths</h3>
<div class="team-member">
	<img src="http://hacks.mozilla.org/wp-content/uploads/2011/11/jeff-griffiths.jpg" alt="A picture of Jeff Griffiths"> Brilliant post from Rob Campbell detailing some excellent <a href="http://antennasoft.net/robcee/2011/11/18/inspector-scratchpad-and-web-console-power-tips/">Firefox dev tools power tips</a> currently available in <a href="http://www.mozilla.org/en-US/firefox/channel/">Firefox Aurora</a>.</p>
<p>    If you want to read more tips or discuss the web with Jeff, he&#8217;s available on Twitter as <a href="http://twitter.com/canuckistani">@canuckistani</a>.
</div>
<h3>Robert Nyman</h3>
<div class="team-member">
	<img src="http://hacks.mozilla.org/wp-content/uploads/2011/07/robert-nyman.jpg" alt="A picture of Robert Nyman"> <a href="http://jlongster.com/2011/11/21/canvas.html">Going Fullscreen with HTML5 Canvas</a> &#8211; Nice and simple example how you can utilize the Fullscreen API to create a complete full-screen canvas experience.</p>
<p>    If you want to read more tips or discuss the web with Robert, he&#8217;s available on Twitter as <a href="http://twitter.com/robertnyman">@robertnyman</a>.
</div>
<h3>Stormy Peters</h3>
<div class="team-member">
    <img src="http://hacks.mozilla.org/wp-content/uploads/2011/07/stormy-peters.jpg" alt="A picture of Stormy Peters"> Should you really have to wait for that email to send? <a href="http://alexmaccaw.co.uk/posts/async_ui">Asynchronous UIs &#8211; the future of web user interfaces</a>.</p>
<p>    If you want to read more tips or discuss the web with Stormy, she&#8217;s available on Twitter as <a href="http://twitter.com/storming">@storming</a></p>
<div>
<style>
    .team-member { overflow: hidden; margin-bottom: 15px; }
    .team-member img { float: left; margin: 0 20px 10px 0; }
    .team-member ul { margin-left: 0; }
    .team-member li { margin-left: 180px; }
</style>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/11/mozilla-hacks-weekly-november-24th-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Webinar: Canvas with Rob Hawkes</title>
		<link>http://hacks.mozilla.org/2011/11/webinar-canvas-with-rob-hawkes/</link>
		<comments>http://hacks.mozilla.org/2011/11/webinar-canvas-with-rob-hawkes/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 19:38:17 +0000</pubDate>
		<dc:creator>Janet Swisher</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Webinars]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=10011</guid>
		<description><![CDATA[Update 2011-11-10: Video of this webinar is now available: This video is also available on Vimeo. You can download the code that Rob demos in the webinar. You might also check out the recording of the webinar created by BigBlueButton. It syncs the audio with the slides and chat window using Popcorn.js. On the downside, [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Update 2011-11-10:</strong> Video of this webinar is now available:<br />
<video controls="true" width="500"><br />
<source src="http://www.archive.org/download/MdnWebinarOnCanvasWithRobHawkes/Webinar_canvas_2011-11-08.mp4"<br />
type="video/mp4"><br />
<source src="http://www.archive.org/download/MdnWebinarOnCanvasWithRobHawkes/Webinar_canvas_2011-11-08.webm"<br />
type="video/webm"><br />
<source src="http://www.archive.org/download/MdnWebinarOnCanvasWithRobHawkes/Webinar_canvas_2011-11-08.ogv"<br />
type="video/ogg"><br />
<a href="http://vimeo.com/31851888">This video is also available on Vimeo</a>.<br />
</video><br />
You can <a href="http://cl.ly/BdoA">download the code</a> that Rob demos in the webinar.</p>
<p>You might also check out the <a href="http://m5.blindsidenetworks.com/playback/slides/playback.html?meetingId=cd847d892e51c9af96a07d5f1327caaaa74f5961-1320768324375">recording of the webinar created by BigBlueButton</a>. It syncs the audio with the slides and chat window using <a href="http://popcornjs.org/">Popcorn.js</a>. On the downside, BBB starts recording as soon as anyone joins the conference audio bridge, which in this case happened an hour before the webinar started. Fast-forward to time 58:20 for the start of the webinar.
</p></blockquote>
<p>Please join us on Tuesday, November 8th at 17:00 UTC (<a href="http://www.timeanddate.com/worldclock/converter.html?year=2011&#038;month=11&#038;day=8&#038;hour=17&#038;min=0&#038;sec=0&#038;p1=0&#038;p2=24">convert to your local time</a>) for a webinar on using the <a href="https://developer.mozilla.org/en/HTML/Canvas">Canvas API</a>, with our own <a href="http://hacks.mozilla.org/author/robhawkes/">Rob Hawkes</a>, author of <cite><a href="http://rawkes.com/foundationcanvas">Foundation HTML5 Canvas</a></cite>. </p>
<p>Canvas is the topic for the November <a href="https://developer.mozilla.org/en-US/demos/devderby">Dev Derby</a>. Rob is planning to show how to make an image editor for avatars using Canvas. Spark your imagination with the webinar, create some new and amazing use of Canvas, and <a href="https://developer.mozilla.org/en-US/demos/submit?tags=challenge%3A2011%3Anovember">submit it to the Dev Derby</a>.</p>
<p>We will use <a href="http://bigbluebutton.org/">BigBlueButton</a> for web-conferencing, and will avoid using the feature that led to the server problems with the September webinar. We will be recording the session, and I promise to double- and triple-check the recording set-up in advance :-)</p>
<p>Add this event to your calendar:<br />
<a target="_blank" href="https://www.google.com/calendar/event?action=TEMPLATE&#038;tmeid=Mzd2bnR0dTUybmxobnRuc2RnNzg3bGg4ODAgN2F0Z2Qyb3Z0dGRpZWExYThwNmZrc2tzZjhAZw&#038;tmsrc=7atgd2ovttdiea1a8p6fksksf8%40group.calendar.google.com"><img border="0" src="http://www.google.com/calendar/images/ext/gc_button1_en.gif"></a></p>
<p>We&#8217;d like to get a rough estimate of how many people will be attending. If you happen to use Plancast, and you plan to attend the seminar, please <a href="http://plancast.com/p/898j">join the event on Plancast</a>.</p>
<p>To join the webinar:</p>
<ol>
<li>Go to the <a href="http://mozilla.bigbluebutton.org/mozilla/">BigBlueButton server for Mozilla</a>.</li>
<li>For Full Name, enter your name.</li>
<li>Select “Mozilla Developer Network” in the Room list.</li>
<li>For Password, enter MDNHacks.</li>
<p>Note: Big Blue Button uses Flash, so make sure you have the latest version installed, especially if you are running Mac OS X Lion.</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/11/webinar-canvas-with-rob-hawkes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
<enclosure url="http://www.archive.org/download/MdnWebinarOnCanvasWithRobHawkes/Webinar_canvas_2011-11-08.mp4" length="0" type="video/mp4" />
<enclosure url="http://www.archive.org/download/MdnWebinarOnCanvasWithRobHawkes/Webinar_canvas_2011-11-08.ogv" length="0" type="video/ogg" />
		</item>
		<item>
		<title>Direct2D Azure hits Firefox 7</title>
		<link>http://hacks.mozilla.org/2011/09/direct2d-azure-hits-firefox-7/</link>
		<comments>http://hacks.mozilla.org/2011/09/direct2d-azure-hits-firefox-7/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 14:11:25 +0000</pubDate>
		<dc:creator>Mozilla Hacks</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Firefox 7]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=9627</guid>
		<description><![CDATA[Based on a blog post originally posted here by Bas Schouten, Firefox Developer. Hrm, Azure, what&#8217;s that again? You can find out all about Azure other blog posts, there&#8217;s an introduction from Joe Drew and there&#8217;s several more in detailed posts discussing the Direct2D Azure backend and the performance implications to be found on my [...]]]></description>
			<content:encoded><![CDATA[<p><em>Based on a blog post originally posted <a href="http://www.basschouten.com/blog1.php/direct2d-azure-hits-firefox-7">here</a> by Bas Schouten, Firefox Developer. </em></p>
<p>Hrm, Azure, what&#8217;s that again?</p>
<p>You can find out all about Azure other blog posts, there&#8217;s an <a href="http://blog.mozilla.com/joe/2011/04/26/introducing-the-azure-project/">introduction</a> from Joe Drew and there&#8217;s several more in detailed posts discussing the Direct2D Azure backend and the performance implications to be found on my blog. The bottom line is that we&#8217;re working on a new graphics API that will be used for rendering in Gecko.</p>
<p>What does that mean for Firefox 7?</p>
<p>Well, we&#8217;re currently only using it with Direct2D and when using canvas. This allows us to stress test it, although a wide array of tests has been run, and it has been in use by our Aurora and Beta testers for a while now, there might still be issues we might have missed. If these issues show in the final release we&#8217;ll only have caused a regression in Canvas and for a limited subset of our users, rather than in all browser rendering. The bottom line is you should generally see a speed improvement using 2D Canvas in Firefox 7 when using Windows 7 or Vista with a sufficiently powerful graphics card.</p>
<p>So what&#8217;s next, what&#8217;s the status?</p>
<p>We&#8217;re currently working hard on both a Cairo and a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=687187">Skia</a> backend for the Azure API, this means we&#8217;ll be able to use the Azure API on all platforms. Possibly getting some quick performance benefits on platforms where Skia outperforms the cairo backends we&#8217;re currently using. At the same time we&#8217;re working on creating a layer that will allow controlled migration of all our content drawing code from the current &#8216;Thebes&#8217; API&#8217;s to the new Azure API. Once that is done webpage rendering in general can start taking advantage of all the latest work!</p>
<p>That&#8217;s about all I have for you right now, enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/09/direct2d-azure-hits-firefox-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculated drop shadows in HTML5 canvas</title>
		<link>http://hacks.mozilla.org/2011/08/calculated-drop-shadows-in-html5-canvas/</link>
		<comments>http://hacks.mozilla.org/2011/08/calculated-drop-shadows-in-html5-canvas/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 10:09:48 +0000</pubDate>
		<dc:creator>Chris Heilmann</dc:creator>
				<category><![CDATA[Animations]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Demo Studio]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[MDN]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[dropshadow]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=9381</guid>
		<description><![CDATA[One of the best new features of HTML5 when it comes to visual effects is the canvas element and its API. On the surface, it doesn&#8217;t look like much &#8211; just a rectangle in the page you can paint on and wipe. Much like an etch-a-sketch. However, the ability to transform, rotate and scale its [...]]]></description>
			<content:encoded><![CDATA[<p>One of the best new features of HTML5 when it comes to visual effects is the canvas element and its API. On the surface, it doesn&#8217;t look like much &#8211; just a rectangle in the page you can paint on and wipe. Much like an etch-a-sketch. However, the ability to transform, rotate and scale its coordinate system is very powerful indeed once you master it. </p>
<p>Today I want to quickly show how you can do (well simulate) something rather complex with it, like a calculated drop shadow on an element. To see what I mean with this, check out the following demo which is <a href="https://developer.mozilla.org/en-US/demos/detail/calculated-shadow/launch">also available on the Demo Studio</a>:     </p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/wNrfU/embedded/result,js,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/wNrfU/">See animated version on JSFiddle</a></p>
<p>(This is using JSFiddle to show you the demos, so you can click the different tabs to see the JavaScript and CSS needed for the effects. All of the demos are also <a href="https://github.com/codepo8/calculated-shadow">available on GitHub</a>.)    </p>
<p>As you can see, the shadow becomes more blurred and less pronounced the further away the &#8220;sun&#8221; is from it. You can use the mouse to see the effect in the following demo:</p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/XJcpg/1/embedded/result,js,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/XJcpg/1">See mouse enabled demo on JSFiddle</a></p>
<p>Let&#8217;s take a look how that is done. The first step is to have a canvas we can paint on &#8211; you do this simply by having a mouse detection script (which we used for years and years) and a canvas with access to its API: </p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/deePU/1/embedded/js,result,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/deePU/1">See step one on JSFiddle</a></p>
<p>Click the play button of the above example and you see that you can paint on the canvas. However, the issue is that you keep painting on the canvas instead of only having the orb follow the cursor. To do this, we need to wipe the canvas every time the mouse moves. You do this with <code>clearRect()</code></p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/z9Z8T/embedded/js,result,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/z9Z8T">See step two on JSFiddle</a></p>
<p>Running the above example now shows that the orb moves with the mouse. Cool, so this is going to be our &#8220;sun&#8221;. Now we need to place an object on the canvas to cast a shadow. We could just plot it somewhere, but what we really want is it to be in the middle of the canvas and the shadow to go left and right from that. You can move the origin of the canvas&#8217; coordinate system using <code>translate()</code>. Which means though that our orb is now offset from the mouse:</p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/z9Z8T/2/embedded/result,js,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/z9Z8T/2">See step three on JSFiddle</a></p>
<p>If you check the &#8220;fix mouse position&#8221; checkbox you see that this is fixed. As we move the coordinate system to the half of the width of the canvas and half of its height, we also need to substract these values from the mouse x and y position. </p>
<p>Now we can draw a line from the centre of the canvas to the mouse position to see the distance using <code>c.moveTo( 0, 0 );c.lineTo( distx, disty );</code> where <code>distx</code> and <code>disty</code> are the mouse position values after the shifting:</p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/z9Z8T/4/embedded/result,js,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/z9Z8T/4">See step four on JSFiddle</a></p>
<p>In order to find out the distance of the shadow, all we need to do is multiply the mouse coordinates with -1 &#8211; in this demo shown as a red line:</p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/z9Z8T/5/embedded/result,js,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/z9Z8T/5">See step five on JSFiddle</a></p>
<p>This gives us a shadow distance from the centre opposite of the mouse position, but we don&#8217;t want the full length. Therefore we can apply a factor to the length, in our case 0.6 or 60%:</p>
<p><iframe style="width: 100%; height: 320px" src="http://jsfiddle.net/codepo8/z9Z8T/6/embedded/result,js,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/z9Z8T/6">See step six on JSFiddle</a></p>
<p>Now we are ready for some drop shadow action. You can apply shadows to canvas objects using <code>shadowColor</code> and its distance is <code>shadowOffsetX</code> and <code>shadowOffsetY</code>. In our case, this is the end of the red line, the inversed and factored distance from the mouse position to the centre of the canvas:</p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/z9Z8T/7/embedded/result,js,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/z9Z8T/7">See step seven on JSFiddle</a></p>
<p>Now, let&#8217;s blur the shadow. Blurring is done using the <code>shadowBlur</code> property and it is a number starting from 0 to the strength of the blur. We now need to find a way to calculate the blur strength from the distance of the mouse to the centre of the canvas. Luckily enough, <a href="http://en.wikipedia.org/wiki/Pythagorean_theorem">Pythagoras</a> found out for us years ago how to do it. As the x and y coordinate of the mouse are the catheti of a right-angled triangle, we can <a href="http://en.wikipedia.org/wiki/Hypotenuse">calculate the length of the hypothenuse</a> (the distance of the point from the centre of the canvas) using the Square root of the squares of the coordinates or <code>Math.sqrt( ( distx * distx ) + ( disty * disty ) )</code>.</p>
<p>This gives us the distance in pixels, but what the really want is a number much lower. Therefore we can again calculate a factor for the blur strength &#8211; here we use an array for the weakest and strongest blur <code>blur = [ 2, 9 ]</code>. As the canvas itself also has a right-angled triangle from the centre to the top edge points we can calculate the longest possible distance from the center using <code>longest = Math.sqrt( ( hw * hw ) + ( hh * hh ) )</code> where <code>hw</code> is half the width of the canvas and <code>hh</code> half the height. Now all we need to do is to calculate the factor to multiply the distance with as <code>blurfactor = blur[1] / longest</code>. The blur during the drawing of the canvas is the distance of the mouse position multiplied with the factor or <code>currentblur = parseInt( blurfactor * realdistance, 10 );</code>. We  disregard blur values below the range we defined earlier and we have our blurred shadow:</p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/z9Z8T/8/embedded/result,js,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/z9Z8T/8">See step eight on JSFiddle</a></p>
<p>In order to make the shadow weaker the further away the mouse is we can use the alpha value of its <code>rgba()</code> colour. The same principle applies as with the blur, we set our edge values as <code>shadowalpha = [ 3, 8 ]</code> and after calculating them from the distance we apply their inverse as the alpha value with <code>c.shadowColor = 'rgba(0,0,0,' + (1 - currentalpha / 10)  + ')';</code>. This blurs and weakens the shadow:</p>
<p><iframe style="width: 100%; height: 350px" src="http://jsfiddle.net/codepo8/z9Z8T/9/embedded/result,js,html,css/"></iframe><br />
<a href="http://jsfiddle.net/codepo8/z9Z8T/9">See step nine on JSFiddle</a></p>
<p>You can do a lot more with this, for example we could also <a href="http://jsfiddle.net/codepo8/eUYKu/26/">scale the sun orb</a> the further out it gets or use a <a href="http://jsfiddle.net/PHbgN/32/">second shape to resize and blur it</a>. You can also go <a href="http://jsfiddle.net/codepo8/mTaug/17/">completely overboard</a>. </p>
<p>Found a way to optimise this? Tell us about it! </p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/08/calculated-drop-shadows-in-html5-canvas/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Living on the Edge &#8211; new Adobe animation tool sparks necessary conversations</title>
		<link>http://hacks.mozilla.org/2011/08/living-on-the-edge-new-adobe-animation-tool-sparks-necessary-conversations/</link>
		<comments>http://hacks.mozilla.org/2011/08/living-on-the-edge-new-adobe-animation-tool-sparks-necessary-conversations/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 09:14:10 +0000</pubDate>
		<dc:creator>Chris Heilmann</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=9028</guid>
		<description><![CDATA[Adobe made quite some splash in the last days by releasing Edge, a Flash-like tool to create HTML5/CSS3/JS driven animations. There is a need for a tool like that and I for one am very happy to see that Adobe are recognising this. Other tools that try to tackle the same task are already around, [...]]]></description>
			<content:encoded><![CDATA[<p>Adobe made quite some splash in the last days by releasing <a href="http://labs.adobe.com/technologies/edge/">Edge</a>, a Flash-like tool to create HTML5/CSS3/JS driven animations. There is a need for a tool like that and I for one am very happy to see that Adobe are recognising this. Other tools that try to tackle the same task are already around, with the yet to be released <a href="http://animatable.com/">Animatable</a> being shown at quite a few conferences and <a href="http://radiapp.com/">Radi</a> leading the way.</p>
<p>I am even happier that this sparked quite a conversation amongst the developer community &#8211; there are far too many truisms thrown around about HTML5 and CSS3, so anything that makes us re-evaluate the current state is a great idea. </p>
<p>Edge, <a href="http://blogs.adobe.com/conversations/2011/08/adobe-edge-hits-50000-downloads-in-first-24-hours.html">according to Adobe themselves has been downloaded 50,000 times in the first 24 hours</a> and looks much like Flash used to a long time ago:</p>
<p><img src="http://hacks.mozilla.org/wp-content/uploads/2011/08/edge.jpg" alt="Edge showing the wheel demo" title="Edge showing the wheel demo" class="alignnone size-medium wp-image-9029" /></p>
<p>The initial feedback was very polarised, whereas fans of Adobe products heralded this as a new dawn of standards-based animations, others were less impressed <a href="http://www.netmagazine.com/features/devs-respond-adobe-edge">as the UK based .net magazine reports</a>. This is to be expected, as everything with the HTML5 stamp these days gets that kind of treatment. </p>
<h2>So what is going on under the hood of Edge?</h2>
<p>Anna Debenham was one of the first to have a go at <a href="http://maban.co.uk/58">reviewing Edge</a> and having a play with it:</p>
<p><iframe style="width:500px;height:300px" src="http://dev.maban.co.uk/animation/hackasaurus-goggles/"></iframe></p>
<p>As you can see in the frame above, the animations generated with it are fixed in size (either pixels or ems) and all consist of a mix of JavaScript and CSS3 transitions. The engine behind the animations is jQuery. Looking it up in Firebug, we are faced with a lot of DIV elements with positioning and CSS transition information:</p>
<p><img src="http://hacks.mozilla.org/wp-content/uploads/2011/08/firebugoutput.jpg" alt="" title="firebugoutput" width="500" height="586" class="alignnone size-full wp-image-9034" /></p>
<p>This is in stark contrast to tools that try to turn Flash into open technology solutions like the conversions done by Google&#8217;s <a href="http://googlecode.blogspot.com/2011/06/swiffy-convert-swf-files-to-html5.html">Swiffy</a>. Swiffy uses SVG to simulate the path-based nature of Flash; Edge doesn&#8217;t and relies on DOM animation of DIV elements instead.</p>
<h2>A total lack of HTML5 in the output</h2>
<p>This caused the main confusion amongst developers and <a href="http://forums.adobe.com/thread/884525">sparked a longer discussion on the Adobe forums</a> initiated by Rob Hawkes. The original problem Rob found with Edge is that it doesn&#8217;t use HTML5 technologies like Canvas or other W3C animation and painting technologies like SVG:</p>
<blockquote><p>Why has Edge gone with div-based animation over other technologies like canvas and SVG? I was deeply saddened to see that not only were divs used in the example files that you released, but that divs are the default option for the stage and any other element that is added to it.</p></blockquote>
<p>Adobe&#8217;s answer was that <a href="http://forums.adobe.com/message/3833054#3833054">animating DOM elements simply is faster</a> and allows for more browser compatibility, especially on mobiles: </p>
<blockquote><p>We seriously considered Canvas, but current performance on mobile browsers (especially iOS) is very bad.  We didn&#8217;t want to have the first experience produce content that couldn&#8217;t run acceptably.  Note that this may be changing in iOS 5, so that&#8217;s good.  Finally, SVG can be a little slow, though we do support bringing in SVG elements and animating them &#8211; just not reach into them.</p></blockquote>
<p>The performance argument is something that keeps cropping up in discussions. A lot of the animations by Google also moved DIV elements around rather than using Canvas and/or SVG (remember the <a href="http://www.wait-till-i.com/2010/09/07/google-goes-bubbly-interactive-logo-today-on-the-uk-homepage-plus-source/">exploding balls logo</a>?) whilst sporting the HTML5 label. </p>
<p>HTML5 Games developer and co-organiser of the <a href="http://ongamestart.com/">onGameStart conference</a> Kamil Trebunia, <a href="http://forums.adobe.com/message/3835209#3835209">questioned the concerns over Canvas being too slow on mobile devices</a>. The great news is that in a backchannel discussion on Twitter, Paul Bakaus, CTO of Zynga Germany pointed out that they are doing intensive research into the subject at the moment and <a href="http://twitter.com/#!/pbakaus/status/98407711699505152">that they are happy to share the outcome at a later stage</a>. So this is something very cool to look forward to and something to complement the <a href="http://developers.facebook.com/blog/post/460/">HTML5 games performance research by Facebook a few months ago</a>.</p>
<h2>Lack of semantics in the output</h2>
<p>The other issue with Edge that puzzled developers is the HTML that gets generated. As <a href="http://www.morenafiore.com/">Morena Fiore</a> asked with <a href="http://www.morenafiore.com/edge/why/">her Edge demo</a> it seems weird that Adobe doesn&#8217;t use SVG and Canvas for animating when the output of the tool doesn&#8217;t feature any semantic HTML whatsoever: </p>
<p><script src="https://gist.github.com/1122169.js"></script></p>
<p>The text content, the tweens and positioning and all the other information of the animation is in JSON objects instead:</p>
<p><script src="https://gist.github.com/1122172.js"></script></p>
<p><a href="http://forums.adobe.com/message/3833002#3833002">Adobe&#8217;s original answer</a> to these concerns was that they don&#8217;t want to touch the original HTML as developers don&#8217;t like that:</p>
<blockquote><p>Our approach is that we separate out the stuff you add from the underlying HTML *AND* we don&#8217;t try to edit the HTML in the way old-style tools did &#8211; in general a lot of people don&#8217;t like when tools muck with HTML.</p>
<p>That said, we will be looking at ways of trimming down the HTML that gets added to a page in the future if that&#8217;s what people want.</p></blockquote>
<p>That sounds like a slippery slope to me. As Tobias Leingruber <a href="http://tobi-x.com/adobe_edge_test/">showed in his firmly tongue-in-cheek demo done with Edge</a> a lack of semantics and enhancing existing markup just means that we now create Flash tunnel pages in a different technology and makes you wonder if the main use case of Edge would be interactive ads that are not blocked by Flashblockers. </p>
<p>This is a challenge that any tool faces: how do I not only allow people to create but also make them aware that web content is not only pretty moving pictures? The <a href="http://animatable.com/demos/madmanimation/">Madmaninmation</a> demo of animatable is a great example &mdash; it is a pure animation but when you check the source code it falls back to a list with the script of the animation. This allows everybody to know what is going on and helps your product to be understood by search engines. Will every user of animatable go through that level of support for the web or simply create animations? </p>
<p>With Edge, Adobe has a chance to do a very cool thing for open web technologies. It will be interesting to see where it goes.</p>
<p>As Bruce Lawson of Opera put it:</p>
<blockquote><p>Designers will require authoring tools that can help them turn their creativity into code, and Adobe have a great track record on making IDEs that designers find user-friendly.</p></blockquote>
<p>So the ball is in Adobe&#8217;s court to do the right thing for the web and move Edge further along (with help from the research the discussion sparked). And they are well on the way and <a href="http://forums.adobe.com/message/3832667#3832667">declared that they are actively looking for feedback</a>:</p>
<blockquote><p>Edge will be evolving rapidly &#8211; the product is by no means feature complete.  We expect to add support for more and more of the HTML universe over time.  Edge does currently support SVG graphics (you can File > Import an SVG image), but you can&#8217;t yet reach into those graphics and animate their components.  The good news is that our JS runtime is capable of animations that include all sorts of HTML Elements, SVG Elements and even Canvas graphics, so we have not boxed ourselves in.</p>
<p>Which of these enhancements would you like to see Edge tackle first?  Canvas?  Embedded SVG?  Ability to select HTML tags other than DIV?</p></blockquote>
<p>I, for one am excited to see Adobe start to wave the flag of open web technologies higher than before. Their new <a href="http://beta.theexpressiveweb.com/">The Expressive Web</a> showcase site is a proof of that. It is up to us now to cry foul at what they do or work side by side to bring the best experiences to the web for our users out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/08/living-on-the-edge-new-adobe-animation-tool-sparks-necessary-conversations/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>The HTML5 canvas clip method</title>
		<link>http://hacks.mozilla.org/2011/07/the-html5-canvas-clip-method/</link>
		<comments>http://hacks.mozilla.org/2011/07/the-html5-canvas-clip-method/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 08:26:31 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=8871</guid>
		<description><![CDATA[HTML5 canvas offers a lot of interesting ways to create effects and experiences on the web. One of the methods to do that, which seem lesser known, is canvas clip. I wrote about it in Using the HTML5 canvas clip method to hide certain content, showing how to stage content and create a looking glass [...]]]></description>
			<content:encoded><![CDATA[<p>HTML5 <code>canvas</code> offers a lot of interesting ways to create effects and experiences on the web. One of the methods to do that, which seem lesser known, is <code>canvas clip</code>.</p>
<p><span id="more-8871"></span></p>
<p>I wrote about it in <a href="http://robertnyman.com/2011/07/26/using-the-html5-canvas-clip-method-to-hide-certain-content/">Using the HTML5 canvas clip method to hide certain content</a>, showing how to stage content and create a looking glass effect. You could also see it in action in the <a href="http://robertnyman.com/playground/canvas/clip/">canvas clip demo</a>.</p>
<p>You could also read up more on it in the <a href="https://developer.mozilla.org/en/Canvas_tutorial/Compositing#Clipping_paths">Clipping paths in the Compositing article on MDN</a> and learn how to create some interesting combinations.</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/07/the-html5-canvas-clip-method/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML5 APIs &#8211; Where No Man Has Gone Before! &#8211; Presentation at Gotham JS</title>
		<link>http://hacks.mozilla.org/2011/07/html5-apis-where-no-man-has-gone-before-presentation-at-gotham-js/</link>
		<comments>http://hacks.mozilla.org/2011/07/html5-apis-where-no-man-has-gone-before-presentation-at-gotham-js/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 13:21:04 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[FileAPI]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[Web Developers]]></category>
		<category><![CDATA[WebGL]]></category>
		<category><![CDATA[WebSocket]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=8758</guid>
		<description><![CDATA[Last weekend I was in New York City to speak at the GothamJS conference and Mozilla also sponsored it. It was a nice event with about 200 attendees, taking place in the NYIT Auditorium on Broadway. The event was one-track with 8 speakers, and personally I always prefer when it&#8217;s just one track for follow-up [...]]]></description>
			<content:encoded><![CDATA[<p>Last weekend I was in New York City to speak at the <a href="http://www.gothamjs.com/">GothamJS conference</a> and Mozilla also sponsored it. It was a nice event with about 200 attendees, taking place in the <a href="http://www.nyit.edu/aob/">NYIT Auditorium on Broadway</a>. </p>
<p>The event was one-track with 8 speakers, and personally I always prefer when it&#8217;s just one track for follow-up discussions and that everyone have seen and heard the same thing. The topics were ranging broadly between script loaders and HTML5 in one end, and voice-controlled telephony applications in the other.</p>
<h3>My presentation</h3>
<p>My talk was about HTML5 APIs in general, to give an introduction to them but also to inspire people to try things out and also give feedback to both working groups and web browser vendors about current implementations.</p>
<p><iframe style="border:none;width:510px;height:425px;" src="http://icant.co.uk/slidesharehtml/embed.php?url=http://www.slideshare.net/robnyman/html5-apis-where-no-man-has-gone-before-gothamjs&amp;width=460&amp;current=1"></iframe></p>
<p><a href="http://www.slideshare.net/robnyman/html5-apis-where-no-man-has-gone-before-gothamjs">Slides can also be downloaded at SlideShare</a>.</p>
<p>Additionally to the APIs covered in my <a href="http://hacks.mozilla.org/2011/07/html5-and-css3-exploring-mobile-possibilities-presentation-at-london-ajax-mobile-event/">London Ajax Mobile Event presentation</a>, I went through <a href="https://developer.mozilla.org/en/WebSockets">Web Sockets</a>, <a href="https://developer.mozilla.org/en/Using_files_from_web_applications">File API</a>, <a href="https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox">HTML5 video</a>, <a href="https://developer.mozilla.org/en/HTML/canvas">canvas</a> and <a href="https://developer.mozilla.org/en/WebGL">WebGL</a>. Also, if you are more interested in the &lt;canvas&gt; element, my colleague Rob Hawkes recently released the <a href="http://rawkes.com/foundationcanvas">Foundation HTML5 Canvas book</a>.</p>
<p>What I especially liked talking about is services like <a href="http://vid.ly/">vid.ly</a> which helps you take control over the problem of different video codec support in different web browsers, by storing various formats and then deliver the most suitable one depending on the web browser/device accessing it. </p>
<p>Another favorite is <a href="http://www.universalsubtitles.org/en/">Universal Subtitles</a>, which is an excellent tool for everyone to be able to add subtitles to a video clip, empowering users with varying language skills to take part of a video and its content and sharing it with the world.</p>
<p>An option to make the content of a web site richer, there is <a href="http://popcornjs.org/">Popcorn.js</a> to sync key events in the video playing to what kind of text or other information you want to present to go with that. To complement that, the <a href="http://butterapp.org/">Butterapp</a> is an editor to create that kind of content syncing, currently in alpha.</p>
<p>I also mentioned <a href="https://developer.mozilla.org/en-US/demos/detail/videograbber/launch">videograbber</a> for taking easy video screenshots in the web browser. </p>
<h3>Dev Derby &lt;video&gt; challenge</h3>
<p>I also want to take the opportunity to remind you that <a href="https://developer.mozilla.org/en-US/demos/devderby">Mozilla Dev Derby</a> has a challenge for what you can accomplish with the &lt;video&gt; that goes till the end of July, so please submit anything if you have a good idea!</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/07/html5-apis-where-no-man-has-gone-before-presentation-at-gotham-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doom on the Web</title>
		<link>http://hacks.mozilla.org/2011/06/doom-on-the-web/</link>
		<comments>http://hacks.mozilla.org/2011/06/doom-on-the-web/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 14:00:15 +0000</pubDate>
		<dc:creator>Janet Swisher</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Gaming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[game]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=8212</guid>
		<description><![CDATA[Update: We had a doubt whether this port of the Open Source Doom respected its term of use. We decided to remove it from our Website before taking an informed and definitive decision. This is a guest post written by Alon Zakai. Alon is one of the Firefox Mobile developers, and in his spare time [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update</strong>: We had a doubt whether this port of the Open Source Doom respected its term of use. We decided to remove it from our Website before taking an informed and definitive decision.</em></p>
<p><em>This is a guest post written by Alon Zakai. Alon is one of the Firefox Mobile developers, and in his spare time does experiments with JavaScript and new web technologies. One of those experiments is <a href="https://github.com/kripken/emscripten">Emscripten</a>, an LLVM-to-JavaScript compiler, and below Alon explains how it uses typed arrays to run the classic first-person shooter <a href="#"><del datetime="2011-06-06T09:56:21+00:00">Doom on the web</del></a>.</em></p>
<p><iframe width="425" height="349" src="http://www.youtube.com/embed/WDUPZRQf7oc" frameborder="0" allowfullscreen></iframe></p>
<p>As a longtime fan of first-person shooters, I&#8217;ve wanted to bring them to the web. Writing one from scratch is very hard, though, so instead I took the original Doom, which is open source, and compiled it from C to JavaScript using <a href="https://github.com/kripken/emscripten">Emscripten</a>. The result is a version of Doom that can be <a href="#"><del datetime="2011-06-06T09:56:21+00:00">played on the web</del></a>, using standard web technologies.</p>
<p>Doom renders by writing out pixel data to memory, then copying that pixel data to the screen, after converting colors and so forth. For this demo, the compiled code has <i>memory</i> that is simulated using a large JavaScript array (so element N in that array represents the contents of memory address N in normal native code). That means that rendering, color conversion, and copying to the screen are all operations done on that large JavaScript array. Basically the code has large loops that copy or modify elements of that array. For that to be as fast as possible, the demo optionally uses JavaScript typed arrays, which look like normal JavaScript arrays but are guaranteed to be <i>flat</i> arrays of a particular data type.</p>
<pre>// Create an array which contains only 32-bit Integers
var buffer = new Int32Array(1000);
for ( var i = 0 ; i < 1000 ; i++ ) {
    buffer[i] = i;
}</pre>
<p>When using a typed array, the main difference from a normal JavaScript array is that the elements of the array all have the type that you set. That means that working on that array can be much faster than a normal array, because it corresponds very closely to a normal low-level C or C++ array. In comparison, a normal JavaScript array can also be <i>sparse</i>, which means that it isn't a single contiguous section of memory. In that case, each access of the array has a cost, that of calculating the proper memory address. Finding the memory address is much faster with a typed array because it is simple and direct. As a consequence, in the Doom demo the frame rate is almost twice as fast with typed arrays than without them.</p>
<p>Typed arrays are very important in WebGL and in the <a href="https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension">Audio Data</a> API, as well as in <a href="https://developer.mozilla.org/en/HTML/Canvas">Canvas</a> elements (the pixel data received from <code>getImageData()</code> is, in fact, a typed array). However, typed arrays can also be used independently if you are working on large amounts of array-like data, which is exactly the case with the Doom demo. Just be careful that your code also works if the user's browser does not support typed arrays. This is fairly easy to do because typed arrays look and behave, for the most part, like normal ones &mdash; you access their elements using square brackets, and so forth. The main potential pitfalls are:</p>
<ul>
<li>Typed arrays do not have the <code>slice()</code>. Instead they have the <code>subarray()</code>, which does not create a copy of the array &mdash; instead it's a view into the same data.
<li>Don't forget that the type of the typed array is silently enforced. If you write 5.25 to an element of an integer-typed array and then read back that exact same element, you get 5 and not 5.25.
</ul>
<style>
.pre {font-size: .8em; background: #F8F8FF; border: 1px solid #DEDEDE; }
</style>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/06/doom-on-the-web/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>MarbleRun, an HTML5 Game</title>
		<link>http://hacks.mozilla.org/2011/04/marblerun-an-html5-game/</link>
		<comments>http://hacks.mozilla.org/2011/04/marblerun-an-html5-game/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 16:28:18 +0000</pubDate>
		<dc:creator>Paul Rouget</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Firefox 4]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=7900</guid>
		<description><![CDATA[Take the HTML5 Canvas element, a Javascript library to do the physics (box2d), add a nice design, a social touch, and you have an awesome HTML5 Game called MarbleRun! MarbleRun was the winner of the last Mozilla Game On Challenge, among other exciting HTML5 games (check them out), and had been added to Web O&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>Take the <a href="https://developer.mozilla.org/en/Canvas_tutorial">HTML5 Canvas element</a>, a Javascript library to do the physics (<a href="https://github.com/jwagner/box2d2-js">box2d</a>), add a nice design, a social touch, and you have an awesome HTML5 Game called <a href="https://demos.mozilla.org/en-US/#marblerun">MarbleRun</a>!</p>
<p>MarbleRun was the winner of the last <a href="http://mozillalabs.com/gaming/2011/02/03/game-on-winners/">Mozilla Game On Challenge</a>, among other exciting HTML5 games (<a href="http://mozillalabs.com/gaming/2011/02/03/game-on-winners/">check them out</a>), and had been added to <a href="http://webowonder.org">Web O&#8217; Wonder</a>.</p>
<p><a href="https://demos.mozilla.org/en-US/#marblerun"><img src="https://gaming.mozillalabs.com/media/uploads/marblerun.png" width="100%"></a></p>
<p>The authors of MarbleRun visited us a couple of weeks ago and gave the following talk about the story of their game:</p>
<p><iframe title="YouTube video player" width="500" height="300" src="http://www.youtube.com/embed/hrHCLQeYz6E" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/04/marblerun-an-html5-game/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Firefox 4 Demos: Runfield &#8211; a Canvas Game</title>
		<link>http://hacks.mozilla.org/2011/03/runfield/</link>
		<comments>http://hacks.mozilla.org/2011/03/runfield/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 16:54:41 +0000</pubDate>
		<dc:creator>Paul Rouget</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Featured Demo]]></category>
		<category><![CDATA[Firefox 4]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=7571</guid>
		<description><![CDATA[Yeah! Another awesome demo in Web&#8217;o Wonder! With Hardware Acceleration and a fast JavaScript engine, the web platform is ready for Games. Runfield is an example. This HTML5 Game has been developed by Ilmari Heikkinen. It&#8217;s based on Canvas 2D, and this game works on all the recent browsers. (small definition version here &#8211; Oh! [...]]]></description>
			<content:encoded><![CDATA[<p>Yeah! Another awesome demo in <a href="https://demos.mozilla.org/en-US/#runfield">Web&#8217;o Wonder</a>!</p>
<p>With Hardware Acceleration and a fast JavaScript engine, the web platform is ready for Games. Runfield is an example. This HTML5 Game has been developed by <a href="http://twitter.com/#!/ilmarihei">Ilmari Heikkinen</a>. It&#8217;s based on Canvas 2D, and this game works on all the recent browsers.</p>
<p><a href="https://mozillademos.org/demos/runfield/demo.html"><img src="https://mozillademos.org/demos/runfield/screenshot.jpg"></a><br />
<em>(small definition version <a href="https://mozillademos.org/demos/runfield/640/">here</a> &#8211; Oh! and check-out the little built-in level editor)</em></p>
<p>Want to see more HTML5 Games? Take a look at <a href="https://gaming.mozillalabs.com">Mozilla Labs Gaming</a>:</p>
<p><a href="https://gaming.mozillalabs.com"><img src="http://hacks.mozilla.org/wp-content/uploads/2011/03/gaming.png" alt="Mozilla Gaming" title="Mozilla Gaming" class="aligncenter"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/03/runfield/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>People of HTML5 &#8211; Rob Hawkes</title>
		<link>http://hacks.mozilla.org/2011/01/people-of-html5-rob-hawkes/</link>
		<comments>http://hacks.mozilla.org/2011/01/people-of-html5-rob-hawkes/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 09:08:00 +0000</pubDate>
		<dc:creator>Chris Heilmann</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Featured Article]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[People of HTML5]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[robhawkes]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=7128</guid>
		<description><![CDATA[HTML5 needs spokespeople to work. There are a lot of people out there who took on this role, and here at Mozilla we thought it is a good idea to introduce some of them to you with a series of interviews and short videos. The format is simple &#8211; we send the experts 10 questions [...]]]></description>
			<content:encoded><![CDATA[<p>HTML5 needs spokespeople to work. There are a lot of people out there who took on this role, and here at Mozilla we thought it is a good idea to introduce some of them to you with a series of interviews and short videos. The format is simple &#8211; we send the experts 10 questions to answer and then do a quick video interview to let them introduce themselves and ask for more detail on some of their answers.</p>
<p><a href="http://www.html5today.it/link/people-of-html5-chris-intervista-rob-hawkes-creatore-gioco-rawkets">Leggi la traduzione in italiano</a></p>
<p><img src="http://hacks.mozilla.org/wp-content/uploads/2011/01/rob.jpg" alt="Rob Hawkes" style="float:left;margin:5px"></a>Today we are featuring <a href="http://rawkes.com/">Rob Hawkes</a> author of <a href="http://rawkets.com/">Rawkets</a>, a multiplayer game using canvas and websockets. </p>
<p>Rob was one of the presenters at the Game On 2010 event in London, England where he showed off his game. The video and his slides are <a href="http://mozillalabs.com/gaming/2010/12/09/game_on-2010-150-gamer-geeks-pack-out-london/">available on the Mozilla Games Blog</a>. He is currently busy working on <a href="http://amzn.to/gzQMHp">a book about Canvas</a>. You can find Rob on Twitter as <a href="http://twitter.com/robhawkes">@robhawkes</a>. </p>
<p>The message I really loved getting from Rob was that it is OK to use any technology you want and that there is a benefit to people messing around with your code &#8211; even if it is to game the system.</p>
<h2 style="clear:both">The video interview</h2>
<p>You can <a href="http://vid.ly/0n4g0t">see the video on any HTML5 enabled device here</a> (courtesy of vid.ly).</p>
<p><video controls="true" height="295" width="480"><source src="http://vidly.s3.amazonaws.com/0n4g0t/mp4.mp4" type="video/mp4"><source src="http://vidly.s3.amazonaws.com/0n4g0t/mp4.mp4" type="video/webm"><source src="http://vidly.s3.amazonaws.com/0n4g0t/ogv.ogv" type="video/ogg">Your browser does not support the video tag, <a href="<a href="http://vid.ly/0n4g0t">Check the video on vid.ly</a>.</video></p>
<h2>Ten questions about HTML5 for Rob Hawkes</h2>
<h3>1) So, you&#8217;ve been fiddling around with Canvas for gaming a lot &#8211; why the fascination? Did you write games in other environments before?</h3>
<p>I sure have. My life has practically revolved around making games of some sort for the past year or two now. I just love the concept of using games to experiment with a programming languages and really learn everything I can about them. It’s a good way to try out most of the features involved in visual programming as well, particularly with harder concepts like physics, which I’m still no expert in. My fascination with games programming started out of necessity really; I had to create a game in my second year of university, so I co-created an <a href="https://github.com/robhawkes/sushi-roboto">augmented reality game</a> using Papervision3D and ActionScript. From there I co-created another game of sorts in Adobe Flex that allowed people to <a href="http://www.chromacam.co.uk/">play against each other using a webcam</a>, which was fun. And now I’m making games in canvas; partly because it’s fun, and partly to learn everything I can about it. I get a kick out of the interactivity and playability factor that games bring, which I think hooks into my addiction for visual programming in general.</p>
<h3>2) The cool thing about open technologies is that it is easy to see what is going on under the hood. View source and you get the picture. For gaming, isn&#8217;t that a problem? To &#8220;game&#8221; a highscore for a Flash game at least you need to do some HTTP sniffing &#8211; with Canvas it must be even easier. How do you protect yourself from that?</h3>
<p>The fact that canvas is so open is something that makes me interested in it. I’m usually pretty open about programming and I’d love it if people can learn from my code, so being able to view the source code directly within the browser is amazing for that. However, the major drawback is that your code is open for everyone to see, so security becomes a pretty big issue.</p>
<p>You’re right though, this is particularly troublesome with gaming, and I’m inclined to say that there isn’t much that you can do about it. In fact, is wasn’t long after I released the first version of <a href="http://rawkets.com/">Rawkets</a> that people started to poke around the code and manipulate the game to their advantage.</p>
<p>In all honesty, I actually see it as a good thing, as it showed me where my code was weak, and highlighted the areas that I needed to secure. You can obfuscate and minify your code as much as you want, but people can still get access to it because it’s just the way JavaScript works. However, there are a few ways to mitigate the problem, like passing core logic for the game to a remote server and communicating to it via restrictive and secure API calls. This is a good method for multiplayer games, where data received from the server is seen as trustworthy, and where as data on the client side is not. Or, you can wrap sensitive code in closures and take advantage of local variables to hide away data that you don’t want people to easily access. Another option is to just not worry about it. So long as you don’t let the hackers ruin the game for other players, does it really matter if they screw it up in their own browser?</p>
<p>In reality, none of these methods will 100% protect you, but they’ll certainly make things harder for would-be hackers.</p>
<h3>3) Talking about open. Isn&#8217;t Canvas just a Java applet with a predefined API and no need for a slow JVM? You still only have a rectangle somewhere in the page you can manipulate&#8230;</h3>
<p>If you mean that canvas is like a sandbox that you can only access via a specific set of API calls, then yes, pretty much. Then again, the API calls allow you to do a hell of a lot, and couldn’t you say the same about Flash and all the closed methods of creating graphics?</p>
<p>I suppose when you say canvas is open; you’re mainly talking about the development behind its creation (ie. the W3C), and the fact that the code to draw elements on it isn’t hidden away from prying eyes. Canvas is definitely not open in the sense that you are free to extend it and do whatever you want with it. So long as you abide by the API calls, which is fine for 99% of the time, then you’ve not got a problem.</p>
<p>As you say, canvas is effectively just a rectangular area that the browser allows you to draw into. Once you’ve drawn a few shapes into it, you can’t access them individually, but then again, that’s exactly how canvas is meant to work. It’s not like SVG, where every element that you’ve drawn can be accessed from the DOM and edited. Canvas is a bitmap system that has no concept of individual elements. It’s a destructive system that basically just changes the colour of pixels within its rectangle, based on the API calls that you give it. In that way, it’s just like Microsoft Paint from back in the day.</p>
<h3>4) What about accessibility? Can assistive technology access canvas content? How about keyboard access?</h3>
<p>To put it bluntly, not really. At least, not yet.</p>
<p>Canvas does have fallback content, which is placed between the canvas tags and shows up when a browser doesn’t support canvas, but it doesn’t have much else to aid with accessibility. The cool thing about the fallback content is that it’s possible to place content in there for keyboard access. I believe IE9 already has this functionality, which lets you show the canvas, but still give keyboard access so you can describe what’s going in within the canvas in text, or something like that. The problem with methods like this is that you effectively duplicate all of your content; you draw everything on the canvas, and then you have to write it all up within the canvas tags to explain what you’ve drawn.</p>
<p>What you can’t do yet is give assistive access to individual elements within the canvas, simply because canvas is just a big rectangle of pixels with no concept about what’s bee drawn. This is the major drawback with using a bitmap system that has a pretty closed API. There is talk about using something called the shadow DOM, to open up the canvas and allow some sort of access into the elements that have been drawn, but I don’t believe much has been done about this yet.</p>
<p>It’s definitely an area that I’m interested to see progress, but in the meantime, <a href="http://www.brucelawson.co.uk/2010/html5-video-canvas-accessibility-microdata/">Bruce Lawson highlights a couple of the proposals</a> that are floating around to sort out the accessibility issue with canvas.</p>
<h3>5) What about performance? What are the hot tips to keep a canvas game run smoothly?</h3>
<p>This is a massive sticking point with canvas at the moment; it can be so god damn slow! Actually, this isn’t really a problem with canvas, but rather the fact that canvas uses the browser process to draw everything, which in turn uses the processor (CPU).</p>
<p>Some browsers are introducing something called hardware acceleration, which passes off canvas and graphical processes to the graphics card (GPU). This simple feature really speeds things up, and allows you to do some pretty intensive stuff. Still, hardware acceleration isn’t a magic bullet; you still need to program defensively and be aware of potential bottlenecks and performance issues with your code.</p>
<p>The most common issues arise around unnecessarily extravagant timers and loops. For example, animating in canvas usually requires the use of a JavaScript timeout, which runs a function that draws everything onto the canvas 30 times a second; fast enough to look like things are moving. This is great, but what about if you’re not animating things any more? I’ve made the mistake of not turning off the animation timer, and inherently sucking precious CPU juice for no good reason.</p>
<p>Another example is that of collision detection, or any other check that has to be performed on a large amount of objects. The bad way of doing this is to loop through every object, and then loop through every object a second time on each iteration of the original loop. The problem with this is that you end up checking some objects twice, or more, and basically wasting resources. Instead, you can optimise your loops to ignore objects that you’ve already checked, which can cut the amount of loops down considerably.</p>
<p>There are countless ways to optimise your code, and most won’t achieve much on their own, but together they can add up to save a pretty significant amount of resources.</p>
<h3>6) Your game uses Web sockets for communication. How did you find that to work with? Does it scale well? Are there any things you don&#8217;t like about the technology?</h3>
<p>You mean that it used to use WebSockets? It’s a shame FireFox and others decided it would be a great idea to drop support for them for the time being. Jesting aside, the game is built atop WebSockets, and it’s been an interesting journey. I love WebSockets, and I think that having a full-duplex method of communicating within a browser is fantastic. The fact that the data is streamed live opens up a whole range of possibilities for games and Web apps.</p>
<p>I didn’t find too many issues with WebSockets regarding stability and scalability, as in reality most of the problems lay with the code on the server that deals with sending information back and forth. I found that one thing you need to be aware of is that the amount of data being sent back and forth can increase at an exponential rate if you’re not used to optimising communication for a large amount of users.</p>
<p>I have to admit though, my biggest bug bear with WebSockets is that it sends data as text, and it doesn’t support the UDP protocol. Right now, WebSockets sending everything as text data is great because it’s dead simple, but it sucks because it can potentially take a lot of precious bandwidth, especially when you’re sending data many times a second to hundreds of different players in a game.</p>
<p>The UDP problems relates to how canvas currently only supports the TCP protocol. What this means is that every piece of data that is sent back and forth between a server and a client has to be received in order. This is not good for gaming, where a bit of lag can end up causing a backlog of messages that have to be sent in order before any new messages can be sent. UDP on the other hand would allow you to send messages as and when they occur, without worrying about order. This is very good for games that rely on precise data that is time-sensitive, like the movement of a player in an FPS game.</p>
<p>You have to remember that WebSockets is something new, and it’s likely to have some teething troubles at the beginning; hence it being disabled temporarily. Still, it’s got a bright future, and I’m looking forward to seeing how it progresses.</p>
<h3>7) Have you played with SVG, too? If so, when would you use what and is there a chance to use the strong parts of both technologies together?</h3>
<p>Admittedly, I’ve not played with SVG as much as I’d like to. I’ve just become so caught up in the world of canvas in recent months. However, it’s something that I strongly believe should be used instead of canvas in particular circumstances, like when dealing with the conversion of existing HTML data into a graphical format (eg. creating graphs from a table).</p>
<p>SVG is also great because it’s accessible via the DOM, but it falls down with animation and gaming. It was never built with this kind of use in mind, and it’s exactly why canvas exists. Canvas is perfect for fast and dynamic animations, and it’s particularly perfect for creating games.</p>
<p>Fortunately, it isn’t always a case of being either or with SVG and canvas. It’s completely <a href="http://wiki.whatwg.org/wiki/SVG_and_canvas">possible to draw SVG shapes within canvas</a>, which has the added benefit of letting you have all the vector goodness of SVG within a bitmap system. I’ve heard of people using techniques like this for sprites within games, and for drawing images onto canvas that need to be resized a lot.</p>
<h3>8) What&#8217;s the next barrier you&#8217;d love to see opened up? What features of closed technology are there that are beyond your reach but you are itching to try out?</h3>
<p>I’m really interested in seeing the Device APIs (DAP) being supported in the major browsers. One of the things that is lacking in browsers at the moment is support for external devices like webcams and microphones. I can just see canvas and DAP being used together for some pretty awesome Web apps and visualisations. Imagine being able to create an avatar for a website by using a bit of canvas with an attached webcam. Or, what about live video chat through the browser with WebSockets and canvas/HTML5 video? That would be JavaScript awesomeness right there!</p>
<h3>9) Currently you&#8217;re writing a book on Canvas. As not everybody has time to wait for this, where could people go in the meantime to get the real info about starting with canvas?</h3>
<p>It’s not a massive wait (it’ll be out in May), but in the meantime I’d suggest going to the <a href="https://developer.mozilla.org/en/HTML/Canvas">Mozilla Developer Network</a>. It’s where I learnt how to use canvas, so it must be good! Apart from that, there really is a lack of decent resources for learning canvas at the moment, but I predict that changing for the better over the next year.</p>
<h3>10) Where could people go to get inspiration? What other uses of Canvas have you seen that made you go &#8220;woooo I want that!&#8221;?</h3>
<p>There are some fantastic projects being created with canvas at the moment. I could create a massive list, but here are some of my favourite:</p>
<ul>
<li><a href="https://gaming.mozillalabs.com/games/">Mozilla Game On</a></li>
<li><a href="http://playbiolab.com/">Biolab Disaster</a></li>
<li><a href="http://desandro.com/portfolio/">David Desandro’s portfolio</a></li>
<li><a href="http://www.monocubed.com/lab/">Paul Truong</a></li>
<li><a href="http://www.hakim.se/experiments/">Hakim El Hattab</a></li>
<li><a href="http://weavesilk.com/">Silk</a></ul>
<p>Some particularly impressive uses of canvas that have got my juices flowing are projects that really push the pixel manipulation features of canvas, like using it to <a href="https://github.com/liuliu/ccv/tree/current/js/">detect faces in images</a>, or <a href="http://www.patrick-wied.at/static/nudejs/">nudity</a>. Weird, but pretty impressive stuff!</p>
<p>Do you know anyone I should interview for &#8220;People of HTML5&#8243;? Tell me on Twitter: <a href="http://twitter.com/codepo8">@codepo8</a></p>
<p><script type="text/javascript" src="http://s3.www.universalsubtitles.org/js/mirosubs-widgetizer.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/01/people-of-html5-rob-hawkes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://vidly.s3.amazonaws.com/0n4g0t/mp4.mp4" length="151389176" type="video/mp4" />
<enclosure url="http://vidly.s3.amazonaws.com/0n4g0t/ogv.ogv" length="117648101" type="video/ogg" />
		</item>
		<item>
		<title>HTML5 Guitar Tab Player with the Firefox 4 Audio Data API</title>
		<link>http://hacks.mozilla.org/2011/01/html5guitar/</link>
		<comments>http://hacks.mozilla.org/2011/01/html5guitar/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 16:55:19 +0000</pubDate>
		<dc:creator>Paul Rouget</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Firefox 4]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=6978</guid>
		<description><![CDATA[Greg Jopa, an Illinois State University grad student studying web development, built a web-based guitar tab player using Firefox’s Audio Data API and Vexflow (HTML5 music notation rendering API). Here is some details from Greg. You can also read more about this experiment on his blog. I created a mashup using the Firefox 4 Audio [...]]]></description>
			<content:encoded><![CDATA[<p><em><a href="http://www.gregjopa.com">Greg Jopa</a>, an Illinois State University grad student studying web development, built a web-based guitar tab player using Firefox’s <a href="https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension">Audio Data API</a> and <a href="http://www.vexflow.com/">Vexflow (HTML5 music notation rendering API)</a>. Here is some details from Greg. You can also read more about this experiment <a href="http://www.gregjopa.com/2010/12/html5-guitar-tab-player-with-firefox-audio-data-api/">on his blog</a>.</em></p>
<p>I created a mashup using the Firefox 4 <a href="https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension">Audio Data API</a>, <a href="http://recordare.com/musicxml">MusicXML</a>, and <a href="http://vexflow.com">Vexflow</a> to create a HTML 5 Guitar Tab Player.</p>
<p><iframe width="500px" height="360px" src="http://www.youtube.com/embed/4MJeurIHf2I" frameborder="0"></iframe> </p>
<p><em>This is a Youtube video. It uses the HTML5 &lt;video&gt; tag if you <a href="http://www.youtube.com/html5">activate it here</a>.</em></p>
<ul>
<li><a href="http://code.gregjopa.com/html5/audio/tabplayer/">View demo</a>.</p>
<li><a href="https://github.com/GregJ/HTML5-Guitar-Tab-Player">Source code</a>.</p>
</ul>
<p>Using JavaScript, this guitar tab player converts the music note data from a <a href="http://recordare.com/musicxml">MusicXML</a> file to frequencies playable by the Audio Data API. This note data is also converted to a format that can be read by Vexflow to display the guitar tab.</p>
<p>I have broken down this functionality into 4 steps. Here’s how the HTML5 Guitar Tab Player works: </p>
<h2>MusicXML</h2>
<p>When a tab (a <a href="http://en.wikipedia.org/wiki/Tablature">tablature</a>) is selected, the jQuery ajax() function loads the MusicXML file, parses through the contents, and appends all the formatted note data to a &lt;script> tag. The format for each note is: <code>playNote(note, octave, duration)</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">playNote<span style="color: #009900;">&#40;</span>notes.<span style="color: #660066;">C</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The tablature notation information in the MusicXML file is also processed and appended to a &lt;div> tag for Vexflow. </p>
<p>Here is the structure of the nodes I am using from the MusicXML file:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;measure</span> <span style="color: #000066;">number</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attributes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;divisions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1024<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/divisions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attributes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;note<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pitch<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;step<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>C<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/step<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;octave<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/octave<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pitch<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;duration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1024<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/duration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;notations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;technical<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fret<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fret<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/technical<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/notations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/note<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    the note node repeats for the rest of the notes in the measure…
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/measure<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And here is the generated source that is produced by the ajax() function.</p>
<p>For the audio:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;audio&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	function loadAudio(){
	  playNote(notes.C, 4, 1);
	  playNote(notes.C, 4, 1);
	  playNote(notes.G, 4, 1);
	  playNote(notes.G, 4, 1);
	  …
	}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>For the tab:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;tab&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;vex-tabdiv&quot;</span> <span style="color: #000066;">width</span>=780 <span style="color: #000066;">scale</span>=1.0 <span style="color: #000066;">editor</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
tabstave notation=true
	notes :q 1/2 :q 1/2 :q 3/1 :q 3/1 | :q 5/1
   …
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>Frequency Calculation</h2>
<p>When the Play button is clicked the music data <code>&lt;script id=”audio”></code> tag is evaluated and the note information is converted to frequencies using the following formula (assumes equal temperament):</p>
<p><code>frequency = 440 * 2^(n/12)</code></p>
<p>440 is the frequency for the note A at the 4th octave.</p>
<p><code>n = distance away from A4 (440)</code></p>
<p>I am using an array to store the distance between a certain note and the base note “A”</p>
<p><code>notes = {C:-9, Cs:-8, D:-7, Ds:-6, E:-5, F:-4, Fs:-3, G:-2, Gs:-1, A:0, As:1, B:2};</code></p>
<p>And to incorporate that a note can be played at different octaves I have adapted the above formula to the following:</p>
<p><code>frequency = 440 * 2^((octave-4) * 12 + distance)/12);</code></p>
<h2>Audiodata.js</h2>
<p>I am using the Audiodata.js library in the guitar tab player which makes it easy to play continuous audio using a single array. This library encapsulates the Audio Data API methods. Audiodata.js is available on GitHub here: <a href="https://github.com/notmasteryet/audiodata">https://github.com/notmasteryet/audiodata</a>. The Audiodata.js project contains a score example with “Twinkle, Twinkle, Little Star” which inspired me to build this guitar tab player.</p>
<h2>Vexflow and the Animated Cursor</h2>
<p>Vexflow is an open-source web-based music notation rendering API based on the HTML5 canvas element (<a href="http://www.vexflow.com/">http://www.vexflow.com/</a>). I am using Vexflow to display the tab for each MusicXML file. I have added an additional canvas element on top of the Vexflow canvas to control the red cursor that links the audio to the tablature. The speed of the audio is controlled by the tempo which is measured in beats per minute. By converting this tempo to milliseconds I am able to use it for the redraw speed of the second canvas. Every time this canvas is redrawn the red cursor is moved 5 pixels to the right to highlight which note is currently being played.<br />
Keep in mind that this HTML5 Guitar Tab Player is just a proof of concept and can only play single notes.</p>
<p><strong>If you have recommendations on how to make this tab player better or would like to contribute to this project check out the following post:</strong> <a href="http://www.gregjopa.com/2010/12/html5-guitar-tab-player-with-firefox-audio-data-api/ ">http://www.gregjopa.com/2010/12/html5-guitar-tab-player-with-firefox-audio-data-api/ </a></p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/01/html5guitar/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How to develop a HTML5 Image Uploader</title>
		<link>http://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/</link>
		<comments>http://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 10:40:16 +0000</pubDate>
		<dc:creator>Paul Rouget</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Drag and Drop]]></category>
		<category><![CDATA[FileAPI]]></category>
		<category><![CDATA[Firefox 4]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=6846</guid>
		<description><![CDATA[HTML5 comes with a set of really awesome APIs. If you combine these APIs with the &#60;canvas&#62; element, you could create a super/modern/awesome Image Uploader. This article shows you how. All these tips work well in Firefox 4. I also describe some alternative ways to make sure it works on Webkit-based browsers. Most of these [...]]]></description>
			<content:encoded><![CDATA[<p><em>HTML5 comes with a set of really awesome APIs. If you combine these APIs with the &lt;canvas&gt; element, you could create a super/modern/awesome Image Uploader. This article shows you how.</em></p>
<p><em>All these tips work well in Firefox 4. I also describe some alternative ways to make sure it works on Webkit-based browsers. Most of these APIs don&#8217;t work in IE, but it&#8217;s quite easy to use a normal form as a fallback.</em></p>
<p><em>Please let us know if you use one of these technologies in your project!</em></p>
<h1>Retrieve the images</h1>
<h2>Drag and drop</h2>
<p>To upload files, you&#8217;ll need an <a href="https://developer.mozilla.org/en/HTML/element/input#attr-type">&lt;input type=&#8221;file&#8221;&gt;</a> element. But you should also allow the user to drag and drop images from the desktop directly to your web page.</p>
<p>I&#8217;ve written a detailed article about <a href="http://hacks.mozilla.org/2009/12/file-drag-and-drop-in-firefox-3-6/">implementing drag-and-drop support for your web pages</a>.</p>
<p>Also, take a look at the <a href="https://developer.mozilla.org/en/Using_files_from_web_applications#Selecting_files_using_drag_and_drop">Mozilla tutorial on drag-and-drop</a>.</p>
<h2>Multiple input</h2>
<p>Allow the user the select several files to upload at the same time from the File Picker:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;file&quot;</span> multiple<span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>Again, here is an article I&#8217;ve written about <a href="http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/">multiple file selection</a>.</p>
<h1>Pre-process the files</h1>
<h2>Use the File API</h2>
<p>(See the <a href="https://developer.mozilla.org/en/using_files_from_web_applications">File API documentation</a> for details.)</p>
<p>From drag-and-drop or from the <a href="https://developer.mozilla.org/en/HTML/element/input">&lt;input&gt;</a> element, you have a list a files ready to be used:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// from an input element</span>
<span style="color: #003366; font-weight: bold;">var</span> filesToUpload <span style="color: #339933;">=</span> input.<span style="color: #660066;">files</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// from drag-and-drop</span>
<span style="color: #003366; font-weight: bold;">function</span> onDrop<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  filesToUpload <span style="color: #339933;">=</span> e.<span style="color: #660066;">dataTransfer</span>.<span style="color: #660066;">files</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Make sure these files are actually images:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>file.<span style="color: #660066;">type</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/image.*/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// this file is not an image.</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Show a thumbnail/preview</h2>
<p>There are two options here. You can either use a <a href="https://developer.mozilla.org/en/DOM/FileReader">FileReader</a> (from the File API) or use the new <a href="https://developer.mozilla.org/en/DOM/window.URL.createObjectURL"><code>createObjectURL()</code></a> method.</p>
<h3>createObjectURL()</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> window.<span style="color: #660066;">URL</span>.<span style="color: #660066;">createObjectURL</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>FileReader</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> reader <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> FileReader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
reader.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> e.<span style="color: #660066;">target</span>.<span style="color: #660066;">result</span><span style="color: #009900;">&#125;</span>
reader.<span style="color: #660066;">readAsDataURL</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Use a canvas</h2>
<p>Once you have the image preview in an <a href="https://developer.mozilla.org/en/HTML/element/img">&lt;img&gt;</a> element, you can draw this image in a <a href="https://developer.mozilla.org/en/HTML/element/canvas">&lt;canvas&gt;</a> element to pre-process the file.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> ctx <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span>img<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Resize the image</h2>
<p>People are used to uploading images straight from their camera. This gives high resolution and extremely heavy (several megabyte) files. Depending on the usage, you may want to resize such images. A super easy trick is to simply have a small canvas (800&#215;600 for example) and to draw the image tag into this canvas. Of course, you&#8217;ll have to update the canvas dimensions to keep the ratio of the image.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> MAX_WIDTH <span style="color: #339933;">=</span> <span style="color: #CC0000;">800</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> MAX_HEIGHT <span style="color: #339933;">=</span> <span style="color: #CC0000;">600</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> width <span style="color: #339933;">=</span> img.<span style="color: #660066;">width</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> height <span style="color: #339933;">=</span> img.<span style="color: #660066;">height</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>width <span style="color: #339933;">&gt;</span> height<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>width <span style="color: #339933;">&gt;</span> MAX_WIDTH<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    height <span style="color: #339933;">*=</span> MAX_WIDTH <span style="color: #339933;">/</span> width<span style="color: #339933;">;</span>
    width <span style="color: #339933;">=</span> MAX_WIDTH<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>height <span style="color: #339933;">&gt;</span> MAX_HEIGHT<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    width <span style="color: #339933;">*=</span> MAX_HEIGHT <span style="color: #339933;">/</span> height<span style="color: #339933;">;</span>
    height <span style="color: #339933;">=</span> MAX_HEIGHT<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
canvas.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> width<span style="color: #339933;">;</span>
canvas.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> height<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> ctx <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ctx.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span>img<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> width<span style="color: #339933;">,</span> height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Edit the image</h2>
<p>Now, you have your image in a canvas. Basically, the possibilities are infinite. Let&#8217;s say you want to apply a sepia filter:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> imgData <span style="color: #339933;">=</span> ctx.<span style="color: #660066;">createImageData</span><span style="color: #009900;">&#40;</span>width<span style="color: #339933;">,</span> height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> imgData.<span style="color: #660066;">data</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> pixels <span style="color: #339933;">=</span> ctx.<span style="color: #660066;">getImageData</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> width<span style="color: #339933;">,</span> height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> ii <span style="color: #339933;">=</span> pixels.<span style="color: #660066;">data</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> ii<span style="color: #339933;">;</span> i <span style="color: #339933;">+=</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> pixels.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> g <span style="color: #339933;">=</span>pixels.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> b <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pixels</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    data<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>r <span style="color: #339933;">*</span> .393<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>g <span style="color: #339933;">*</span>.769<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>b <span style="color: #339933;">*</span> .189<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    data<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>r <span style="color: #339933;">*</span> .349<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>g <span style="color: #339933;">*</span>.686<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>b <span style="color: #339933;">*</span> .168<span style="color: #009900;">&#41;</span>
    data<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>r <span style="color: #339933;">*</span> .272<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>g <span style="color: #339933;">*</span>.534<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>b <span style="color: #339933;">*</span> .131<span style="color: #009900;">&#41;</span>
    data<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">255</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
ctx.<span style="color: #660066;">putImageData</span><span style="color: #009900;">&#40;</span>imgData<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>Upload with XMLHttpRequest</h1>
<p>Now that you have loaded the images on the client, eventually you want to send them to the server.</p>
<h2>How to send a canvas</h2>
<p>Again, you have two options. You can <a href="https://developer.mozilla.org/en/DOM/HTMLCanvasElement">convert the canvas to a data URL</a> or (in Firefox) <a href="https://developer.mozilla.org/en/Code_snippets/Canvas#Saving_a_canvas_image_to_a_file">create a file from the canvas</a>.</p>
<h3>canvas.toDataURL()</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> dataurl <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">toDataURL</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Create a file from the canvas</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> file <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">mozGetAsFile</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;foo.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Atomic upload</h2>
<p>Allow the user to upload just one file or all the files at the same time.</p>
<h2>Show progress of the upload</h2>
<p>Use the upload events to create a progress bar:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">xhr.<span style="color: #660066;">upload</span>.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;progress&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">lengthComputable</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> percentage <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">loaded</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> e.<span style="color: #660066;">total</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Use FormData</h2>
<p>You probably don&#8217;t want to just upload the file (which could be easily done via: <code>xhr.send(file)</code>) but add side information (like a key and a name).</p>
<p>In that case, you&#8217;ll need to create a <code>multipart/form-data</code> request via a <a href="https://developer.mozilla.org/en/XMLHttpRequest/FormData"><code>FormData</code></a> object. (See <a href="http://hacks.mozilla.org/2010/05/formdata-interface-coming-to-firefox/">Firefox 4: easier JS form handling with FormData</a>.)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> fd <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> FormData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fd.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;paul&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fd.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;image&quot;</span><span style="color: #339933;">,</span> canvas.<span style="color: #660066;">mozGetAsFile</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;foo.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fd.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;key&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;××××××××××××&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> xhr <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
xhr.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;http://your.api.com/upload.json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
xhr.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>fd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>Open your API</h1>
<p>Maybe you want to allow other websites to use your service.</p>
<h2>Allow cross-domain requests</h2>
<p>By default, your API is only reachable from a request created from your own domain. If you want to allow people use your API, allow Cross-XHR in your HTTP header:</p>
<pre>
Access-Control-Allow-Origin: *
</pre>
<p>You can also allow just a pre-defined list of domains.</p>
<p>Read about <a href="http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/">Cross-Origin Resource Sharing</a>.</p>
<h2>postMessage</h2>
<p>(Thanks to <a href="http://twitter.com/dsg">Daniel Goodwin</a> for this tip.)</p>
<p>Also, listen to messages sent from <a href="https://developer.mozilla.org/en/DOM/window.postMessage"><code>postMessage</code></a>. You could allow people to use your API through postMessage:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;message&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// retrieve parameters from e.data</span>
    <span style="color: #003366; font-weight: bold;">var</span> key <span style="color: #339933;">=</span> e.<span style="color: #660066;">data</span>.<span style="color: #660066;">key</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> e.<span style="color: #660066;">data</span>.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> dataurl <span style="color: #339933;">=</span> e.<span style="color: #660066;">data</span>.<span style="color: #660066;">dataurl</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// Upload</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">// Once the upload is done, you can send a postMessage to the original window, with URL</span></pre></div></div>

<p><em>That&#8217;s all. If you have any other tips to share, feel free to drop a comment.</em></p>
<p><strong>Enjoy ;)</strong></p>
<style>
.post h1 {
  font-size: 27px;
  margin-bottom: 7px;
  font-style: italic;
}
.post h2 {
  margin-bottom: 10px;
}
</style>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Real-time server visualization with canvas and processing.js</title>
		<link>http://hacks.mozilla.org/2010/04/real-time-server-visualization-with-canvas-and-processing-js/</link>
		<comments>http://hacks.mozilla.org/2010/04/real-time-server-visualization-with-canvas-and-processing-js/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 19:34:28 +0000</pubDate>
		<dc:creator>Jay Patel</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Featured Demo]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=4399</guid>
		<description><![CDATA[This is a guest blog post by Logan Welliver, Chief Creative at Cloudkick. He is a graphic designer by training and a web designer in practice. Cloud management company Cloudkick has released a real-time server monitoring visualization based on canvas and processing.js, that was co-developed with Alastair McDonald of processing.js fame. The product is designed [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.cloudkick.com/viz/mozilla/"><img src="http://hacks.mozilla.org/wp-content/uploads/2010/04/cloudkick_20100420-250x142.png" alt="" title="cloudkick_20100420" width="250" height="142" class="alignright size-medium wp-image-4403" /></a><em>This is a guest blog post by <a href="https://www.cloudkick.com/about">Logan Welliver, Chief Creative at Cloudkick</a>.  He is a graphic designer by training and a web designer in practice.</em></p>
<p>Cloud management company Cloudkick has released a <a href="https://www.cloudkick.com/viz/mozilla">real-time server monitoring visualization</a> based on canvas and processing.js, that was co-developed with <a href="http://alistairgmacdonald.com/">Alastair McDonald</a> of processing.js fame. The product is designed to let users keep a finger on the pulse of their infrastructure, quickly identify problem nodes, and visualize aggregate performance with an easy-to-digest interface.</p>
<p>The tool uses canvas and processing.js to plot servers as stylized circles in 3 dimensions, with axes mapped to one of three performance metrics: CPU usage, memory usage, and ping latency. Each server&#8217;s radius is determined by it&#8217;s relative prowess (i.e. an EC2 extra large is bigger than 256mb Slice), and colors are customizable via the Cloudkick dashboard. Each server sparkles when the monitoring system returns data, and servers with problems identify themselves by flashing an angry red.</p>
<p>Canvas and processing.js take care of all the presentation, powered by a slew of back-end services that do everything from monitoring servers to pushing data in real-time back to the user.</p>
<p>Here&#8217;s a brief overview of the back-end architecture: instances of the <a href="https://support.cloudkick.com/Main_Page#Cloudkick_Agent">Cloudkick Agent</a> (running on individual servers) report metrics to an endpoint, which talks to <a href="https://labs.omniti.com/trac/reconnoiter">Reconnoiter</a>, which then publishes messages to RabbitMQ. An internal service called Livedata consumes these messages, finds the ones applicable to an account, and publishes messages back to <a href="http://www.rabbitmq.com/">RabbitMQ</a>. <a href="http://orbited.org/">Orbited</a> consumes these messages and sends them to the browser. From agent to browser, the round-trip time is less than a second.</p>
<p>Cloudkick has partnered with Mozilla to provide the visualization for their <a href="http://addons.mozilla.org/">addons.mozilla.org</a> servers. You can see how they&#8217;re behaving in a live demo of the visualization here: <a href="https://www.cloudkick.com/viz/mozilla/">addons.mozilla.org infrastructure in Cloudkick Viz.</a> </p>
<p>Get the visualization for your own servers. Cloudkick is offering <a href="https://www.cloudkick.com/pricing/mozhacks01">20% off for the first 100 Mozilla Hacks readers, using promo code &#8220;mozhacks01&#8243;.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2010/04/real-time-server-visualization-with-canvas-and-processing-js/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>making waves with HTML5</title>
		<link>http://hacks.mozilla.org/2009/10/making-waves-with-html5/</link>
		<comments>http://hacks.mozilla.org/2009/10/making-waves-with-html5/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 03:31:31 +0000</pubDate>
		<dc:creator>Gen Kanai</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Featured Demo]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=1917</guid>
		<description><![CDATA[Thomas Saunders of modern-carpentry has a very nice HTML5 demo, making waves with html5, showcasing the power of Canvas as well as Processing.js. modern carpentry rides the html5 canvas wave Thomas says: I was challenged at work to create something that &#8220;floats naturally&#8221;. After a while of confusion in my pursuit of &#8220;natural floating&#8221; or [...]]]></description>
			<content:encoded><![CDATA[<p>Thomas Saunders of <a href="http://modern-carpentry.com/">modern-carpentry</a> has a very nice HTML5 demo, <a href="http://modern-carpentry.com/workshop/html5/waveform/">making waves with html5</a>, showcasing the power of <a href="https://developer.mozilla.org/en/HTML/Canvas">Canvas</a> as well as <a href="http://processingjs.org/">Processing.js</a>.</p>
<p style="text-align: center;"><strong><a href="http://modern-carpentry.com/workshop/html5/waveform/">modern carpentry rides the html5 canvas wave</a></strong></p>
<p>Thomas says:</p>
<blockquote><p><em>I was challenged at work to create something that &#8220;floats naturally&#8221;.  After a while of confusion in my pursuit of &#8220;natural floating&#8221; or whatever,  I came up with the idea that I needed a tool to investigate my confusion.   This project is a result of my trying to build that tool.</em></p>
<p><em>It was initially built as a Flash/Flex application, which you can see <a href="http://modern-carpentry.com/workshop/waveform/">here</a>.   Later on, however, I became interested in HTML5 and the Canvas tag and decided to port the application to JavaScript and HTML (with the help of jQuery, and also Processing.js, of course&#8230;).  The transition went fairly well, and I ended up with a JS/HTML version of the application that I actually think is cooler than the original Flash version.</em></p>
<p><em>In the end, I came up with both something that &#8220;floats naturally&#8221;  and also  a serendipitous encounter with the simplicity of working with only HTML and JavaScript, which has been very rewarding.</em></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2009/10/making-waves-with-html5/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>9elements &#8211; HTML5 Canvas Experiment</title>
		<link>http://hacks.mozilla.org/2009/08/9elements-html5-canvas-experiment/</link>
		<comments>http://hacks.mozilla.org/2009/08/9elements-html5-canvas-experiment/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 08:31:17 +0000</pubDate>
		<dc:creator>Gen Kanai</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=1541</guid>
		<description><![CDATA[The developers over at 9elements have done a mesmerizing experiment with Canvas and the audio support in HTML5. HTML5 Canvas and Audio Experiment Please comment on their cool experiment at their blog: HTML5 Canvas Experiment.]]></description>
			<content:encoded><![CDATA[<p>The developers over at <a href="http://9elements.com/en.html">9elements</a> have done a mesmerizing experiment with Canvas and the audio support in HTML5.</p>
<p style="text-align: center;"><strong><a href="http://9elements.com/io/projects/html5/canvas/">HTML5 Canvas and Audio Experiment</a></strong></p>
<p>Please comment on their cool experiment at their blog: <a href="http://9elements.com/io/?p=153">HTML5 Canvas Experiment</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2009/08/9elements-html5-canvas-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

