<?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>STRd6</title>
	<atom:link href="http://strd6.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://strd6.com</link>
	<description>It is beyond anything you have ever experienced or imagined</description>
	<lastBuildDate>Sun, 15 Apr 2012 20:02:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Weekly Recap of 1 Hour Daily Game Jams</title>
		<link>http://strd6.com/2012/04/weekly-recap-of-1-hour-daily-game-jams/</link>
		<comments>http://strd6.com/2012/04/weekly-recap-of-1-hour-daily-game-jams/#comments</comments>
		<pubDate>Sun, 15 Apr 2012 19:50:00 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Game Development]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=959</guid>
		<description><![CDATA[@mdiebolt and I review our daily 1 hour game jams over the past week. Audio levels in games are still too loud. First 30 Days: Week ending 04-14-2012: I find that doing these 1 hour jams every day really helps to focus my game design skills. Who&#8217;d have thought that practicing something for at least&#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="https://twitter.com/#!/mdiebolt">@mdiebolt</a> and I review our daily 1 hour game jams over the past week. Audio levels in games are still too loud.</p>
<p>First 30 Days:</p>
<p><iframe width="500" height="375" src="http://www.youtube.com/embed/asskcaLMg0o?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>Week ending 04-14-2012:</p>
<p><iframe width="500" height="375" src="http://www.youtube.com/embed/asskcaLMg0o?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>I find that doing these 1 hour jams every day really helps to focus my game design skills. Who&#8217;d have thought that practicing something for at least an hour every day will make you better at it? Now when Ludum Dare rolls around 48 hours will seem like a 2 year dev cycle.</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2012/04/weekly-recap-of-1-hour-daily-game-jams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Function#debounce Useful JavaScript Game Extension #36</title>
		<link>http://strd6.com/2011/11/function-debounce-useful-javascript-game-extension-36/</link>
		<comments>http://strd6.com/2011/11/function-debounce-useful-javascript-game-extension-36/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 02:56:45 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[256 JavaScript Game Extensions]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=953</guid>
		<description><![CDATA[I got this from Underscore.js. ###* Calling a debounced function will postpone its execution until after wait milliseconds have elapsed since the last time the function was invoked. Useful for implementing behavior that should only happen after the input has stopped arriving. For example: rendering a preview of a Markdown comment, recalculating a layout after&#8230;]]></description>
			<content:encoded><![CDATA[<p>I got this from <a href="http://documentcloud.github.com/underscore/#debounce">Underscore.js</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="coffeescript" style="font-family:monospace;">###*
Calling a debounced function will postpone its execution until after 
wait milliseconds have elapsed since the last time the function was 
invoked. Useful for implementing behavior that should only happen after 
the input has stopped arriving. For example: rendering a preview of a 
Markdown comment, recalculating a layout after the window has stopped 
being resized...
&nbsp;
lazyLayout = calculateLayout.debounce(300)
$(window).resize(lazyLayout)
&nbsp;
@name debounce
@methodOf Function#
@returns {Function} The debounced version of this function.
###
Function::debounce = (wait) -&gt;
  timeout = null
  func = this
&nbsp;
  return -&gt;
    context = this
    args = arguments
&nbsp;
    later = -&gt;
      timeout = null
      func.apply(context, args)
&nbsp;
    clearTimeout(timeout)
    timeout = setTimeout(later, wait)</pre></div></div>

<p>Already I can see an important use for it. In the code editor we copy out the buffer every keyup. This can lead to a bunch of extra work for the browser when typing. Usually it&#8217;s not a big deal because the files are generally small, but on larger files it can add up and cause some lagging. When using debounce the editor will only trigger after enough milliseconds have elapsed since the end of new keyup events. This will keep the IDE from lagging on larger files while you are typing.</p>
<p>Another place debounce is useful is in a game that implements a Halo style health regeneration. Every time the player takes damage a debounced <code>startRegen</code> function could be called. That way the regen will only start after enough time without taking damage has elapsed. In the game version it would probably be better to constrain it to ticks of the engine, or engine elapsed time for more accuracy.</p>
<p>I&#8217;m always a big fan of <code>Function</code> functions, they are a great way to reduce boilerplate and solve higher-order problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2011/11/function-debounce-useful-javascript-game-extension-36/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Array#pipeline Useful JavaScript Game Extension #35</title>
		<link>http://strd6.com/2011/11/arraypipeline-useful-javascript-game-extension-35/</link>
		<comments>http://strd6.com/2011/11/arraypipeline-useful-javascript-game-extension-35/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 22:10:38 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[256 JavaScript Game Extensions]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=947</guid>
		<description><![CDATA[###* Pipe the input through each function in the array in turn. For example, if you have a list of objects you can perform a series of selection, sorting, and other processing methods and then receive the processed list. This array must contain functions that accept a single input and return the processed input. The&#8230;]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="coffeescript" style="font-family:monospace;">###*
Pipe the input through each function in the array in turn. For example, if you have
a list of objects you can perform a series of selection, sorting, and other 
processing methods and then receive the processed list. This array must contain 
functions that accept a single input and return the processed input. The output of
the first function is fed to the input of the second and so on until the final
processed output is returned.
&nbsp;
@name pipeline
@methodOf Array#
&nbsp;
@param {Object} input The initial input to pass to the first function in the pipeline.
@returns {Object} The result of processing the input by each function in the array.
###
Array::pipeline = (input) -&gt;
  for fn in this
    input = fn(input)
&nbsp;
  return input</pre></div></div>

<p>The main use for this is in the PixieEngine cameras module where we need to process the camera transform with a stream of modifiers. This also allows for the game objects list to be z-sorted, filtered to a subset that passes a clip test, or any other arbitrary stream filter.</p>
<p>I think this is probably some sort of fundamental concept of functional programming, but I&#8217;m not sure if `pipeline` is the right name. If anyone has historic info on this please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2011/11/arraypipeline-useful-javascript-game-extension-35/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 JavaScript Pasting Image Data in Chrome</title>
		<link>http://strd6.com/2011/09/html5-javascript-pasting-image-data-in-chrome/</link>
		<comments>http://strd6.com/2011/09/html5-javascript-pasting-image-data-in-chrome/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 08:10:47 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=929</guid>
		<description><![CDATA[Pasting anything other than simple text into the browser has historically been stupendously impossible. Until now&#8230; It&#8217;s a miracle, image data pasted into the browser can be retrieved with JavaScript (at least since Chrome 13.0.782.220)! Just use this jQuery plugin and start receiving paste events with images all their sweet gooey image data. This picks&#8230;]]></description>
			<content:encoded><![CDATA[<p>Pasting anything other than simple text into the browser has historically been stupendously impossible. Until now&#8230; It&#8217;s a miracle, image data pasted into the browser can be retrieved with JavaScript (at least since Chrome 13.0.782.220)! Just use this jQuery plugin and start receiving paste events with images all their sweet gooey image data. This picks up paste events initiated with <code>Ctrl+V</code>, it does not provide arbitrary clipboard access (which is probably sane from a security standpoint). What&#8217;s insane is that it used to be so hard to get pasted image data, but that is all behind us now.</p>
<div id="attachment_938" class="wp-caption alignleft" style="width: 42px"><img src="http://strd6.com/wp-content/uploads/2011/09/wizard.png" alt="A magical wizard" title="wizard" width="32" height="32" class="size-full wp-image-938" /><p class="wp-caption-text">Copy and paste me in this webpage!</p></div>
<p>Give it a try now, right click this wizard and choose &#8220;Copy Image&#8221;, then jam <code>Ctrl+V</code> or <code>Command+V</code>. Be amazed (unless you&#8217;re not using Chrome, and in that case, get off my lawn). It also works in the pixel editor on <a href="http://pixieengine.com/pixel-editor" title="PixieEngine Pixel Editor" target="_blank">PixieEngine</a>. Use the wizard there too, the editor currently only handles small images. Generally there is no size restriction, you can even paste image data from your favorite image editing programs, boot one up and try it out on this page.</p>

<div class="wp_syntax"><div class="code"><pre class="coffeescript" style="font-family:monospace;"># Created by STRd6
# MIT License
# jquery.paste_image_reader.js.coffee
(($) -&gt;
  # Make sure paste events get clipboard data
  $.event.fix = ((originalFix) -&gt;
    (event) -&gt;
      event = originalFix.apply(this, arguments)
&nbsp;
      if event.type.indexOf('copy') == 0 || event.type.indexOf('paste') == 0
        event.clipboardData = event.originalEvent.clipboardData
&nbsp;
      return event
  )($.event.fix)
&nbsp;
  defaults =
    callback: $.noop
    matchType: /image.*/
&nbsp;
  # Create the plugin
  # To use it: $(&quot;html&quot;).pasteImageReader callback
  $.fn.pasteImageReader = (options) -&gt;
    if typeof options == &quot;function&quot;
      options =
        callback: options
&nbsp;
    options = $.extend({}, defaults, options)
&nbsp;
    # Listen to paste events on each element in the selector
    this.each () -&gt;
      element = this
      $this = $(this)
&nbsp;
      $this.bind 'paste', (event) -&gt;
        found = false
        clipboardData = event.clipboardData
&nbsp;
        # Loop through all types the data can be pasted as until 
        # we hit an image type
        Array::forEach.call clipboardData.types, (type, i) -&gt;
          return if found
          return unless type.match(options.matchType)
&nbsp;
          # Get the corresponding file data
          file = clipboardData.items[i].getAsFile()
&nbsp;
          # Read the file data and fire off the callback with
          # the useful stuff when it's been read
          reader = new FileReader()
          reader.onload = (evt) -&gt;
            options.callback.call element,
              filename: file.name
              dataURL: evt.target.result
&nbsp;
          reader.readAsDataURL(file)
&nbsp;
          # We found an image, we're done
          found = true
&nbsp;
)(jQuery)</pre></div></div>

<p>Pretty simple plugin, eh? The first part is extending the copy and paste events in jQuery with the clipboardData object. Once the paste events have been extended with all the clipboard data that Chrome provides we can use that data to extract the image contents.</p>
<p>The meat of the plugin is binding a paste event to all the elements in the selector. When a paste event is triggered we loop through each MIME type until we hit one that claims to be an image. Once we find it we get the corresponding file data and load it as a dataURL. This can be used directly in CSS or passed on to the server and chopped up, base64 decoded, and stored as a regular png.</p>
<p>To use it you choose what element to listen to paste events on (html should get all of them). I haven&#8217;t messed around much with scoping it to other elements, but I don&#8217;t see why it wouldn&#8217;t work.</p>

<div class="wp_syntax"><div class="code"><pre class="coffeescript" style="font-family:monospace;">$(&quot;html&quot;).pasteImageReader (results) -&gt;
  {filename, dataURL} = results
&nbsp;
  $(&quot;body&quot;).css
    backgroundImage: &quot;url(#{dataURL})&quot;</pre></div></div>

<p>Now when someone pastes a copied image to the page it sets the background to the pasted image. This is just scratching the surface, but the great thing is that you can now capture paste events containing images in pure JS/HTML.</p>
<p>What&#8217;s that? CoffeeScript is hot for you to handle? Well here&#8217;s the JS version:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Created by STRd6</span>
<span style="color: #006600; font-style: italic;">// MIT License</span>
<span style="color: #006600; font-style: italic;">// jquery.paste_image_reader.js</span>
<span style="color: #009900;">&#40;</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>
  <span style="color: #003366; font-weight: bold;">var</span> defaults<span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">event</span>.<span style="color: #660066;">fix</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>originalFix<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      event <span style="color: #339933;">=</span> originalFix.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">type</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'copy'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> event.<span style="color: #660066;">type</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'paste'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        event.<span style="color: #660066;">clipboardData</span> <span style="color: #339933;">=</span> event.<span style="color: #660066;">originalEvent</span>.<span style="color: #660066;">clipboardData</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000066; font-weight: bold;">return</span> event<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">event</span>.<span style="color: #660066;">fix</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    callback<span style="color: #339933;">:</span> $.<span style="color: #660066;">noop</span><span style="color: #339933;">,</span>
    matchType<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/image.*/</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">pasteImageReader</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> options <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;function&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        callback<span style="color: #339933;">:</span> options
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> defaults<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</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>
      <span style="color: #003366; font-weight: bold;">var</span> $this<span style="color: #339933;">,</span> element<span style="color: #339933;">;</span>
      element <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
      $this <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      $this.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'paste'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> clipboardData<span style="color: #339933;">,</span> found<span style="color: #339933;">;</span>
        found <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        clipboardData <span style="color: #339933;">=</span> event.<span style="color: #660066;">clipboardData</span><span style="color: #339933;">;</span>
&nbsp;
        Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">forEach</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>clipboardData.<span style="color: #660066;">types</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #003366; font-weight: bold;">var</span> file<span style="color: #339933;">,</span> reader<span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>found<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
&nbsp;
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>type.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">matchType</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
&nbsp;
          file <span style="color: #339933;">=</span> clipboardData.<span style="color: #660066;">items</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getAsFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          reader <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> FileReader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          reader.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            options.<span style="color: #660066;">callback</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
              filename<span style="color: #339933;">:</span> file.<span style="color: #000066;">name</span><span style="color: #339933;">,</span>
              dataURL<span style="color: #339933;">:</span> evt.<span style="color: #660066;">target</span>.<span style="color: #660066;">result</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
          reader.<span style="color: #660066;">readAsDataURL</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          found <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><script>
// Created by STRd6
// MIT License
// jquery.paste_image_reader.js
(function($) {
  var defaults;
  $.event.fix = (function(originalFix) {
    return function(event) {
      event = originalFix.apply(this, arguments);
      if (event.type.indexOf('copy') === 0 || event.type.indexOf('paste') === 0) {
        event.clipboardData = event.originalEvent.clipboardData;
      }
      return event;
    };
  })($.event.fix);
  defaults = {
    callback: $.noop,
    matchType: /image.*/
  };
  $.fn.pasteImageReader = function(options) {
    if (typeof options === "function") {
      options = {
        callback: options
      };
    }
    options = $.extend({}, defaults, options);
    return this.each(function() {
      var $this, element;
      element = this;
      $this = $(this);
      $this.bind('paste', function(event) {
        var clipboardData, found;
        found = false;
        clipboardData = event.clipboardData;
        Array.prototype.forEach.call(clipboardData.types, function(type, i) {
          var file, reader;
          if (found) {
            return;
          }
          if (!type.match(options.matchType)) {
            return;
          }
          file = clipboardData.items[i].getAsFile();
          reader = new FileReader();
          reader.onload = function(evt) {
            options.callback.call(element, {
              filename: file.name,
              dataURL: evt.target.result
            });
          };
          reader.readAsDataURL(file);
          found = true;
        });
      });
    });
  };
})(jQuery);
jQuery("html").pasteImageReader(function(results) {
  var dataURL, filename;
  filename = results.filename, dataURL = results.dataURL;
  _gaq.push("_trackEvent", "Special", "HTML5 Paste", filename);
  return jQuery("#page").css({
    backgroundImage: "url(" + dataURL + ")",
    backgroundRepeat: "repeat"
  });
});
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2011/09/html5-javascript-pasting-image-data-in-chrome/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaScript Number#even and Number#odd, Useful JavaScript Game Extensions #33 and #34</title>
		<link>http://strd6.com/2011/08/javascript-number-even-and-number-odd-useful-javascript-game-extensions-33-and-34/</link>
		<comments>http://strd6.com/2011/08/javascript-number-even-and-number-odd-useful-javascript-game-extensions-33-and-34/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 22:07:26 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[256 JavaScript Game Extensions]]></category>
		<category><![CDATA[coffeescript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=923</guid>
		<description><![CDATA[Wow, it&#8217;s been a while! But enough with the small talk, time for some more simple JavaScript extensions! ###* Returns true if this number is even (evenly divisible by 2). &#160; @name even @methodOf Number# &#160; @type Boolean @returns true if this number is an even integer, false otherwise. ### Number::even = -&#62; this %&#8230;]]></description>
			<content:encoded><![CDATA[<p>Wow, it&#8217;s been a while! But enough with the small talk, time for some more simple JavaScript extensions!</p>

<div class="wp_syntax"><div class="code"><pre class="coffeescript" style="font-family:monospace;">###*
Returns true if this number is even (evenly divisible by 2).
&nbsp;
@name even
@methodOf Number#
&nbsp;
@type Boolean
@returns true if this number is an even integer, false otherwise.
###
Number::even = -&gt;
  this % 2 == 0
&nbsp;
###*
Returns true if this number is odd (has remainder of 1 when divided by 2).
&nbsp;
@name odd
@methodOf Number#
&nbsp;
@type Boolean
@returns true if this number is an odd integer, false otherwise.
###
Number::odd = -&gt;
  if this &gt; 0
    this % 2 == 1
  else
    this % 2 == -1</pre></div></div>

<p>These are just a couple of simple methods so you can do things like <code>if exponent.even()</code> to make code quite a bit more readable. The only trick is for <code>Number#odd</code>, due to the way the default mod operator works in JavaScript it would be a pain to check if a negative number were odd without this helper.</p>
<p>Stay tuned for the next 222 parts of the series!</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2011/08/javascript-number-even-and-number-odd-useful-javascript-game-extensions-33-and-34/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boomstick &#8211; Hella Joysticks in JavaScript</title>
		<link>http://strd6.com/2011/07/boomstick-hella-joysticks-in-javascript/</link>
		<comments>http://strd6.com/2011/07/boomstick-hella-joysticks-in-javascript/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 22:37:33 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=919</guid>
		<description><![CDATA[Hey! I know that you want to use joysticks and gamepads in your HTML/JavaScript games, so what are you waiting for? Check out Boomstick and give it a shot. This cross-platform, multi-browser extension gives JavaScript access to all joysticks on all platforms. Pretty rad. Right now I&#8217;m having great results with it in my game&#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/STRd6/Boomstick/wiki"><img src="http://strd6.com/wp-content/uploads/2011/07/unnamed.png" alt="Boomstick!" title="Joystick Icon" width="128" height="128" class="alignleft size-full wp-image-920" /></a></p>
<p>Hey! I know that you want to use joysticks and gamepads in your HTML/JavaScript games, so what are you waiting for? Check out <a href="https://github.com/STRd6/Boomstick/wiki">Boomstick</a> and give it a shot.</p>
<p>This cross-platform, multi-browser extension gives JavaScript access to all joysticks on all platforms. Pretty rad.</p>
<p>Right now I&#8217;m having great results with it in my game <a href="http://pixieengine.com/projects/166/fullscreen">Red Ice</a>. It can support up to 8 joysticks straight away, so don&#8217;t worry.</p>
<p>If you use any browser on Windows, then run the <a href="https://github.com/downloads/STRd6/Boomstick/windows_install.zip">Windows installer</a>.</p>
<p>If you&#8217;re using Chrome on any OS, bust out the <a href="https://chrome.google.com/webstore/detail/ibghgpidpbpnhdgmncpbhioaohmgkigo?hl=en-US">Chrome Extension</a></p>
<p>Once you&#8217;ve got it plug in a joystick and check out the <a href="https://github.com/STRd6/Boomstick/blob/master/README.md">readme</a> for how to access joystick data. Or you could just start developing on <a href="http://pixieengine.com/">PixieEngine</a> which has libraries for joystick handling built in.</p>
<p>But at any rate, use it, abuse it, and let me know what awesome games you make (also if you encounter any bugs or issues.)</p>
<p>Peace!</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2011/07/boomstick-hella-joysticks-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing Matrix and Point Classes in PixieEngine</title>
		<link>http://strd6.com/2011/07/optimizing-matrix-and-point-classes-in-pixieengine/</link>
		<comments>http://strd6.com/2011/07/optimizing-matrix-and-point-classes-in-pixieengine/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 19:21:04 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[coffeescript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=914</guid>
		<description><![CDATA[I was able to go a long way without optimizing the Matrix and Point classes. Since most of my games and prototypes were relatively simple or made limited use of points and matrices it didn&#8217;t matter too much, that is until Red Ice, which was using 5 physics steps per frame and computing tons of&#8230;]]></description>
			<content:encoded><![CDATA[<p>I was able to go a long way without optimizing the Matrix and Point classes. Since most of my games and prototypes were relatively simple or made limited use of points and matrices it didn&#8217;t matter too much, that is until Red Ice, which was using 5 physics steps per frame and computing tons of vectors and collision responses.</p>
<p><strong>Optimizing the Drawing</strong></p>
<p>The problems became evident in the profiler. First was the classic of &#8220;draw less&#8221;. Because Red Ice is running at 1024&#215;768 even clearing the entire canvas can get costly, not to mention copying over the ice and blood canvases to the main one. In order to break through this bottleneck I separated out the rink/background and blood canvases into layers that stay below the main canvas. Since the rink never redraws and since the blood only adds and erases strokes in a semi-permanent way, this saves copying a ton of image data to the main canvas, which in turn saves a ton of time. I still clear the entire main canvas every frame, but implementing selective clearing is a big project and would have limited performance gains (we still need to clear big chunks of the canvas most updates with all the stuff moving around).</p>
<p><strong>Optimizing Joystick Input</strong></p>
<p>Now that we are drawing less the next big bottleneck came from joystick input. This sounds pretty ridiculous for anyone coming from a non-web background, but considering that using 6 XBox 360 controllers as input into an HTML5 game was pretty much unheard of, it&#8217;s not inconceivable that the first time it has been done might not be the most optimal. The core of the issue was that every single piece of data that is transferred from the native extension into JavaScript slows things down. Even something as simple as an array of true/false values for buttons. Even an array of six integers for six axes. Even an object with two properties <code>buttons</code> and <code>axes</code>. Each single piece slows things down. </p>
<p>The first performance improvement I made was to use a single integer for all the buttons, holding each one in a bit. This gave an immediate 25% speedup, confirming that going from an array of 10 booleans to 1 integer (reducing the number of items passed across) speeds things up. Next, since I wasn&#8217;t using the additional 4 axes I decided to only pass 2 axes as a temporary fix. This also gave a decent speedup, especially at the 6 controller mark, because each additional controller was additional data. </p>
<p>At this point I was stumped for a while, but then I realized that if I could pass a single JSON string across that would only be a single item of data, no matter how many joysticks or axes were active. I assumed that browsers were pretty good at parsing JSON, since that is most of what the JavaScript interpreter does on all web pages, and after a day of struggling getting C++ to spit out JSON it was legit and joystick input was no longer an issue.</p>
<p><strong>Optimizing the Points</strong></p>
<p>This finally exposed the remaining problems of the <code>Point</code> class and garbage collection being the next bottle neck. Due to all the physics updates and point computations it was creating tons of new Point objects and each additional point operation created more because the operations were non-destructive. The good news is that I have a full test suite for the Point class, so that I can refactor and optimize without any fear. This was quite valuable when testing crazy new ideas to see if they would improve performance without breaking everything. I figured that since I was creating so many points that if I added optional destructive methods, and used them in the right places, that could reduce the new point creation and also GC load quite a bit.</p>
<p>I wish that JavaScript or CoffeeScript would allow for a shortcut to use <code>!</code> as a method suffix like in Ruby, because it is a known convention for destructive methods. The closest I could come would be <code>point["add!"](otherPoint)</code>, which was too brutal on the mind and eyes to make it into common usage. If CoffeeScript could auto-compile <code>point.add!(otherPoint)</code> into the index-operator notation like it does with <code>a.class</code> and <code>a.new</code> then it would be okay, but until then the <code>!</code> suffix is out.</p>
<p>JavaScript does allow for the <code>$</code> symbol in variable and method names so, by necessity, I have chosen to use <code>$</code> as the glyph of destruction, which has its own poetry in a way. <code>point.add$(otherPoint)</code> not bad, but not my first choice.</p>
<p>Now, armed with new destructive methods, I set about looking for places in the physics and collisions where I could slip them in to prevent the creation of unwanted/unused points. Then a funny thing happened, the majority of the places I looked needed the operators to be non-destructive, and it was difficult to see exactly where a destructive method could be added without unwanted side-effects except in a few simple situations such as <code>point = point.add$(delta) => point.add$(delta)</code>.</p>
<p>While I was cleaning up the Point code I was thinking about <a href="https://github.com/em/matrix.js/commit/6ca4eaa8049c1d1581f87b8b23339dccc7043c33">a conversation I had on GitHub</a> about the performance benefits from using prototype inheritance rather than object augmentation. This sounded like a good idea in this case, as <code>Point</code>s are primitive objects with their <code>x</code> and <code>y</code> properties on the outside and all of their methods using <code>this</code> everywhere. The one sticking point was that I could not abide having to stick <code>new</code> in front of the point constructor in ten thousand places in my existing and future code. If only there was some way to get the advantages of prototype performance, without pushing the syntactic hassles onto the people using the class.</p>
<p>The good news is that there is a way to set an objects prototype. All you need to do is to set the <code>__proto__</code> property. So now my <code>Point</code> constructor looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="coffeescript" style="font-family:monospace;">  Point = (x, y) -&gt;
    __proto__: Point::
    x: x || 0
    y: y || 0</pre></div></div>

<p>You know you&#8217;ve been programming in the browser too long when <code>__proto__: Point::</code> becomes a thing of beauty.</p>
<p>All the instance methods are defined below as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="coffeescript" style="font-family:monospace;">  Point:: =
    copy: -&gt;
      Point(this.x, this.y)
&nbsp;
    add: (first, second) -&gt;
      this.copy().add$(first, second)
&nbsp;
    add$: (first, second) -&gt;
      if second?
        this.x += first
        this.y += second
      else
        this.x += first.x
        this.y += first.y
&nbsp;
      this
&nbsp;
    ...</pre></div></div>

<p>This gives all the performance benefits of using prototypes rather than making an anonymous function for every method as well as the additional side benefit that developers can extend <code>Point.prototype</code> with additional methods for use in their own projects if they want to. Another advantage is that the syntax remains unchanged, no need to use the <code>new</code> operator, and all the tests still pass.</p>
<p>The best news is that this provides a 90% reduction in time that the code spends constructing and garbage collecting points, and was simple enough to pull into the <code>Matrix</code> class with a two line change as well. For primitive objects like Points, Matrixes, Arrays, Numbers, and the like I wholeheartedly recommend this approach. For complex objects that require mixins, private variables, and instance variables I don&#8217;t think it will be possible because each object actually does need it&#8217;s own functions that are in the correct closure scope.</p>
<p>Another interesting thing is that this last optimization voided the assumption of my previous one about destructive operators. I assumed that because creating points was expensive it would be worthwhile to go to extra lengths to prevent their creation unnecessarily. Using the prototypesque construction the cost of point creation and garbage collection was reduced so much that it&#8217;s not worth it to try and squeeze out the now slight performance gains that would produce except in the hottest inner loops. I&#8217;ll still keep the destructive methods around for situations where points actually want to be updated in place, like <code>p = p.norm(speed) => p.norm$(speed)</code>, but I won&#8217;t be quick to begin trying to &#8220;optimize&#8221; by defaulting to using destructive methods and then spend hours debugging issues that come up because two objects are actually sharing the same point reference. </p>
<p>Points are cheap now, use them freely!</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2011/07/optimizing-matrix-and-point-classes-in-pixieengine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 Audio In Chrome</title>
		<link>http://strd6.com/2011/06/html5-audio-in-chrome/</link>
		<comments>http://strd6.com/2011/06/html5-audio-in-chrome/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 22:19:14 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Internet Adventures]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=911</guid>
		<description><![CDATA[Remember how the HTML5 audio tag used to be terrible and crash the whole browser? Or a few months later when it would only play intermittently or with 2000ms latency? Well with some recent updates (Google Chrome 13.0.782.32 beta) now the audio tag works perfectly! Just thought I&#8217;d share the news in case you guys&#8230;]]></description>
			<content:encoded><![CDATA[<p>Remember how the HTML5 audio tag used to be terrible and crash the whole browser? Or a few months later when it would only play intermittently or with 2000ms latency? Well with some recent updates (Google Chrome 13.0.782.32 beta) now the audio tag works perfectly!</p>
<p>Just thought I&#8217;d share the news in case you guys <a href="http://pixieengine.com">wanted to make some games</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2011/06/html5-audio-in-chrome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Operator Overloading in PaperScript</title>
		<link>http://strd6.com/2011/06/operator-overloading-in-paperscript/</link>
		<comments>http://strd6.com/2011/06/operator-overloading-in-paperscript/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 23:31:15 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Internet Adventures]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=903</guid>
		<description><![CDATA[I was looking into how paper.js did their operator overloading and what I found was pretty clever: var operators = &#123; '+': 'add', '-': 'subtract', '*': 'multiply', '/': 'divide', '%': 'modulo', '==': 'equals', '!=': 'equals' &#125;; &#160; function $eval&#40;left, operator, right&#41; &#123; var handler = operators&#91;operator&#93;; if &#40;left &#38;&#38; left&#91;handler&#93;&#41; &#123; var res = left&#91;handler&#93;&#40;right&#41;;&#8230;]]></description>
			<content:encoded><![CDATA[<p>I was looking into how paper.js did their operator overloading and what I found was pretty clever:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> operators <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">'+'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'add'</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'-'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'subtract'</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'*'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'multiply'</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'/'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'divide'</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'%'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'modulo'</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'=='</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'equals'</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'!='</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'equals'</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> $eval<span style="color: #009900;">&#40;</span>left<span style="color: #339933;">,</span> operator<span style="color: #339933;">,</span> right<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> handler <span style="color: #339933;">=</span> operators<span style="color: #009900;">&#91;</span>operator<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>left <span style="color: #339933;">&amp;&amp;</span> left<span style="color: #009900;">&#91;</span>handler<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> res <span style="color: #339933;">=</span> left<span style="color: #009900;">&#91;</span>handler<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span>right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> operator <span style="color: #339933;">==</span> <span style="color: #3366CC;">'!='</span> <span style="color: #339933;">?</span> <span style="color: #339933;">!</span>res <span style="color: #339933;">:</span> res<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>operator<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'+'</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> left <span style="color: #339933;">+</span> right<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'-'</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> left <span style="color: #339933;">-</span> right<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'*'</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> left <span style="color: #339933;">*</span> right<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'/'</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> left <span style="color: #339933;">/</span> right<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'%'</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> left <span style="color: #339933;">%</span> right<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'=='</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> left <span style="color: #339933;">==</span> right<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'!='</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> left <span style="color: #339933;">!=</span> right<span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
    <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #003366; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Implement Operator: '</span> <span style="color: #339933;">+</span> operator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Though technically this is PaperScript and not JavaScript, so they can get around the lack of native JS operator overloading. The PaperScript code is given a minimal compile pass which replaces calls to arithmetic operators with calls to <code>$eval()</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// PaperScript</span>
<span style="color: #003366; font-weight: bold;">var</span> p <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Point<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> p <span style="color: #339933;">*</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// JavaScript</span>
<span style="color: #003366; font-weight: bold;">var</span> p <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Point<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> $eval<span style="color: #009900;">&#40;</span>p<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;*&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><a href="https://github.com/paperjs/paper.js/blob/master/src/core/PaperScript.js">Related PaperScript source</a></p>
<p>So as long as Point#multiply is defined then the operator is effectively overloaded.</p>
<p>I&#8217;m very interested in the implications for PixieEngine and CoffeeScript.</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2011/06/operator-overloading-in-paperscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Array::eachPair A useful method for interacting each element of an array with another (#32)</title>
		<link>http://strd6.com/2011/06/arrayeachpair-a-useful-method-for-interacting-each-element-of-an-array-with-another/</link>
		<comments>http://strd6.com/2011/06/arrayeachpair-a-useful-method-for-interacting-each-element-of-an-array-with-another/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 17:00:18 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[256 JavaScript Game Extensions]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=897</guid>
		<description><![CDATA[I&#8217;ve got this classic n2 collision detection code and I wanted to separate out all the iteration business into its own place. So I spent a long time trying to figure out the name for the method, searching around in case anyone had anything similar. I finally found it each_pair, which is exactly what I&#8230;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve got this classic n<sup>2</sup> collision detection code and I wanted to separate out all the iteration business into its own place. So I spent a long time trying to figure out the name for the method, searching around in case anyone had anything similar. I finally found it <a href="http://www.codeodor.com/index.cfm/2007/12/3/Arrayeach_pair/1784">each_pair</a>, which is exactly what I wanted. The each implies iteration, and we are iterating over each possible pair of items from the array.</p>

<div class="wp_syntax"><div class="code"><pre class="coffeescript" style="font-family:monospace;">###*
Call the given iterator once for each pair of objects in the array.
&nbsp;
Ex. [1, 2, 3, 4].eachPair (a, b) -&gt;
  # 1, 2
  # 1, 3
  # 1, 4
  # 2, 3
  # 2, 4
  # 3, 4 
&nbsp;
@name eachPair
@methodOf Array#
@param {Function} iterator Function to be called once for 
each pair of elements in the array.
@param {Object} [context] Optional context parameter to be 
used as `this` when calling the iterator function.
###
Array::eachPair = (iterator, context) -&gt;
  length = this.length
  i = 0
  while i &lt; length
    a = this[i]
    j = i + 1
    i += 1
&nbsp;
    while j &lt; length
      b = this[j]
      j += 1
&nbsp;
      iterator.call context, a, b</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2011/06/arrayeachpair-a-useful-method-for-interacting-each-element-of-an-array-with-another/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

