<?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>Jason Mooberry &#187; jQuery</title>
	<atom:link href="http://blog.jasonmooberry.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jasonmooberry.com</link>
	<description>Stuff I did for you.</description>
	<lastBuildDate>Sat, 29 Oct 2011 23:41:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.2</generator>
		<item>
		<title>Geoff &#8211; Game Life!</title>
		<link>http://blog.jasonmooberry.com/2010/06/geoff-game-life/</link>
		<comments>http://blog.jasonmooberry.com/2010/06/geoff-game-life/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 00:31:05 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[game of life]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=61</guid>
		<description><![CDATA[I've been fascinated with Conway's Game of Life for years now.  I love how there is an apparent order to things that is reproducible as well as simple in it's requirements.  Recently there was a discovery that made the tech news about a new pattern that replicated itself.  I'll be honest, the demo of the replicating code wasn't as sexy as I had hoped.  But it did remind me how much I want to make this game.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been fascinated with <a href="http://en.wikipedia.org/wiki/Conway's_Game_of_Life" target="_blank">Conway&#8217;s Game of Life</a> for years now.  I love how there is an apparent order to things that is reproducible as well as simple in it&#8217;s requirements.  Recently there was a discovery that made the tech news about a <a href="http://www.newscientist.com/article/mg20627653.800-first-replicating-creature-spawned-in-life-simulator.html" target="_blank">new pattern that replicated itself</a>.  I&#8217;ll be honest, the demo of the replicating code wasn&#8217;t as sexy as I had hoped.  But it did remind me how much I want to make this game.</p>
<p>I&#8217;ve been on a recent tear through javascript, browser and server side (node.js is just fun).  So I set out to build a little game of life with js and html.  jQuery aided with some of the lifting too.  :)</p>
<p>After a couple afternoons Geoff was born.  He&#8217;s a simple lad.  Just gives you the basics, but still fun to play with non-the-less.  I have only tested him on Chrome, FF, and Safari.  Interestingly this is a great way to see how fast your js engine is.  Chrome handles it the best on my laptop.  FF the worst.</p>
<p><strong>A little bit about the code:</strong></p>
<p>jQuery&#8217;s <a href="http://api.jquery.com/live/" target="_blank">live()</a> event handling is perfect for this situation.  Since I opted to turn a crap-ton of b tags into large pixels of my game grid, I needed to bind some mouseover/mouseout and click events to each item.  There is no need to do this to each of the ~2k tags.  Instead, using live(), jQuery will bind to the document and as events bubble up, check to see if they&#8217;re relevant to my event handlers.  This cuts memory usage as well as bind time.</p>
<p>Recursion with setTimeout().  Initially when I built this I was using setInterval() to fire my life function and advance Geoff another step.  On Chrome it was fast enough that I didn&#8217;t notice any problems.  But when I tested in Safari and FF, I found that I was &#8220;dropping frames&#8221; when I cranked up the speed.  This had weird effects.  So I used a recursive function that pauses at the end of it&#8217;s execution.  This will ensure that I don&#8217;t lose an iteration, while giving reasonable control over the speed of execution.</p>
<p>Pseudo-casting as integer.  This is a hack that I picked up from <a href="http://james.padolsey.com/javascript/double-bitwise-not/">James Padolsey&#8217;s blog</a>.  For my purposes it&#8217;s a nice way to take a boolean expression and convert it into a 0 or 1.</p>
<pre class="brush: js">
// sum up the active neighbors
active += ~~(typeof current[neighbors[j]] === 'number' &amp;&amp; current[neighbors[j]] === 1);
</pre>
<p>Best practices.  I&#8217;ve violated them .. a bit.  :)</p>
<p>Well I hope you have fun playing.  I tried drawing moo and it lived a healthy and rich life.  ;)</p>
<p><strong><a href="http://jasonmooberry.com/dev/geoff.html" target="_blank">Enjoy Geoff!</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2010/06/geoff-game-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.062 seconds -->

