<?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>scriptNode &#187; just-for-fun</title>
	<atom:link href="http://scriptnode.com/tag/just-for-fun/feed/" rel="self" type="application/rss+xml" />
	<link>http://scriptnode.com</link>
	<description>Tips and tricks for web developers.</description>
	<lastBuildDate>Tue, 01 Sep 2009 18:46:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP: goto hell;</title>
		<link>http://scriptnode.com/article/php-goto-hell/</link>
		<comments>http://scriptnode.com/article/php-goto-hell/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 19:53:11 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Novice]]></category>
		<category><![CDATA[code-style]]></category>
		<category><![CDATA[just-for-fun]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=326</guid>
		<description><![CDATA[
As of version 5.3, PHP supports goto (much to the chagrin of many). To protest, one snarky programmer filed a faux bug in their bug tracking system:





Funny stuff! But all kidding aside, I personally feel like PHP was ugly enough without goto. To me, one of the language&#8217;s biggest downfalls has always been that it [...]]]></description>
			<content:encoded><![CDATA[<p>
As of <a href="http://www.sitepoint.com/article/whats-new-php-5-3/">version 5.3</a>, PHP supports <a href="http://us3.php.net/goto"><code>goto</code></a> (much to the chagrin of many). To protest, one snarky programmer filed a <a href="http://bugs.php.net/bug.php?id=48669">faux bug</a> in their bug tracking system:
</p>
<p>
<a href="http://bugs.php.net/bug.php?id=48669"><img alt="PHP: goto hell;" src="/assets/img/php_goto_hell.jpg" style="border: 1px solid #000;"/></a>
</p>
<p>
Funny stuff! But all kidding aside, I personally feel like PHP was ugly enough without <code>goto</code>. To me, one of the language&#8217;s biggest downfalls has always been that it practically <em>encourages</em> sloppy design, and this is a huge step in the wrong direction. How do you feel about it?
</p>
<p>
(Link via <a href="http://foohack.com/">Isaac Schlueter</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/php-goto-hell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>5 Things That Suck About Being a Frontend Engineer</title>
		<link>http://scriptnode.com/article/5-things-that-suck-about-being-a-frontend-engineer/</link>
		<comments>http://scriptnode.com/article/5-things-that-suck-about-being-a-frontend-engineer/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 00:23:18 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Novice]]></category>
		<category><![CDATA[careers]]></category>
		<category><![CDATA[just-for-fun]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=313</guid>
		<description><![CDATA[
Call it what you will. There&#8217;s been much debate about the job title for a frontend engineer, or a web developer, or whatever name you prefer. What I&#8217;m referring to, however, are the folks who code for the browser. If you spend all day waste-deep in markup, CSS and JavaScript, then you do what I [...]]]></description>
			<content:encoded><![CDATA[<p>
Call it what you will. There&#8217;s been much debate about the job title for a frontend engineer, or a web developer, or whatever name you prefer. What I&#8217;m referring to, however, are the folks who code for the browser. If you spend all day waste-deep in markup, <a href="/tag/css/">CSS</a> and <a href="/tag/javascript/">JavaScript</a>, then you do <a href="http://raptr.com/">what I do</a> and I&#8217;m talking about you.
</p>
<p>
And let&#8217;s just skip right past <a href="http://www.stopie6.com/">Internet Explorer</a> and its plethora of headaches, shall we? We all know it sucks. Here&#8217;s why <em>else</em> it sucks to be one of us:
</p>
<ol>
<li>
<h3>Everyone Thinks It&#8217;s Your Fault</h3>
<p>
So you&#8217;re <a href="/article/5-ways-qa-ruin-developers-lives/">QA</a>. You&#8217;re testing a website and something is broken. It looks to you like the frontend, because that&#8217;s what you see. What may separate good QA from excellent QA is the ability to determine where the error lies, but sometimes that&#8217;s out of QA&#8217;s scope.
</p>
<p>
Regardless of who the owner is, chances are the issue will go to you first. You must then determine if it&#8217;s even your issue, and either fix it, or pass it on. Bringing us to …
</p>
</li>
<li>
<h3>You Are Also a Project Manager</h3>
<p>
The frontend is the very <strong>last</strong> thing to get done. That&#8217;s because the design needs to be finished way in advance so that assets can be delivered, and the backend has to be complete before you have access to data to use in your implementation.
</p>
<p>
This means that you must act as <strong>Project Manager</strong> to keep everyone else on track, because otherwise you can&#8217;t ever get to work! And that&#8217;s why …
</p>
</li>
<li>
<h3>You Always Seem Late</h3>
<p>
Since you&#8217;re the last one that gets to begin implementing, chances are you&#8217;ve got less time than everyone else. And sometimes you can&#8217;t even get started until <em>after</em> your deadline! And even when you do finally get your assets and can get to it, sometimes …
</p>
</li>
<li>
<h3>You Must Know Photoshop</h3>
<p>
To be fair, I actually use <a href="http://www.gimp.org/">The Gimp</a>, which works fine. What I mean by this point is that you must learn to use a competent image manipulation program. Why? Because although you may have an excellent design person/team, chances are they&#8217;re not going to cater to you and your crazy <a href="http://delicious.com/richtaur/css">CSS hacks</a>.
</p>
<p>
You know what I mean. Sometimes you&#8217;re wanting to <a href="http://developer.yahoo.com/performance/rules.html">sprite your images</a> to get better page performance, or sometimes you need to pull off some crazy rounded corners hack to get the positioning <a href="http://developer.yahoo.com/yui/articles/gbs/">cohesive across browsers</a>. You could go back-and-forth with design all day, or you could say &#8220;screw it&#8221; and alter the image yourself. It sucks but that&#8217;s how it gets done. And that&#8217;s part of …
</p>
</li>
<li>
<h3>You Must be a Jack-of-All-Trades</h3>
<p>
In addition to competency with a decent image manipulation application, you&#8217;re going to need at least a familiarity in many other areas. It&#8217;s very rare to find a frontend engineer who doesn&#8217;t ever need to modify at least some server-side code.
</p>
<p>
For example, although I am official a frontend engineer, I probably spend 30-50% of my time in <a href="/tag/php/">PHP</a>. That&#8217;s because, before I can even render the markup I need to tweak, I&#8217;ve got to setup the data I receive from the backend.
</p>
<p>
Not to mention the various other tasks that randomly pop up in the webdev stack, such as <a href="http://www.addedbytes.com/apache/url-rewriting-for-beginners/">Apache rewrite rules</a> or cronjobs. I&#8217;m sure the same could be said for most jobs, but it seems like frontend engineers&#8217; skillsets must be broader than most.
</p>
</li>
</ul>
<div class="section">
But it&#8217;s not all bad. Especially right now in Silicon Valley, frontend engineers are quite valuable, so it&#8217;s a great time to know how to code for the browser. Either way, did I miss something? Let me know!
</div>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/5-things-that-suck-about-being-a-frontend-engineer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spacius! Source Code</title>
		<link>http://scriptnode.com/article/spacius-source-code/</link>
		<comments>http://scriptnode.com/article/spacius-source-code/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 05:52:23 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[code-style]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[just-for-fun]]></category>
		<category><![CDATA[lab]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=278</guid>
		<description><![CDATA[
I&#8217;ve been meaning to &#8220;release&#8221; this for quite some time now, but I wanted to do it in small doses, with in-depth explanations of the code. Making a game can be somewhat overwhelming, but it&#8217;s just like any other large task: if you break it up into smaller pieces, it becomes much easier to manage.


But [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;ve been meaning to &#8220;release&#8221; this for quite some time now, but I wanted to do it in small doses, with in-depth explanations of the code. Making a game can be somewhat overwhelming, but it&#8217;s just like any other large task: if you break it up into smaller pieces, it becomes much easier to manage.
</p>
<p>
But time is a commodity nowadays. I&#8217;ve got way less time to write, and when I do, I&#8217;d rather be writing <em>code</em> than tutorials (or honestly, <a href="http://raptr.com/richtaur"><em>playing</em> video games</a>). Sorry about that, but I hope the (well-commented!) source will help those of you out there who&#8217;d like to contribute to the <a href="http://games.nihilogic.dk/">slowly growing world of DHTML games</a>.
</p>
<p>
You&#8217;ll notice that this code is <a href="/article/spacius-a-space-adventure/">over 6 months old</a>. And I&#8217;m the kind of developer who constantly updates his <a href="/tag/code-style/">style, methods and patterns</a>. Given that, there may very well be many mistakes or bad practices in here, some of which I may have improved upon by now, but others maybe not. Either way, feel free to comment on them, and I&#8217;ll answer any questions as well.
</p>
<p>
Thanks for checking it out, and please be good to it. I&#8217;d love to know about any projects created with this source as a basis, and would appreciate links back here. Also please don&#8217;t claim it as your own, that&#8217;s not cool.
</p>
<div class="section">
For now I am hosting the source code with <a href="http://github.com/richtaur/spacius-/tree/master">GitHub</a>.
</div>
<p>
Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/spacius-source-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software Development Meme</title>
		<link>http://scriptnode.com/article/software-development-meme/</link>
		<comments>http://scriptnode.com/article/software-development-meme/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 23:50:21 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Novice]]></category>
		<category><![CDATA[careers]]></category>
		<category><![CDATA[interviews]]></category>
		<category><![CDATA[just-for-fun]]></category>
		<category><![CDATA[questions]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=171</guid>
		<description><![CDATA[
I&#8217;ve been tagged by the insanely creative Jacob Seidelin, which means it&#8217;s my turn to fill out the Software Development Meme!

How old were you when you first started programming?
I was about 12 years old. That combined with my love of Nintendo really makes it sound like I never left the house, but I found time [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;ve been tagged by the insanely creative <a href="http://blog.nihilogic.dk/2008/09/software-development-meme.html">Jacob Seidelin</a>, which means it&#8217;s my turn to fill out the <strong>Software Development Meme</strong>!
</p>
<h3>How old were you when you first started programming?</h3>
<p>I was about 12 years old. That combined with my love of Nintendo really makes it sound like I never left the house, but I found time to play sports and get in trouble, really&#8230; &#8230;</p>
<h3>How did you get started in programming?</h3>
<p>A mysterious friend of mine (Jim MacDonald, who all but doesn&#8217;t exist online) and I used to play games all day, like <a href="http://www.rpgclassics.com/shrines/nes/dw1/">Dragon Warrior</a> and <a href="http://www.rpgclassics.com/shrines/genesis/shiningforce/">Shining Force</a>. Then one day he wondered how games were made, and found&#8230;</p>
<h3>What was your first language?</h3>
<p>QBASIC! This has gotta be the easiest language to learn, and that says a lot in an age where PHP exists. I think more developers would benefit from starting with this fantastically simple language.</p>
<h3>What was the first real program you wrote?</h3>
<p>I wrote a program I simply called <strong>Dragon</strong>, which was a direct ripoff of Jim&#8217;s game <strong>Wizard</strong> or something. It used QBASIC&#8217;s <code>DRAW</code> commands to draw shapes and <code>PLAY</code> for sound effects. It was a single-battle, turn-based game pitting you (a knight) against a dragon. It was amazingly bad but pretty fun (for 12-year-olds anyway).</p>
<h3>What languages have you used since you started programming?</h3>
<p><strong>Professionally:</strong> Only <a href="http://php.net/">PHP</a> and JavaScript</p>
<p><strong>For fun and/or school:</strong> BASIC, C, C++, Perl, Python, QBASIC, Turbo Pascal, Visual BASIC</p>
<h3>What was your first professional programming gig?</h3>
<p>Working for <a href="http://blog.davglass.com/">Dav Glass</a> at <a href="http://schoolcenter.com/">SchoolCenter</a>. I was a PHP programmer making a measly $10/hour coding content management tools for K-12 schools. I was quickly promoted to lead designer (odd, right?), then when the company realized we needed engineers more than designers, put back into the development department. About a year after <a href="http://yuiblog.com/blog/2007/03/29/yuiteam/">Dav moved to Yahoo!</a>, I followed.</p>
<h3>If you knew then what you know now, would you have started programming?</h3>
<p>Oh <strong>hell</strong> yes. I&#8217;m always trying to learn as much as I can. Learning new languages is fascinating, and learning more about what you already are familiar with to me should be a daily exercise. If I had had the knowledge I have now when I was younger, I can&#8217;t imagine what I would have built by now. Interesting to think about!</p>
<h3>If there is one thing you learned along the way that you would tell new developers, what would it be?</h3>
<p>In a normal curriculum in school, students are taught to read well before they are taught to write. I&#8217;m not sure why this isn&#8217;t the case in programming. You&#8217;ve always got these wannabe developers that try to run before they can walk, and they end up tripping. There&#8217;s no shame in beginning modestly.</p>
<p>I recommend to <strong>anyone of any</strong> programming level: read other people&#8217;s code. The Internet is the <strong>ideal</strong> place to learn.</p>
<h3>What’s the most fun you’ve ever had… programming?</h3>
<p>Everytime I learn a new language, my first task is to build a game. I&#8217;ve been doing this for over a decade, in every single language I&#8217;ve dabbled in. But I think it was the most fun in QBASIC. I built an intentionally awful game called <a href="http://seanbaby.com/readers/richter1.htm">Seanbaby&#8217;s Magic Bus Ride Trip</a> for you guessed it&#8230; <a href="http://seanbaby.com/">Seanbaby</a>. Working in <a href="http://paletteswap.com/misc/games/benzer/">Flash is really fun</a> too, but <a href="/lab/spacius/">nothing beats JavaScript</a>.</p>
<h3>Who’s next?</h3>
<p>Let&#8217;s go with <a href="http://foohack.com/">Isaac Schlueter</a>, since he&#8217;s a great writer and always has interesting things to say!</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/software-development-meme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>twittertyper</title>
		<link>http://scriptnode.com/article/twittertyper/</link>
		<comments>http://scriptnode.com/article/twittertyper/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 01:11:51 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[just-for-fun]]></category>
		<category><![CDATA[lab]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=157</guid>
		<description><![CDATA[



I unfortunately am not allowed to participate, but in anticipation of Yahoo!&#8217;s Hack Day 2008, I put together a little app I&#8217;ll hopefully be able to port to YAP: twittertyper!


The concept is very simple. twittertyper displays the latest tweet from Twitter. To read the next one, first type out the tweet. The text is highlighted [...]]]></description>
			<content:encoded><![CDATA[<p class="before">
<a href="/lab/twittertyper/"><img alt="twittertyper" src="http://scriptnode.com/lab/twittertyper/logo.png"/></a>
</p>
<p>
I unfortunately am not allowed to participate, but in anticipation of Yahoo!&#8217;s <a href="http://developer.yahoo.net/hackday/">Hack Day 2008</a>, I put together a little app I&#8217;ll hopefully be able to port to <a href="http://developer.yahoo.com/searchmonkey/" title="Yahoo! Application Platform">YAP</a>: <a href="/lab/twittertyper/">twittertyper</a>!
</p>
<p>
The concept is very simple. <strong>twittertyper</strong> displays the latest tweet from <a href="http://twitter.com">Twitter</a>. To read the next one, first <strong>type out the tweet</strong>. The text is highlighted as you go. If you come across a character your keyboard (or operating system) won&#8217;t let you type, just press <code>Esc</code> to move on to the next character.
</p>
<p>
<strong>twittertyper</strong> currently just pulls in from the <a href="http://twitter.com/public_timeline">public timeline</a>; no authentication is supported to pull from <em>your</em> timeline (maybe in a future version). This mini-app is built on <a href="http://developer.yahoo.com/yui/" title="Yahoo! User Interface Library">YUI</a>. Source code (uncompressed) is <a href="/lab/twittertyper/tt.js">free to peruse</a>.
</p>
<p>
<a href="/lab/twittertyper/">Try it out!</a>
</p>
<p>
<em><strong>Note:</strong> If you use Twitter, I&#8217;m sure you&#8217;re used to it being down. Errors happen often, but <strong>twittertyper</strong> attempts to handle them somewhat gracefully. Usually a page reload should suffice.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/twittertyper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shark!</title>
		<link>http://scriptnode.com/article/shark/</link>
		<comments>http://scriptnode.com/article/shark/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 10:56:42 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[just-for-fun]]></category>
		<category><![CDATA[lab]]></category>
		<category><![CDATA[script-sunday]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=48</guid>
		<description><![CDATA[
Well, this year&#8217;s Shark Week is over. In its memory, I offer up a script that makes sharks swim around on the screen. You should see a few sharks swimming about right now! Here&#8217;s the source code:


/**
 * Global Shark constructor
 * Options for ops: dir, speed, url, x, y, zIndex
 * @constructor
 * @public
 [...]]]></description>
			<content:encoded><![CDATA[<p>
Well, this year&#8217;s <a href="http://discovery.com/sharkweek/">Shark Week</a> is over. In its memory, I offer up a script that makes sharks swim around on the screen. You should see a few sharks swimming about right now! Here&#8217;s the source code:
</p>
<p><textarea class="javascript" cols="50" name="code" rows="10"><br />
/**<br />
 * Global Shark constructor<br />
 * Options for ops: dir, speed, url, x, y, zIndex<br />
 * @constructor<br />
 * @public<br />
 */<br />
Shark = function(ops) {</p>
<p>	var Y = YAHOO.util,<br />
		DEFAULT_SPEED = 2,<br />
		DEFAULT_ZINDEX = 1000,<br />
		DELAY = 25,<br />
		LEFT = &#8216;l&#8217;,<br />
		RIGHT = &#8216;r&#8217;,<br />
		SCREEN_WIDTH = Y.Dom.getViewportWidth(),<br />
		SCREEN_HEIGHT = Y.Dom.getViewportHeight(),<br />
		SHARK_WIDTH = 242,<br />
		SHARK_HEIGHT = 82;</p>
<p>	var interval,<br />
		that = this;</p>
<p>	that.active = true;<br />
	that.dir = LEFT;<br />
	that.el = {};<br />
	that.onOutLeft = function(){};<br />
	that.onOutRight = function(){};<br />
	that.x = 0;<br />
	that.y = 0;</p>
<p>	/**<br />
	 * Initializes the shark variables<br />
	 * @private<br />
	 */<br />
	var init = function() {</p>
<p>		ops = ops || {};<br />
		ops.speed = ops.speed || rand(DEFAULT_SPEED, (DEFAULT_SPEED * 2));<br />
		ops.url = ops.url || &#8216;./&#8217;;<br />
		ops.zIndex = ops.zIndex || DEFAULT_ZINDEX;</p>
<p>		if (ops.dir) {<br />
			that.dir = ops.dir;<br />
		} else {<br />
			that.dir = [LEFT, RIGHT][rand(0, 1)];<br />
		}</p>
<p>		if (ops.x === undefined) {<br />
			if (that.dir == LEFT) {<br />
				that.x = (SCREEN_WIDTH &#8211; 1);<br />
			} else {<br />
				that.x = -SHARK_WIDTH;<br />
			}<br />
		} else {<br />
			that.x = ops.x;<br />
		}</p>
<p>		that.el = document.createElement(&#8217;div&#8217;);<br />
		that.el.className = &#8217;shark&#8217;; // Doesn&#8217;t do anything. Just in case you want to use it<br />
		that.el.style.position = &#8216;absolute&#8217;;<br />
		that.el.style.height = SHARK_HEIGHT + &#8216;px&#8217;;<br />
		that.el.style.zIndex = ops.zIndex;</p>
<p>		Y.Event.addListener(that.el, &#8216;click&#8217;, onclick);</p>
<p>		document.body.appendChild(that.el);<br />
		reset();</p>
<p>		if (ops.y !== undefined) {<br />
			that.y = ops.y<br />
			plot();<br />
		}</p>
<p>		that.start();</p>
<p>	};</p>
<p>	/**<br />
	 * Kills the shark<br />
	 * @param {Boolean} fade Whether to fade the shark in or not<br />
	 */<br />
	that.kill = function(fade) {</p>
<p>		that.active = false;</p>
<p>		var done = function() {<br />
			document.body.removeChild(that.el);<br />
			stop();<br />
		};</p>
<p>		if (fade) {</p>
<p>			var anim = new Y.Anim(that.el, {opacity : {to : 0}}, 0.5);</p>
<p>			anim.onComplete.subscribe(done);<br />
			anim.animate();</p>
<p>		} else {<br />
			done();<br />
		}</p>
<p>	};</p>
<p>	/**<br />
	 * Move the shark<br />
	 */<br />
	var move = function() {</p>
<p>		if (!that.active) {<br />
			return;<br />
		}</p>
<p>		if (that.dir == LEFT) {</p>
<p>			that.x -= ops.speed;</p>
<p>			if (that.x &lt; -SHARK_WIDTH) {<br />
				that.dir = RIGHT;<br />
				that.onOutLeft();<br />
				reset();<br />
			}</p>
<p>		} else {</p>
<p>			that.x += ops.speed;</p>
<p>			if (that.x &gt; (SCREEN_WIDTH &#8211; 1)) {<br />
				that.dir = LEFT;<br />
				that.x = (SCREEN_WIDTH &#8211; 1);<br />
				that.onOutRight();<br />
				reset();<br />
			}</p>
<p>		}</p>
<p>		if (that.x &gt; (SCREEN_WIDTH &#8211; SHARK_WIDTH)) {<br />
			that.el.style.width = (SHARK_WIDTH &#8211; (that.x &#8211; (SCREEN_WIDTH &#8211; SHARK_WIDTH))) + &#8216;px&#8217;;<br />
		} else {<br />
			that.el.style.width = SHARK_WIDTH + &#8216;px&#8217;;<br />
		}</p>
<p>		plot();</p>
<p>	};</p>
<p>	/**<br />
	 * Kills the shark. Note: intended to be overwritten<br />
	 */<br />
	var onclick = function() {<br />
		that.onclick();<br />
	};</p>
<p>	/**<br />
	 * Default onclick behavior<br />
	 */<br />
	that.onclick = function() {<br />
		that.kill(true);<br />
	};</p>
<p>	/**<br />
	 * Moves the shark element to the XY coordinates<br />
	 */<br />
	var plot = function() {<br />
		that.el.style.left = that.x + &#8216;px&#8217;;<br />
		that.el.style.top = that.y + &#8216;px&#8217;;<br />
	};</p>
<p>	/**<br />
	 * Returns a random number<br />
	 * @param {Number} from The starting point<br />
	 * @param {Number} to The stopping point<br />
	 * @return {Number} A random number within the range<br />
	 */<br />
	var rand = function(from, to) {<br />
		return (from + Math.floor((to &#8211; from + 1) * Math.random()));<br />
	}; </p>
<p>	/**<br />
	 * Sets the background based on direction and randomizes the Y position<br />
	 */<br />
	var reset = function() {</p>
<p>		that.el.style.background = &#8216;url(&#8217; + ops.url + &#8217;shark_&#8217; + that.dir + &#8216;.gif)&#8217;;<br />
		that.y = rand(0, (SCREEN_HEIGHT &#8211; SHARK_HEIGHT &#8211; 1));</p>
<p>		plot();</p>
<p>	};</p>
<p>	/**<br />
	 * Starts the move interval<br />
	 */<br />
	that.start = function() {</p>
<p>		if (interval) {<br />
			return;<br />
		}</p>
<p>		interval = setInterval(move, DELAY);</p>
<p>	};</p>
<p>	/**<br />
	 * Stops the move interval<br />
	 */<br />
	that.stop = function() {<br />
		if (interval) {<br />
			clearInterval(interval);<br />
			interval = false;<br />
		}<br />
	};</p>
<p>	init();</p>
<p>};<br />
</textarea></p>
<p>
You can create new sharks like this:
</p>
<p><textarea class="javascript" cols="50" name="code" rows="10"><br />
var myShark = new Shark();</p>
<p>// Or setup some basics, like having him swim to the left<br />
var anotherShark = new Shark({dir : &#8216;l&#8217;});<br />
anotherShark.onclick = function() {<br />
alert(&#8221;I&#8217;m a shaaaaaaark!&#8221;);<br />
myShark.kill(true); // Kill it with a fade<br />
};</p>
<p>// You may also want to host the shark images yourself:<br />
var hostedShark = new Shark({url : &#8216;http://mydomain.com/shark/&#8217;});<br />
</textarea></p>
<p>
The last example above shows setting a custom <acronym title="Uniform Resource Locator">URL</acronym> for the shark images. You can download those here:
</p>
<p>
<a href="/lab/shark/shark_l.gif"><img alt="Shark!" src="/lab/shark/shark_l.gif"/></a><br />
<a href="/lab/shark/shark_r.gif"><img alt="Shark!" src="/lab/shark/shark_r.gif"/></a>
</p>
<p>
<a class="after" href="/lab/shark/"><img alt="Shark!" src="/assets/img/shark_thumbnail.jpg"/></a><br />
There are a few different events you can subscribe to including <code>onclick</code>, <code>onOutLeft</code> and <code>onOutRight</code>, which I think are pretty self-explanatory.<br />
Using these events, I put together <a href="http://scriptnode.com/lab/shark/">a very simple game</a> involving sharks, clicking and hopelessly trying to save a doomed diver. The ocean graphics came from one of my <a href="http://csszengarden.com/?cssfile=http://www.css-praxis.de/cssocean/zenocean.css">favorite CSS Zen Garden examples</a>.
</p>
<p>
The shark script requires <a href="http://developer.yahoo.com/yui/">YUI</a> (Animation, DOM and Event). I&#8217;ve included it in the third download option below:
</p>
<ul>
<li><a href="/assets/js/shark/shark.js">[Download shark.js]</a> (3,747 bytes)</li>
<li><a href="/assets/js/shark/shark-min.js">[Download shark-min.js]</a> (1,550 bytes; compressed)</li>
<li><a href="/assets/js/shark/shark-min-yui.js">[Download shark-min-yui.js]</a> (46k; compressed with YUI)</li>
</ul>
<p>
I&#8217;d love to see if anybody else has cool ideas of what to do with the shark script!
</p>
<p><script src="/assets/js/shark/shark-min-yui.js" type="text/javascript"></script><br />
<script type="text/javascript">
(function() {
new Shark({url : '/lab/shark/'});
new Shark({url : '/lab/shark/'});
})();
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/shark/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Weekly Round-up (Week of 7/13/08)</title>
		<link>http://scriptnode.com/article/weekly-round-up-week-of-71308/</link>
		<comments>http://scriptnode.com/article/weekly-round-up-week-of-71308/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 07:43:30 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[just-for-fun]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[weekly-roundup]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=41</guid>
		<description><![CDATA[
Last week was an amazing week for web development. If you haven&#8217;t heard about these cool new projects, here&#8217;s what you&#8217;ve been missing out on:



The first thing I saw last week was Scott Schiller&#8217;s amazing Experimental dynamic XBM test, favicon &#8220;VU meter&#8221;. He put his very useful Sound Manager 2 flash API to interesting use: [...]]]></description>
			<content:encoded><![CDATA[<p>
Last week was an <strong>amazing</strong> week for web development. If you haven&#8217;t heard about these cool new projects, here&#8217;s what you&#8217;ve been missing out on:
</p>
<p>
<a href="http://schillmania.com/projects/soundmanager2/demo/page-player/xbm-test.html"><img alt="VU meter" class="after" src="/assets/img/2008_7_13_favicon_vu.gif"/></a><br />
The first thing I saw last week was <a href="http://www.schillmania.com/">Scott Schiller&#8217;s</a> amazing <a href="http://schillmania.com/projects/soundmanager2/demo/page-player/xbm-test.html">Experimental dynamic XBM test, favicon &#8220;VU meter&#8221;</a>. He put his <a href="http://scriptnode.com/lab/spacius/">very useful</a> <a href="http://schillmania.com/projects/soundmanager2/">Sound Manager 2</a> flash API to interesting use: the <a href="http://en.wikipedia.org/wiki/Favicon">favicon</a> displayed in many browsers&#8217; tabs and other places is a VU meter of the current song playing. Awesome! So, using that cool premise, what other neat things could be done…
</p>
<p>
<a href="http://www.p01.org/releases/DHTML_contests/files/DEFENDER_of_the_favicon/"><img alt="DEFENDER of the favicon" class="before" src="/assets/img/defender_of_the_favicon.gif"/></a><br />
Enter <a href="http://www.p01.org/">Mathieu &#8216;p01&#8242; Henri&#8217;s</a> super cool <a href="http://www.p01.org/releases/DHTML_contests/files/DEFENDER_of_the_favicon/">DEFENDER of the favicon</a>! This unbelievable game is confined in a tiny <strong>16&#215;16</strong> box, just big enough for your favicon! You can also hit <code>Enter</code> to transfer the game into a <code>canvas</code> element on the page. So creative, so retro, so cool! I&#8217;ve already spent way too much time playing this game, much to the misfortune of my poor squinting eyes.
</p>
<p>
<a href="http://blog.nihilogic.dk/2008/07/house-of-canvas-radiohead-meets.html"><img alt="Radiohead" class="after" src="/assets/img/radiohead_canvas.gif"/></a><br />
Last but never least is the always impressive <a href="http://blog.nihilogic.dk/">Jacob Seidelin</a> with another mind-blowing demo of what <a href="/tag/javascript/">JavaScript</a> is capable of in the right hands. I&#8217;m sorry if it&#8217;s tiring that I keep reposting what Jacob is up to, but as long as he&#8217;s doing incredible things like this, it&#8217;s not gonna stop.
</p>
<p>
You may have already heard about <a href="http://www.radiohead.com/">Radiohead&#8217;s</a> new <a href="http://code.google.com/creative/radiohead/">video hosted on Google Code</a>. If not, here&#8217;s the gist of it:
</p>
<blockquote><p>
No cameras or lights were used.  Instead two technologies were used to capture 3D images: <a href="http://www.geometricinformatics.com/">Geometric Informatics</a> and <a href="http://www.velodyne.com/lidar/">Velodyne LIDAR</a>.  Geometric Informatics scanning systems produce structured light to capture 3D images at close proximity, while a Velodyne Lidar system that uses multiple lasers is used to capture large environments such as landscapes.  In this video, 64 lasers rotating and shooting in a 360 degree radius 900 times per minute produced all the exterior scenes.
</p>
</blockquote>
<p>
Awesome right? Well Jacob saw this as a challenge from Radiohead and did what he does: <a href="http://blog.nihilogic.dk/2008/07/house-of-canvas-radiohead-meets.html">implemented it in JavaScript and canvas</a>. As usual, super cool stuff.
</p>
<p>
Well, this week&#8217;s almost over, so here&#8217;s to hoping that <strong>next</strong> is half as cool as last week was!</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/weekly-round-up-week-of-71308/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spacius! A Space Adventure</title>
		<link>http://scriptnode.com/article/spacius-a-space-adventure/</link>
		<comments>http://scriptnode.com/article/spacius-a-space-adventure/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 19:19:43 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[just-for-fun]]></category>
		<category><![CDATA[lab]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=38</guid>
		<description><![CDATA[



I must have been feeling nostalgic, missing my wasted hours playing old Nintendo games as a kid, because last weekend I put together Spacius! A Space Adventure. My goal was to make a fun, simple game using only JavaScript that would work in any browser. That&#8217;s right folks, this game was made using just div [...]]]></description>
			<content:encoded><![CDATA[<p>
<a href="/lab/spacius/"><img alt="Spacius! A Space Adventure" src="/assets/img/spacius-a-space-adventure/title.gif"/></a>
</p>
<p>
I must have been feeling nostalgic, missing my wasted hours playing <a href="http://gradius.classicgaming.gamespy.com/">old Nintendo games</a> as a kid, because last weekend I put together <a href="/lab/spacius/">Spacius! A Space Adventure</a>. My goal was to make a fun, simple game using only JavaScript that would work in any browser. That&#8217;s right folks, this game was made using just <code>div</code> elements! Really, there&#8217;s nothing hardcore in here that would require <code>canvas</code>, so I guess that shouldn&#8217;t blow any minds. But this game has been tested and works in IE6, IE7, FireFox 2/3, Opera 9.5 and Safari 3.
</p>
<p>
My one cop-out was falling back on flash for the audio, but until all browsers support HTML5 (or some <a href="http://blog.nihilogic.dk/">mad genius</a> makes a JavaScript-only audio player), this is the best I could do. Spacius! uses <a href="http://www.schillmania.com/">Scott Schiller&#8217;s</a> <em>fantastic</em> <a href="http://www.schillmania.com/projects/soundmanager2/">Sound Manager 2</a> to enable sound. There&#8217;s a little latency, but it otherwise works like a charm.
</p>
<p>
<a href="/lab/spacius/"><img alt="Spacius! A Space Adventure" src="/assets/img/spacius-a-space-adventure/screenshot.gif"/></a>
</p>
<p>
One really cool thing about the way Spacius! works is that it takes the shape of its containing element. So it was really trivial to make an <a href="/lab/spacius/?width=800&amp;height=600">800&#215;600 pixel version</a>.
</p>
<p>
<strong>Here&#8217;s how to play:</strong> Press the <strong>space bar</strong> to begin the game. Use the <strong>arrow keys</strong> to move the ship. Once playing, use the <strong>space bar</strong> to shoot balls of excitement. The <strong>S</strong> key toggles sound on/off.
</p>
<p>
There are <strong>six waves</strong> in Spacius!. The last one begins at <strong>10,000 points</strong>, and it&#8217;s <em>really hard</em> so only total badasses will be able to get super high scores (yes, that&#8217;s a challenge).
</p>
<p>
Here are the <acronym title="Unidentified Flying Object">UFO</acronym> scores:
</p>
<p>
<img alt="Bomber" src="/lab/spacius/ufo_bomber.gif"/><br />
<strong>Bomber:</strong> 15 points
</p>
<p>
<img alt="Bogey" src="/lab/spacius/ufo_bogey.gif"/><br />
<strong>Bogey:</strong> 20 points
</p>
<p>
<img alt="Meteor" src="/lab/spacius/ufo_meteor.gif"/><br />
<strong>Meteor:</strong> 50 points
</p>
<p>
<img alt="Death Star" src="/lab/spacius/ufo_ds.gif"/><br />
<strong>&#8220;Death Star&#8221;:</strong> 25 points
</p>
<p>
So what&#8217;re you waiting for?? <a href="/lab/spacius/">PLAY NOW!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/spacius-a-space-adventure/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Bresenham&#8217;s Line Algorithm In JavaScript</title>
		<link>http://scriptnode.com/article/bresenhams-line-algorithm-in-javascript/</link>
		<comments>http://scriptnode.com/article/bresenhams-line-algorithm-in-javascript/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 22:03:40 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[just-for-fun]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[script-sunday]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=37</guid>
		<description><![CDATA[
Today for Script Sunday I implemented Bresenham&#8217;s line algorithm
in the web browser. If you&#8217;ve got JavaScript enabled, you should see a red square in the upper-left hand corner
of the box below.
Clicking anywhere within the box should send the square to that location.



Here&#8217;s the source code:


/**
 * Bresenham&#8217;s line algorithm function
 * by Matt Hackett [scriptnode.com]
 [...]]]></description>
			<content:encoded><![CDATA[<p>
Today for <a href="/tag/script-sunday/">Script Sunday</a> I implemented <a href="http://en.wikipedia.org/wiki/Bresenham's_line_algorithm">Bresenham&#8217;s line algorithm</a><br />
in the web browser. If you&#8217;ve got <a href="/article/how-to-enable-javascript/">JavaScript enabled</a>, you should see a red square in the upper-left hand corner<br />
of the box below.<br />
Clicking anywhere within the box should send the square to that location.
</p>
<div id="example" style="border: 1px dashed #000; height: 200px; margin-bottom: 1em; position: relative;"></div>
<p>
Here&#8217;s the source code:
</p>
<p><textarea class="javascript" cols="50" name="code" rows="10"><br />
/**<br />
 * Bresenham&#8217;s line algorithm function<br />
 * by Matt Hackett [scriptnode.com]<br />
 * @param {Object} el The element to target (accepts both strings for id&#8217;s and element objects themselves)<br />
 * @param {Number} x1 The starting X coordinate<br />
 * @param {Number} y1 The starting Y coordinate<br />
 * @param {Number} x2 The finishing X coordinate<br />
 * @param {Number} y2 The finishing Y coordinate<br />
 * @param {Object} params Additional parameters [delay, onComplete, speed]<br />
 */<br />
var bresenham = function(el, x1, y1, x2, y2, params) {</p>
<p>	var<br />
		interval,<br />
		b,<br />
		m,<br />
		sx,<br />
		y;</p>
<p>	var init = function() {</p>
<p>		var dx, dy, sy;</p>
<p>		// Default parameters<br />
		params = params || {};<br />
		params.delay = params.delay || 10;<br />
		params.onComplete = params.onComplete || function(){};<br />
		params.speed = params.speed || 5;</p>
<p>		// No point in doing anything if we&#8217;re not actually moving<br />
		if ((x1 == x2) &amp;&amp; (y1 == y2)) {<br />
			plot(x1, y);<br />
			params.onComplete();<br />
			return;<br />
		}</p>
<p>		el = ((typeof el === &#8217;string&#8217;) ? document.getElementById(el) : el);</p>
<p>		// Initalize the math<br />
		dx = x2 &#8211; x1;<br />
		sx = (dx &lt; 0) ? -1 : 1;<br />
		dy = y2 &#8211; y1;<br />
		sy = (dy &lt; 0) ? -1 : 1;<br />
		m = dy / dx;<br />
		b = y1 &#8211; (m * x1);</p>
<p>		interval = setInterval(next, params.delay);</p>
<p>	};</p>
<p>	/**<br />
	 * Execute the algorithm and move the element<br />
	*/<br />
	var next = function() {</p>
<p>		y = Math.round((m * x1) + b);<br />
		plot(x1, y);<br />
		x1 += (sx * params.speed);</p>
<p>		if (x1 &gt;= x2) {<br />
			clearInterval(interval);<br />
			params.onComplete();<br />
		}</p>
<p>	};</p>
<p>	/**<br />
	 * Move the target element to the given coordinates<br />
	 * @param float x The horizontal coordinate<br />
	 * @param float y The vertical coordinate<br />
	*/<br />
	var plot = function(x, y) {<br />
		el.style.left = x + &#8216;px&#8217;;<br />
		el.style.top = y + &#8216;px&#8217;;<br />
	};</p>
<p>	init();</p>
<p>};<br />
</textarea></p>
<p>
The parameters are self-explanatory except for the (optional) <code>params</code> object. Here&#8217;s a breakdown:
</p>
<ul>
<li><code>delay</code>: The interval that the <code>setInterval</code> call uses [default: 10]</li>
<li><code>onComplete</code>: An optional function to call when the algorithm is finished</li>
<li><code>speed</code>: How quickly to move the element down the line [default: 5]</li>
</ul>
<p>
I&#8217;m not sure how much use this has in the &#8220;real world&#8221; but it&#8217;s typically pretty neat to see elements dancing around the page,<br />
and I always love to see classic algorithms put to good use.<br />
Enjoy!
</p>
<ul>
<li><a href="/assets/js/bresenhams-line-algorithm/bresenhams-line-algorithm.js">[Download bresenhams-line-algorithm.js]</a> (1,769 bytes)</li>
<li><a href="/assets/js/bresenhams-line-algorithm/bresenhams-line-algorithm-min.js">[Download bresenhams-line-algorithm-min.js]</a> (516 bytes; compressed)</li>
</ul>
<p><script src="/assets/js/bresenhams-line-algorithm/bresenhams-line-algorithm-min.js" type="text/javascript"></script><br />
<script type="text/javascript">
<!--//	
YAHOO.util.Event.onDOMReady(function() {</p>
<p>	var
		busy = false,
		con = document.getElementById('example'),
		el = document.createElement('div'),
		x = 0,
		y = 0;</p>
<p>	el.style.border = '1px solid red';
	el.style.left = '0px';
	el.style.top = '0px';
	el.style.position = 'absolute';
	el.style.width = '25px';
	el.style.height = '25px';</p>
<p>	con.appendChild(el);</p>
<p>	// Listen for the click event
	YAHOO.util.Event.addListener(con, 'click', function(e) {</p>
<p>		if (busy) {
			return;
		}</p>
<p>		var coords = YAHOO.util.Event.getXY(e);
		busy = true;
		x = coords[0] - YAHOO.util.Dom.getX(con);
		y = coords[1] - YAHOO.util.Dom.getY(con);</p>
<p>		bresenham(el, 0, 0, x, y, {
			onComplete : function() {
				busy = false;
			}
		});</p>
<p>	});</p>
<p>});
//-->
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/bresenhams-line-algorithm-in-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
