<?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>nooshu &#187; Experiments Archives </title>
	<atom:link href="http://nooshu.com/category/experiments/feed" rel="self" type="application/rss+xml" />
	<link>http://nooshu.com</link>
	<description>Kneeling on the shoulders of giants</description>
	<lastBuildDate>Fri, 20 Jan 2012 11:38:04 +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>Plotting the Lorenz Attractor using three.js</title>
		<link>http://nooshu.com/plotting-the-lorenz-attractor-using-three-js?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=plotting-the-lorenz-attractor-using-three-js</link>
		<comments>http://nooshu.com/plotting-the-lorenz-attractor-using-three-js#comments</comments>
		<pubDate>Thu, 15 Dec 2011 14:53:24 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Three.js]]></category>
		<category><![CDATA[chaos]]></category>
		<category><![CDATA[lorenz]]></category>
		<category><![CDATA[plot]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=2058</guid>
		<description><![CDATA[The Lorenz equations are a cornerstone in Chaos theory. The "butterfly effect" is how it is known in popular culture. I little experiment plotting the Lorenz Attractor using three.js.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I dabbled with <a href="https://github.com/mrdoob/three.js">three.js</a>. There have been a few API changes, so it&#8217;s slightly different from what I remember. That being said it&#8217;s still as fun to use, and there are even a few <a href="http://threejs.org/io/s/">API docs</a> available (not sure if they are fully up to date though)! I happened to be reading an article on Chaos Theory and the &#8220;butterfly effect&#8221; which mentioned a lovely set of equations; the <a href="http://en.wikipedia.org/wiki/Lorenz_attractor#Equations">Lorenz Equations</a>, also known as the Lorenz oscillator. So I decided to investigate further. Here they are in all their glory:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cbegin%7Baligned%7D%5Cdot%7Bx%7D+%26+%3D+%5Csigma%28y-x%29+%5C%5C+%5Cdot%7By%7D+%26+%3D+%5Crho+x+-+y+-+xz+%5C%5C+%5Cdot%7Bz%7D+%26+%3D+-%5Cbeta+z+%2B+xy+%5Cend%7Baligned%7D&#038;bg=D7DBCD&#038;fg=000&#038;s=1' alt='&#92;begin{aligned}&#92;dot{x} &amp; = &#92;sigma(y-x) &#92;&#92; &#92;dot{y} &amp; = &#92;rho x - y - xz &#92;&#92; &#92;dot{z} &amp; = -&#92;beta z + xy &#92;end{aligned}' title='&#92;begin{aligned}&#92;dot{x} &amp; = &#92;sigma(y-x) &#92;&#92; &#92;dot{y} &amp; = &#92;rho x - y - xz &#92;&#92; &#92;dot{z} &amp; = -&#92;beta z + xy &#92;end{aligned}' class='latex' /></p>
<p>So what exactly is the Lorenz oscillator? Well to quote from Wikipedia &#8220;The Lorenz oscillator is a 3-dimensional dynamical system that exhibits chaotic flow, noted for its figure eight shape.&#8221;. What this really boils down to is how even very small change in the equations initial conditions (x, y and z) causes large changes over time, in a complex and non-repeating pattern. There&#8217;s a famous title of a talk given in 1972 by Philip Merilees:</p>
<blockquote><p>Does the flap of a butterfly’s wings in Brazil set off a tornado in Texas?</p></blockquote>
<p>The butterfly flapping its wings introduces slight changes to the initial conditions, creating a chain of events that lead to a tornado in Texas. The Lorenz butterfly is a graphical way of showing these changes over time on a much smaller scale.</p>
<p>I&#8217;ve <a href="http://dl.dropbox.com/u/7851949/lorenz-attractor/index.html">created a demo</a> that allows you to change variables related to the Lorenz butterfly and observe the effect it has on the system.</p>
<div id="attachment_2075" class="wp-caption alignnone" style="width: 528px"><a href="http://dl.dropbox.com/u/7851949/lorenz-attractor/index.html"><img src="http://nooshu.com/wp-content/uploads/2011/12/lorenz-examples.jpg" alt="Example of my Lorenz attractor demo in action" title="lorenz-examples" width="518" height="501" class="size-full wp-image-2075" /></a><p class="wp-caption-text">Adjust the demo variables to see how the Lorenz butterfly changes.</p></div>
<p>There are a few variables you can play to change how the Lorenz attractor is rendered:</p>
<ul>
<li><strong>rhoValue</strong>: Called the Rayleigh number. Rho of value 28 shows chaotic behavior. Other values show periodic orbits.</li>
<li><strong>showAxis</strong>: Allows you to turn the x, y, z (red, green, blue) axis on for reference.</li>
<li><strong>randomStart</strong>: Picks a random initial conditions, rather than 0, 0, 0.</li>
<li><strong>totalTime</strong>: The total time (or number of iterations performed) when generating the graph. Higher numbers equals more lines and increases the render time.</li>
<li><strong>timeIncriment</strong>: The accuracy of the graph depends on the number of points plotted. A lower number creates a smoother graph but increases render time.</li>
<li><strong>colorModifier</strong>: Simply changes the colo(u)r. Pointless but pretty!</li>
</ul>
<p>While rendering a larger number of points, I noticed the browser lock-up for a second or so. This was because the points were being calculated on the browsers UI thread. Luckily modern browsers support thread like message passing in the form of the <a href="http://www.html5rocks.com/en/tutorials/workers/basics/">Web Workers API</a>. By offloading the point calculation to its own thread (<a href="http://dl.dropbox.com/u/7851949/lorenz-attractor/js/lorenzPoints.js">lorenzPoints.js</a>), I was able to stop the nasty UI freeze. Unfortunately you are fairly limited with what you can pass back and forth between workers. It was possible to generate the three.js geometry in the worker thread thanks to the importScripts() method. I tried passing the three.js geometry back to the browser but all the methods were stripped out, leading to lots of errors (JSON issues). In the end I dropped back to calculating the points in the worker, pushing them into an array and generating the geometry on the main browser thread. </p>
<p>It was good fun dabbling with three.js, Web Workers and dat.gui again. Now on to my next project&#8230; View the demo <a href="http://dl.dropbox.com/u/7851949/lorenz-attractor/index.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/plotting-the-lorenz-attractor-using-three-js/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dat.gui &#8211; controller library for JavaScript</title>
		<link>http://nooshu.com/dat-gui-controller-library-for-javascript?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dat-gui-controller-library-for-javascript</link>
		<comments>http://nooshu.com/dat-gui-controller-library-for-javascript#comments</comments>
		<pubDate>Wed, 16 Nov 2011 02:14:45 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Interesting]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Vanilla JavaScript]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[euler]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1933</guid>
		<description><![CDATA[Building a demo in JavaScript? Then you really need to start using the dat.gui library. It takes the hassle out of controlling your variables. ]]></description>
			<content:encoded><![CDATA[<p>Very recently I&#8217;ve been looking at some awesome JavaScript experiments and have noticed they are all using the same GUI. Now I fully admit I had a little &#8216;blonde&#8217; moment as I assumed it was just a style everyone had adopted; developers being &#8216;one of the cool kids&#8217;, that type of thing. It turns out I was wrong, and it finally clicked. All the experiments have started using a little controller library called <a href="http://code.google.com/p/dat-gui/">dat.gui</a>.</p>
<p>After it appeared on <a href="http://workshop.chromeexperiments.com/">Google&#8217;s workshop</a> (along with three.js), I thought it was about time I had a play with this neat little library. Luckily there&#8217;s an excellent set of documentation and <a href="http://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage">working examples</a> available so you can dive right in. Here&#8217;s a code example of how to get started:</p>
<div class="codecolorer-container javascript default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">//Define the controller function</span><br />
<span style="color: #003366; font-weight: bold;">var</span> FresnelControls <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><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">movingParticles</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">5000</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">seedColor</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#ff0098&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Create the Dat.gui controls</span><br />
<span style="color: #003366; font-weight: bold;">var</span> fc <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> FresnelControls<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Create the GUI</span><br />
<span style="color: #003366; font-weight: bold;">var</span> gui <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> dat.<span style="color: #660066;">GUI</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Add 2 folders</span><br />
<span style="color: #003366; font-weight: bold;">var</span> f1 <span style="color: #339933;">=</span> gui.<span style="color: #660066;">addFolder</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Particle Dynamics'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> f2 <span style="color: #339933;">=</span> gui.<span style="color: #660066;">addFolder</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Particle Colours'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #006600; font-style: italic;">//Add the moving particles controller to folder 1</span><br />
f1.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>fc<span style="color: #339933;">,</span> <span style="color: #3366CC;">'movingParticles'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5000</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">step</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Add the colour controller, store in a var to attach events</span><br />
<span style="color: #003366; font-weight: bold;">var</span> seedColor <span style="color: #339933;">=</span> f2.<span style="color: #660066;">addColor</span><span style="color: #009900;">&#40;</span>fc<span style="color: #339933;">,</span> <span style="color: #3366CC;">'seedColor'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Colour change event</span><br />
seedColor.<span style="color: #660066;">onChange</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Do something on color change...</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>I decided to dig out an <a href="http://nooshu.com/animating-the-euler-spiral">old demo</a> I created last year and adapt it to use dat.gui. Originally I used jQuery + jQuery UI to control the JavaScript variables. It worked well, but it really added page weight (jQuery + UI came to over 90Kb); not great when you are only using it for the sliders. </p>
<p>Following the documentation you start off simple and progressively add more of the dat.gui functionality. You can see my adapted demo <a href="http://dl.dropbox.com/u/7851949/euler-dat/index.html">here</a>. The dat.gui code is highlighted if you want to see how it was set up.</p>
<div id="attachment_1936" class="wp-caption alignnone" style="width: 528px"><a href="http://dl.dropbox.com/u/7851949/euler-dat/index.html"><img src="http://nooshu.com/wp-content/uploads/2011/11/datgui-518x205.jpg" alt="Dat.gui in action on the Euler Spiral demo I created." title="datgui" width="518" height="205" class="size-medium wp-image-1936" /></a><p class="wp-caption-text">You can see dat.gui in action on my modified Euler Spiral demo.</p></div>
<p>Dat.gui really has some excellent features available. I was able to make use of the colour picker, presets and folder functionality; but there&#8217;s a whole host of others I didn&#8217;t, such as the <a href="http://workshop.chromeexperiments.com/examples/gui/#8--Custom-Placement">custom placement</a> and <a href="http://workshop.chromeexperiments.com/examples/gui/#9--Updating-the-Display-Automatically">updating the display automatically</a>. Personally I love the presets functionality; supply the GUI with a little bit of JSON and away you go!</p>
<p>As always, a big thank you goes out to the Data Arts Team in Google’s Creative Lab for creating such a useful little library! One I will be using in every demo I create from now on.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/dat-gui-controller-library-for-javascript/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fun with Space Invaders and Parallax scrolling</title>
		<link>http://nooshu.com/fun-with-space-invaders-and-parallax-scrolling?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fun-with-space-invaders-and-parallax-scrolling</link>
		<comments>http://nooshu.com/fun-with-space-invaders-and-parallax-scrolling#comments</comments>
		<pubDate>Wed, 25 May 2011 23:25:47 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[aliens]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1723</guid>
		<description><![CDATA[Loving the HTML5 Canvas element. Having fun with the parallax effect and a few aliens.]]></description>
			<content:encoded><![CDATA[<p>Back when I was a young wippersnapper (many moons ago) one of my good friends had a <a href="http://en.wikipedia.org/wiki/Mega_Drive">Sega Mega Drive</a>. As with any new console it was on every kids Christmas list but compared to the current generation of games consoles it looks very primitive. The games were immense fun and you didn&#8217;t need an instruction manual to play them. Two of my favourite games were <a href="http://en.wikipedia.org/wiki/Golden_Axe">Golden Axe</a> and <a href="http://en.wikipedia.org/wiki/Sonic_the_Hedgehog_(video_game)">Sonic the Hedgehog</a>. Sonic the Hedgehog used a technique called <a href="http://en.wikipedia.org/wiki/Parallax_scrolling">Parallax scrolling</a>; this is where background images move slower than &#8220;closer&#8221; foreground images giving the illusion of depth in a 2D plane.</p>
<p>I&#8217;m quite late to the web parallax party as the effect was recreated and popularised back in 2008. I first remember seeing it being used by the holding page for Clearleft&#8217;s <a href="http://silverbackapp.com/">Silverback application</a>, but it may have appeared elsewhere before that. Three years on the web is a long time and technology has moved on, so I set myself a little project to recreate the effect using the HTML5 canvas element.</p>
<div id="attachment_1724" class="wp-caption alignnone" style="width: 528px"><a href="http://dl.dropbox.com/u/7851949/space-invaders/index.html"><img src="http://nooshu.com/wp-content/uploads/2011/05/space-invader-parallax.gif" alt="Parallax scrolling using a Space Invaders alien" title="space-invader-parallax" width="518" height="357" class="size-full wp-image-1724" /></a><p class="wp-caption-text">Move your mouse to see the Parallax scrolling effect.</p></div>
<p>To demonstrate the effect I used a few graphics from another iconic retro game: <a href="http://en.wikipedia.org/wiki/Space_Invaders">Space Invaders</a>. As you move the mouse the scary alien separates into its constituent pixels. The foreground pixels move faster than the background pixels creating a slight parallax effect. You have three aliens to choose from: Dave, Julian and Brian, which I&#8217;ve named for no particular reason. I think the names quite suit them. I&#8217;ve also added a little randomness to the demo in how they are generated, which you can see by reloading the page.</p>
<p>Hooray for retro games and <a href="http://dl.dropbox.com/u/7851949/space-invaders/index.html">pointless demo&#8217;s</a>! :) </p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/fun-with-space-invaders-and-parallax-scrolling/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Antimatter 3D Graph Plotter and a little animation</title>
		<link>http://nooshu.com/antimatter-3d-graph-plotter-and-a-little-animation?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=antimatter-3d-graph-plotter-and-a-little-animation</link>
		<comments>http://nooshu.com/antimatter-3d-graph-plotter-and-a-little-animation#comments</comments>
		<pubDate>Tue, 17 May 2011 08:32:35 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Three.js]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[plotter]]></category>
		<category><![CDATA[three.js]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1691</guid>
		<description><![CDATA[Three.js is a powerful 3D library. Graph plotter and a little bit of experimentation is good fun!]]></description>
			<content:encoded><![CDATA[<p>Last year I stumbled upon this <a href="http://antimatter15.com/wp/2010/05/simple-javascript-3d-function-plotter/">blog post</a> by <a href="http://twitter.com/#!/antimatter15">@antimatter15</a> who added a little three line modification to mr.doobs <a href="http://mrdoob.github.com/three.js/examples/canvas_particles_floor.html">particle floor demo</a> and created a graph plotter in three.js. Unfortunately as three.js has developed and evolved the API has changed; in doing so it broke the graphing demo. I left a message asking if there was a fix on Antimatters blog but got no response. So I decided to update the code and fix it for the latest version of <a href="https://github.com/mrdoob/three.js/">three.js</a>; once updated for the latest API it ran as expected.</p>
<div id="attachment_1694" class="wp-caption alignnone" style="width: 528px"><a href="http://dl.dropbox.com/u/7851949/plotter/index.html?cos(sqrt(sq(x)+sq(y)))/3"><img src="http://nooshu.com/wp-content/uploads/2011/05/antimatter-graph-plotter.gif" alt="3D graph plotter using three.js" title="antimatter-graph-plotter" width="518" height="312" class="size-full wp-image-1694" /></a><p class="wp-caption-text">Antimatter15 graph plotter updated for latest version of three.js.</p></div>
<p>You pass the equation you wish to plot via a URL parameter and out the other pops a pretty 3D graph. Here are a couple of examples taken from the <a href="http://antimatter15.com/wp/2010/05/simple-javascript-3d-function-plotter/">original blog post</a>:</p>
<ul>
<li><a href="http://dl.dropbox.com/u/7851949/plotter/index.html?sin(sqrt(sq(x)+sq(y)))/5">sin(sqrt(sq(x)+sq(y)))/5</a></li>
<li><a href="http://dl.dropbox.com/u/7851949/plotter/index.html?sin(sqrt(sq(x)+sq(y)))/sqrt(sq(x)+sq(y))">sin(sqrt(sq(x)+sq(y)))/sqrt(sq(x)+sq(y))</a></li>
</ul>
<p>In updating the code I thought I&#8217;d have a little play myself and see if I could add a bit of motion to the graphs just for the fun of it. I&#8217;ve created a version of my own which you can <a href="http://dl.dropbox.com/u/7851949/animated-plotter/index.html">view here</a>.</p>
<div id="attachment_1700" class="wp-caption alignnone" style="width: 528px"><a href="http://dl.dropbox.com/u/7851949/animated-plotter/index.html"><img src="http://nooshu.com/wp-content/uploads/2011/05/animated-plotter.gif" alt="Graphing multiple for formula using JavaScript and three.js" title="animated-plotter" width="518" height="215" class="size-full wp-image-1700" /></a><p class="wp-caption-text">Modified version allows you to add more than one formula to plot.</p></div>
<p>In my version you no longer pass the formula you wish to plot via a URL parameter, you add it via the panel on the right hand side. You can add and remove as many equations as you wish and the demo will cycle between them. To do so update the right hand panel then click the &#8220;Plot new formula(e)&#8221; button. The equation that is currently being plotted is highlighted in grey and available mathematical functions listed below.</p>
<p>With a little bit of trial end error you can create some interesting effects. There may not be much practical use for the experiment but I enjoyed putting it together with a little help from mr.doob and antimatter15 :)</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/antimatter-3d-graph-plotter-and-a-little-animation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debug Axes in three.js</title>
		<link>http://nooshu.com/debug-axes-in-three-js?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=debug-axes-in-three-js</link>
		<comments>http://nooshu.com/debug-axes-in-three-js#comments</comments>
		<pubDate>Sun, 15 May 2011 14:51:31 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Three.js]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[three.js]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1681</guid>
		<description><![CDATA[Orientate yourself in your three.js with this little bit of JavaScript code. Not the most exciting experiment but I find it very useful!]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: The code I had previously stopped working with the latest three.js API. I&#8217;ve updated and improved the code for the latest API.</p>
<p>I&#8217;ve been working on a couple of small projects using three.js recently; An issue I always seem to have when working with 3D is knowing the current orientation. To help me out I&#8217;ve put together a small snippet of JavaScript.</p>
<div id="attachment_1683" class="wp-caption alignnone" style="width: 528px"><a href="http://dl.dropbox.com/u/7851949/debug-axes/index.html"><img src="http://nooshu.com/wp-content/uploads/2011/05/debug-axis.gif" alt="Creating a set of axis in three.js" title="debug-axes" width="518" height="352" class="size-full wp-image-1683" /></a><p class="wp-caption-text">{x: red, y: green, z: blue} It&#039;s not much to look at but the axes can be very useful.</p></div>
<p>The point where the lines cross is 0,0,0 as you&#8217;d expect, you can adjust the length of the line by changing the axisLength variable. I&#8217;ve uploaded a <a href="http://dl.dropbox.com/u/7851949/debug-axes/index.html">small demo</a> so you can see the code used or copy / paste below:</p>
<div class="codecolorer-container javascript default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> debugaxis <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>axisLength<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Shorten the vertex function</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> v<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Create axis (point1, point2, colour)</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> createAxis<span style="color: #009900;">&#40;</span>p1<span style="color: #339933;">,</span> p2<span style="color: #339933;">,</span> color<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> line<span style="color: #339933;">,</span> lineGeometry <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Geometry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lineMat <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">LineBasicMaterial</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span> color<span style="color: #339933;">,</span> lineWidth<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lineGeometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>p1<span style="color: #339933;">,</span> p2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Line</span><span style="color: #009900;">&#40;</span>lineGeometry<span style="color: #339933;">,</span> lineMat<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scene.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; createAxis<span style="color: #009900;">&#40;</span>v<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>axisLength<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> v<span style="color: #009900;">&#40;</span>axisLength<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> 0xFF0000<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; createAxis<span style="color: #009900;">&#40;</span>v<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span>axisLength<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> v<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> axisLength<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 0x00FF00<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; createAxis<span style="color: #009900;">&#40;</span>v<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> <span style="color: #339933;">-</span>axisLength<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> v<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> axisLength<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 0x0000FF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//To use enter the axis length</span><br />
debugaxis<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>It&#8217;s not much to look at, but it can certainly help you get your bearing when starting a new project (or when things aren&#8217;t working!). Hopefully you find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/debug-axes-in-three-js/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Sieve of Eratosthenes</title>
		<link>http://nooshu.com/the-sieve-of-eratosthenes?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-sieve-of-eratosthenes</link>
		<comments>http://nooshu.com/the-sieve-of-eratosthenes#comments</comments>
		<pubDate>Thu, 12 May 2011 15:19:05 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Interesting]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[maths]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1670</guid>
		<description><![CDATA[Having fun with a little bit of prime hunting and JavaScript. Maths geek for the win!]]></description>
			<content:encoded><![CDATA[<p>I recently read <a href="http://www.amazon.co.uk/Prime-Obsession-Bernhard-Greatest-Mathematics/dp/0452285259">Prime Obsession by John Derbyshire</a>; a book all about prime numbers and one of the worlds greatest Mathematicians: <a href="http://en.wikipedia.org/wiki/Bernhard_Riemann">Bernhard Riemann</a>. The books main focus is on the <a href="http://en.wikipedia.org/wiki/Riemann_hypothesis">Riemann Hypothesis</a> which states that:</p>
<blockquote><p>The real part of any non-trivial zero of the Riemann zeta function is 1/2.</p></blockquote>
<p>I&#8217;d love to say that after reading the book I understand the Maths behind it but alas I do not. That&#8217;s not surprising though as it&#8217;s a problem that has yet to be solved, 159 years after Riemann paper on &#8220;On the Number of Primes Less Than a Given Magnitude&#8221;. It doesn&#8217;t look like it&#8217;s going to be solved any time soon either! If you&#8217;re interested it&#8217;s one of the Clay Mathematics Institutes <a href="http://en.wikipedia.org/wiki/Millennium_Prize_Problems">Millennium Prize Problems</a> in which you can earn yourself US$1,000,000.</p>
<p>While reading Prime Obsession it mentioned an interesting method for finding prime numbers called &#8220;Sieve of Eratosthenes&#8221; (pronounced air-a-TAWS-the-nEEss). Eratosthenes was a librarian at the great library of Alexandria around 230 B.C.E. It&#8217;s quite obvious how the method works once you know it, and easy to see why it&#8217;s called a sieve. The method goes like this:</p>
<ol>
<li>Write a list of numbers in which you wish to identify the primes, say 2 &#8211; 100 (exclude 1 as it isn&#8217;t required)</li>
<li>Take the first number 2. Leaving 2 intact, remove every second number.</li>
<li>Move onto the next number 3. Leave 3 intact and remove every third number</li>
<li>Take the next number 5. Leave 5 intact and take away every fifth number</li>
<li>Repeat until you get to the end of your list</li>
</ol>
<p>The end result is the set of prime numbers up to your given number. Essentially all you are doing is removing any number that is divisible by the 1st, 2nd&#8230; Nth number. Clever stuff!</p>
<p>As a little side project I decided to implement this method using JavaScript, displaying the result in the browser. You can view the <a href="http://dl.dropbox.com/u/7851949/sieve/index.html">demo here</a>. For fun I created two implementations, one relying heavily on the DOM, the other only using arrays. As you&#8217;d expect the DOM method is slow; looping through large tables multiple times doesn&#8217;t make for a quick execution time. The second method using a single JavaScript array is much quicker. I&#8217;ve added a stats panel to the right hand side of the page so it&#8217;s possible to compare results from both methods over different input values.</p>
<p>I&#8217;ve added a limit to the number you can enter into the input box (5000), I don&#8217;t want anyone blaming me for crashing their browser by entering 10 million! :) Feel free to copy the demo if you want to see what happens at higher values.</p>
<div id="attachment_1672" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2011/05/sieve.gif"><img src="http://nooshu.com/wp-content/uploads/2011/05/sieve-518x255.gif" alt="Sieve of Eratosthenes using JavaScript" title="sieve" width="518" height="255" class="size-medium wp-image-1672" /></a><p class="wp-caption-text">The sieve in action showing prime numbers up to 500.</p></div>
<p>Thanks goes to John Resig for his very handy <a href="http://ejohn.org/blog/javascript-array-remove/">Array Remove method</a>.It made removing non-primes from the numbers array very simple indeed.</p>
<p>Prime Obsession is a superb book but a word of warning, it contains a lot of higher level Mathematics, so may not be to everyone&#8217;s taste. It certainly made my brain hurt at times; not always what you need on that 8am commute to work! <a href="http://dl.dropbox.com/u/7851949/sieve/index.html">View the demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/the-sieve-of-eratosthenes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating 3D trees with some #CreativeJS</title>
		<link>http://nooshu.com/creating-3d-trees-with-some-creativejs?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-3d-trees-with-some-creativejs</link>
		<comments>http://nooshu.com/creating-3d-trees-with-some-creativejs#comments</comments>
		<pubDate>Mon, 09 May 2011 15:15:06 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Interesting]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Three.js]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[three.js]]></category>
		<category><![CDATA[tree]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1654</guid>
		<description><![CDATA[Everyone love trees. What about a few virtual trees created using some JavaScript goodness?]]></description>
			<content:encoded><![CDATA[<div id="attachment_1655" class="wp-caption alignnone" style="width: 528px"><a href="http://dl.dropbox.com/u/7851949/treejs/index.html"><img src="http://nooshu.com/wp-content/uploads/2011/05/threejs-trees.gif" alt="Random trees created using three.js and some creative JavaScript" title="threejs-trees" width="518" height="449" class="size-full wp-image-1655" /></a><p class="wp-caption-text">Trees generated at random using some CreateiveJS and Three.js.</p></div>
<p>Over a month has passed since my last blog post and much has happened. We&#8217;ve had a wedding, a funeral at sea (maybe in bad taste!) and I&#8217;ve gone full-time freelance (yay!). I&#8217;ve had a little more time to work on a couple of personal projects so I&#8217;ve finished one that I started way back in January.</p>
<p>I had the pleasure of attending a <a href="http://sebleedelisle.com/2011/02/creativejs-experiments/">Creative JavaScript course</a> in Brighton, UK, hosted by <a href="http://sebleedelisle.com/">Seb Lee-Delisle</a>; a two-day course that covered a wealth of topics from Vanilla JavaScript to Three.js. If you&#8217;re looking for some inspiration I highly recommend looking out for one of Seb&#8217;s courses. Great fun and you get to meet some really nice people. <strong>Quick tip:</strong> You may want to brush up on a little <a href="http://en.wikipedia.org/wiki/Trigonometry">Trigonometry</a> before you go as it&#8217;s used numerous times. I knew that A-Level Mathematics course would come in useful one day :).</p>
<p>Seb produced a demo in Canvas that created &#8216;trees&#8217; and it really caught my eye. The trees were in 2D so as I&#8217;ve had a bit of experience with <a href="https://github.com/mrdoob/three.js/">Three.js</a> I decided to create a 3D version! I&#8217;m quite happy with the result although I&#8217;ve had to restrict the number of branches rendered due to the lack of dedicated graphics card in my laptop; I get about 1fps when stopping at a branch length value of 10 (line 211) :(</p>
<p><a href="http://dl.dropbox.com/u/7851949/treejs/index.html">The demo</a> also allowed me to use the new request animation frame API which vendors have added to aid animations in browsers. The main advantage of using it is if you have the animation running in a tab that isn&#8217;t visible, the browser will know to stop the animation! Using the old setTimeout method, the animation still runs in the background and uses up precious CPU, memory and battery power (especially on a laptop). As with most new browser features the API isn&#8217;t set in stone (yet) but luckily Paul Irish has <a href="http://paulirish.com/2011/requestanimationframe-for-smart-animating/">created a polyfill</a> that falls back to setTimeout in older browsers. </p>
<p>View the <a href="http://dl.dropbox.com/u/7851949/treejs/index.html">demo here</a>; reload for different trees. JavaScript finally seems to be coming of age!</p>
<p><strong>Update:</strong> Original credit goes to Jean-No with his <a href="http://www.openprocessing.org/portal/?userID=997">amazing OpenProcessing work</a>! I&#8217;ll be bookmarking that link, some stunning work there. Thanks to Seb for pointing out who to credit :)</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/creating-3d-trees-with-some-creativejs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual thesaurus using arbor.js</title>
		<link>http://nooshu.com/visual-thesaurus-using-arbor-js?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=visual-thesaurus-using-arbor-js</link>
		<comments>http://nooshu.com/visual-thesaurus-using-arbor-js#comments</comments>
		<pubDate>Sun, 30 Jan 2011 19:30:40 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[words]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1587</guid>
		<description><![CDATA[Arbor.js is a very impressive graph visualisation library that takes advantage of jQuery and the Web Workers API. I make my own version of the Visual Thesaurus with it.]]></description>
			<content:encoded><![CDATA[<p>Wow, I can&#8217;t believe we are at the end of January &#8211; one twelfth of the year gone already! I&#8217;ve been so busy this month I&#8217;ve barely had time to sit down and work on any personal projects. Thankfully I had a spare few hours over the weekend to work on  a project I&#8217;ve been meaning to finish for a couple of weeks: <a href="http://nooshu.com/explore/arbor-visual-thesaurus/">a visual thesaurus using JavaScript</a>.</p>
<div id="attachment_1588" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2011/01/visual-thesaurus.gif"><img src="http://nooshu.com/wp-content/uploads/2011/01/visual-thesaurus.gif" alt="Visual Thesaurus using JavaScript" title="visual-thesaurus" width="518" height="350" class="size-full wp-image-1588" /></a><p class="wp-caption-text">Visual thesaurus representation of the word 'clean'.</p></div>
<p>You may (or may not) know of the <a href="http://www.visualthesaurus.com/">Visual Thesaurus by Thinkmap</a>; very useful but it&#8217;s a paid for service, I use it so infrequently I can&#8217;t justify paying for it (there is a free trial though). Recently a very interesting graph visualisation library popped up on <a href="http://www.delicious.com/">delicious</a> called <a href="http://arborjs.org/">arbor.js</a>, so I decided to have a closer look and see if I could use it for the JavaScript version. For the word data I&#8217;ve used the <a href="http://words.bighugelabs.com/api.php">Bighugelabs thesaurus API</a> which I previously used to create my <a href="http://nooshu.com/wordpress-plug-in-post-thesaurus/">Post Thesaurus</a> WordPress plug-in (shameless plug!).</p>
<p>Arbor.js took a little getting used to as it uses a mixture jQuery, canvas and its own methods; but there&#8217;s a fairly extensive set of documentation and a set of usage examples. Once you get your head around adding nodes and edges to the system, arbor takes care of the rest. One thing I did notice is the site examples and my VT experiment run much smoother in Firefox than they do in Chrome, which is quite surprising considering how quick the V8 engine is in Chrome. Maybe this will be improved in future versions.</p>
<p>So to the <a href="http://nooshu.com/explore/arbor-visual-thesaurus/">demo</a>; I&#8217;ve tried to keep it very simple to use. Enter the word you wish to visualise and click search. Once the API returns a result it&#8217;s plotted by arbor. You can drill down into the result by clicking on the sub-particles (and remove them by clicking again). The individual words can be clicked and you&#8217;re given the option to search again using the selected word. I still haven&#8217;t got the perfect system setup as some results can be a little jittery; usually when an even set of words are returned. I&#8217;ll keep playing with system settings to see if I can improve this.</p>
<p>Any suggestions, comments or feature improvements please leave a comment below!</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/visual-thesaurus-using-arbor-js/feed</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>A three.js community on Reddit</title>
		<link>http://nooshu.com/a-three-js-community-on-reddit?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-three-js-community-on-reddit</link>
		<comments>http://nooshu.com/a-three-js-community-on-reddit#comments</comments>
		<pubDate>Thu, 30 Dec 2010 11:59:55 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[Three.js]]></category>
		<category><![CDATA[reddit]]></category>
		<category><![CDATA[three.js]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1573</guid>
		<description><![CDATA[Three.js now has a community on reddit, so why not submit a few links and experiments!]]></description>
			<content:encoded><![CDATA[<p>Well 2011 is nearly upon us; which leaves me thinking&#8230; where did 2010 go! I hope I&#8217;m not the only one who thinks this year has gone quick! One big web application that died in 2010 was <a href="http://digg.com/news">digg.com</a>. I used to use it every day for the latest technology and funny videos, but then they changed it. The design became very blue and digg seemed to change from a simple community driven link aggregator to a, well, I&#8217;m not sure what it changed to in all honesty. So it was time to find an alternative.</p>
<p>Luckily for me (and all digg users) there&#8217;s already a well established alternative: <a href="http://www.reddit.com/">reddit.com</a>. It may not look as flashy as digg, but it makes up for it with ease of use and functionality. Need to set up a community for your web application, current technology, interest or well, just about anything really; then reddit is the place for you.</p>
<p>So that&#8217;s exactly what I&#8217;ve done for Mr. doobs <a href="https://github.com/mrdoob/three.js/">three.js JavaScript library</a>. I created a <a href="http://www.reddit.com/r/threejs/">Threejs community</a> that anyone can submit links to relating to three.js. Over the past few weeks I&#8217;ve been adding a couple of links a day, there really are a great selection of examples out there if you take the time to hunt then down.</p>
<p>So if you&#8217;ve created a cool new example using three.js or any other link relating to this excellent JavaScript library <a href="http://www.reddit.com/r/threejs/">submit it here</a>. Digg is dead. Long live reddit.com!</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/a-three-js-community-on-reddit/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Experimenting with Webkit form speech input</title>
		<link>http://nooshu.com/experimenting-with-webkit-form-speech-input?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=experimenting-with-webkit-form-speech-input</link>
		<comments>http://nooshu.com/experimenting-with-webkit-form-speech-input#comments</comments>
		<pubDate>Wed, 22 Dec 2010 20:46:06 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[speech]]></category>

		<guid isPermaLink="false">http://nooshu.com/?p=1563</guid>
		<description><![CDATA[The HTML5 specifications are adding some very interesting new features. Here's one that's just landed in Google Chrome: speech input.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a few weeks now since I attended a <a href="http://nooshu.com/game-on-london-2010/">Web Gaming event hosted by Mozilla</a> and I&#8217;ve not yet had chance to write about one of the coolest features that was demonstrated: <a href="https://docs.google.com/View?id=dcfg79pz_5dhnp23f5">Speech input in forms</a>. Now I must admit, I had no idea this was even possible; so it was quite a surprise when I saw the demonstration. With a few extra attributes added to a standard input box you can enable speech input:</p>
<div class="codecolorer-container html4strict default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;speech&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;speech&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> x-webkit-speech speech error onwebkitspeechchange<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dosomething.coolhere(true);&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></div></td></tr></tbody></table></div>
<p>It really is that simple! You may notice the &#8220;x-webkit-speech&#8221; attribute so will have guessed it currently only works in Webkit; and as far as I&#8217;m aware only in very <a href="http://peter.sh/2010/12/crankshaft-the-chrome-web-store-and-html5s-figure-element/">recent versions of Google Chrome</a> (note: &#8220;The Input Speech API will now be available by default on Chrome’s dev-channel&#8221;). The Speech API seems very new and is still a draft, so it will be a while before it&#8217;s fully adopted by other browser vendors.</p>
<div id="attachment_1568" class="wp-caption alignnone" style="width: 528px"><a href="http://nooshu.com/wp-content/uploads/2010/12/speak-to-santa-speech-api.gif"><img src="http://nooshu.com/wp-content/uploads/2010/12/speak-to-santa-speech-api.gif" alt="Demo of the new HTML5 Speech API" title="speak-to-santa-speech-api" width="518" height="180" class="size-full wp-image-1568" /></a><p class="wp-caption-text">A quick demonstration of the Speech API in action.</p></div>
<p>To demonstrate the speech input I&#8217;ve put together a very simple <strong>festive</strong> <a href="http://nooshu.com/explore/santa-speech-api/">demo</a> that queries the Flickr API looking for images related to a value entered. So if you have a microphone and the <a href="http://www.google.com/chrome/intl/en/eula_dev.html">dev channel of Chrome</a>, why not give it a try. Chrome records the input of the microphone before sending it off to an external server to be processed, where a value is then sent back to the browser. At first I thought it was all processed inside the browser but I guess that&#8217;s a little to much to expect! It isn&#8217;t 100% accurate and the demo accepts Googles first guess so you may get a few strange results. The server returns multiple guesses which a user can select from, but this hasn&#8217;t been added (to my demo at least).</p>
<p>Since the API is very new it took a little trial and error to work out how to detect if the Speech API was available in the browser; but with a little help from <a href="http://paulirish.com/">Paul Irish</a> I managed to crack it:</p>
<div class="codecolorer-container javascript default customCodeColor" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> speechcapable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> elem <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> support <span style="color: #339933;">=</span> <span style="color: #3366CC;">'onwebkitspeechchange'</span> <span style="color: #000066; font-weight: bold;">in</span> elem <span style="color: #339933;">||</span> <span style="color: #3366CC;">'speech'</span> <span style="color: #000066; font-weight: bold;">in</span> elem<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> support<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>This function will return true if the API is available. It&#8217;s worth noting that since it&#8217;s very new this function is likely to break in the future as the properties always seem to be changing. It works at the moment, so get thinking about what this brilliant new API can be used for! It&#8217;s a big plus for accessibility if used correctly and I can also see some cool applications in web gaming too. View the <a href="http://nooshu.com/explore/santa-speech-api/">demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nooshu.com/experimenting-with-webkit-form-speech-input/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

