<?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>The paperCrane's view from the reverseFold &#187; Flash</title>
	<atom:link href="http://www.reversefold.com/blog/category/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reversefold.com/blog</link>
	<description>Flex, PHP, and anything else I care to talk about</description>
	<lastBuildDate>Tue, 30 Aug 2011 08:51:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Life (Cached)</title>
		<link>http://www.reversefold.com/blog/2011/06/22/life-cached/</link>
		<comments>http://www.reversefold.com/blog/2011/06/22/life-cached/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 13:39:39 +0000</pubDate>
		<dc:creator>papercrane</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.reversefold.com/blog/?p=159</guid>
		<description><![CDATA[Sean Cooper recently ran a challenge at Lolapps to create the fastest version of Conway&#8217;s game of life in Flash that we could. Of course, he first showed us his version which uses a convolution filter, but that&#8217;s not what this challenge was about. The idea was to figure out how to make AS3 both [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><a href="http://blog.seantcooper.com/">Sean Cooper</a> recently ran a challenge at <a href="http://www.lolapps.com">Lolapps</a> to create the fastest version of <a href="http://en.wikipedia.org/wiki/Conway's_Game_of_Life">Conway&#8217;s game of life</a> in Flash that we could. Of course, he first showed us <a href="http://blog.seantcooper.com/?p=73">his version</a> which uses a convolution filter, but that&#8217;s not what this challenge was about. The idea was to figure out how to make AS3 both perform and display as fast as possible. Of course I immediately found someone else&#8217;s <a href="http://wonderfl.net/c/3w0l">Pixel Bender version</a> but after playing with that I went my own route to see what I could do in pure AS3.</p>
<p style="text-align: left;">For the impatient, you can <a href="http://www.reversefold.com/life/demo/">view an animation which helps to explain the concept</a> or <a href="http://www.reversefold.com/life/">jump straight to the result</a>.</p>
<p style="text-align: left;">Pretty quickly, the discussion I was a part of moved towards the possibility of caching. After getting the initial naive version of Life finished, I let the caching idea bounce around in my head and finally came up with an idea. Since (basic) life has only two states per pixel, alive or dead, these map trivially to bits. Taking an arbitrary rectangle of the map and reducing it to a simple integer then is easy. Additionally, operations on this section can be done via bitshifting and bitwise operations, which tend to be extremely fast. Unfortunately, the uint in AS3 is only 32 bits long, so this limits the size of the &#8220;chunk&#8221; we can put into a single uint, but then again 2^32 would be a lot of states to possibly store and/or calculate. I also found that if I try to make a Vector.&lt;uint&gt; 2^30 long, Flash hangs, then crashes.</p>
<p style="text-align: left;">Let&#8217;s assume for now that we&#8217;re going to deal with Life in 3&#215;3 cell chunks. I&#8217;ll explain why later on. We&#8217;ll start with a 9&#215;9 set of cells:</p>
<p style="text-align: center;"><div id="attachment_160" class="wp-caption aligncenter" style="width: 294px"><a href="http://www.reversefold.com/life/demo/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/1.png" alt="" title="1" width="284" height="287" class="size-full wp-image-160" /></a><p class="wp-caption-text">A 9x9 section of cells</p></div></p>
<p style="text-align: left;">Then break that up into 3&#215;3 chunks of cells.</p>
<p style="text-align: center;">
<div id="attachment_173" class="wp-caption aligncenter" style="width: 322px"><a href="http://www.reversefold.com/life/demo/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/21.png" alt="" title="2" width="312" height="311" class="size-full wp-image-173" /></a><p class="wp-caption-text">3x3 chunks</p></div>
</p>
<p style="text-align: left;">Let&#8217;s look at the center chunk:</p>
<p style="text-align: center;">
<div id="attachment_174" class="wp-caption aligncenter" style="width: 324px"><a href="http://www.reversefold.com/life/demo/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/31.png" alt="" title="3" width="314" height="316" class="size-full wp-image-174" /></a><p class="wp-caption-text">The center chunk</p></div></p>
<p style="text-align: left;">The simple life rules make each cell depend on its immediate neighbors in every direction.</p>
<ul>
<li>If a cell has less than 2 live neighbors it dies (or stays dead) due to loneliness.</li>
<li>If a cell has 2 live neighbors it stays as it is, dead or alive.</li>
<li>If a cell has 3 live neighbors it is alive in the next iteration (dead cells come alive, live cells stay alive).</li>
<li>If a cell has 4 or more live neighbors it dies of overcrowding.</li>
</ul>
<p>To run these rules for a single cell we need the ring of cells around it to calculate its next state. In the same way, to calculate the next state of a 3&#215;3 set of cells we need the ring around it, making the chunk we need to look at a 5&#215;5 chunk of cells.</p>
<p style="text-align: center;"><div id="attachment_186" class="wp-caption aligncenter" style="width: 170px"><a href="http://www.reversefold.com/life/demo/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/61.png" alt="" title="6" width="160" height="161" class="size-full wp-image-186" /></a><p class="wp-caption-text">5x5</p></div></p>
<p style="text-align: left;">This is what ultimately limits the size of the chunks we can easily cache. 5&#215;5 cells mean we need 25 bits to make them into a uint. 5&#215;6 would make 30 bits and a simple array that big crashes Flash.</p>
<p style="text-align: left;">Now that we&#8217;ve established the basics of what we need it&#8217;s just a matter of figuring out how to efficiently calculate, store, and retrieve the values.</p>
<p style="text-align: left;">We&#8217;ll store the state transitions in a simple vector of uints. The index will be the current state and the value is the next state. For the current state we take the 5&#215;5 chunk, turn the pixels into bits, then put them together to make a uint.</p>
<p style="text-align: center;"><div id="attachment_187" class="wp-caption aligncenter" style="width: 156px"><a href="http://www.reversefold.com/life/demo/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/71.png" alt="" title="7" width="146" height="149" class="size-full wp-image-187" /></a><p class="wp-caption-text">5x5 as bits, the top-left is the least significant bit (2^0)</p></div></p>
<p style="text-align: center;"><div id="attachment_194" class="wp-caption aligncenter" style="width: 560px"><a href="http://www.reversefold.com/life/demo/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/9.png" alt="" title="9" width="550" height="21" class="size-full wp-image-194" /></a><p class="wp-caption-text"> = 9870129</p></div></p>
<p style="text-align: left;">Now we have the center chunk&#8217;s current 5&#215;5 state as a uint. 9870129 will be the index into the state transition map. Now we need the state that this will become after the rules are applied.</p>
<p style="text-align: center;"><div id="attachment_197" class="wp-caption aligncenter" style="width: 168px"><a href="http://www.reversefold.com/life/demo/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/10.png" alt="" title="10" width="158" height="160" class="size-full wp-image-197" /></a><p class="wp-caption-text">The next state</p></div></p>
<p style="text-align: left;">Note that the ring around the 3&#215;3 chunk is all empty. Since what we&#8217;re calculating for is the 3&#215;3, that&#8217;s all we care about. We needed the 5&#215;5 to be able to say what the 3&#215;3 became and in the result we store the uint with only the 3&#215;3 chunk filled out.</p>
<p style="text-align: center;"><div id="attachment_198" class="wp-caption aligncenter" style="width: 150px"><a href="http://www.reversefold.com/life/demo/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/11.png" alt="" title="11" width="140" height="145" class="size-full wp-image-198" /></a><p class="wp-caption-text">Result bits</p></div></p>
<p style="text-align: center;"><div id="attachment_199" class="wp-caption aligncenter" style="width: 560px"><a href="http://www.reversefold.com/life/demo/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/12.png" alt="" title="12" width="550" height="19" class="size-full wp-image-199" /></a><p class="wp-caption-text"> = 4194688</p></div></p>
<p style="text-align: left;">Once this is done for all of the 3&#215;3 chunks, you run it all over again. In order to get the 5&#215;5 you can mask out the bits needed in the neighbors, bitshift them, and bitwise-or them together to get the 5&#215;5 uint to index back into the state transition map. To speed things up even more you can store those masked and bitshifted parts separately so all you need to do is bitwise-or them together to find out what the next state is.</p>
<p style="text-align: left;">If you made it this far, thanks for reading. Here again is a link to <a href="http://www.reversefold.com/life/demo/">the explanatory demo</a>, which is where the screenshots above came from.</p>
<p style="text-align: left;">And, finally, the result. The fastest Life implementation I&#8217;ve made thus far. :-) You can press &#8216;r&#8217; to switch to another pattern (try resizing to 1440&#215;599) and then again to get a random start state. &#8216;p&#8217; pauses the animation. Enjoy!</p>
<p style="text-align: center;"><div id="attachment_202" class="wp-caption aligncenter" style="width: 567px"><a href="http://www.reversefold.com/life/"><img src="http://www.reversefold.com/blog/wp-content/uploads/2011/06/life.png" alt="" title="life" width="557" height="501" class="size-full wp-image-202" /></a><p class="wp-caption-text">Click to view the completed application</p></div></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.reversefold.com/blog/2011/06/22/life-cached/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java-style Typesafe Enumerations in AS3: Round 2</title>
		<link>http://www.reversefold.com/blog/2010/12/23/java-style-typesafe-enumerations-in-as3-round-2/</link>
		<comments>http://www.reversefold.com/blog/2010/12/23/java-style-typesafe-enumerations-in-as3-round-2/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 12:11:54 +0000</pubDate>
		<dc:creator>papercrane</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.reversefold.com/blog/?p=152</guid>
		<description><![CDATA[After creating my first Enum class for AS3 I found out that Flash was behaving unexpectedly when running the static initializations. Unfortunately, the order of the static declarations isn&#8217;t always the order in which Flash runs them. In a simple example with just a few classes I found that the initialization order was the same [...]]]></description>
			<content:encoded><![CDATA[<p>After creating my first Enum class for AS3 I found out that Flash was behaving unexpectedly when running the static initializations. Unfortunately, the order of the static declarations isn&#8217;t always the order in which Flash runs them. In a simple example with just a few classes I found that the initialization order was the same as the order of the declarations in the file, hence causing the generated ordinal values to be in the defined order, just like in Java. However, in a more complicated application the order became somewhat random, causing the ordinal values to not match what they might be in Java. In the case where you don&#8217;t care what the ordinal values are, (i.e. you use the names for storage or network communication or are only using the static vars directly in code) you don&#8217;t need to worry about this. However, if you want to use the ordinal values then you&#8217;ll have to go back to specifying the ordinal values manually. However, this Enum class still gets you a lot more than just static ints. The type safety alone is worth it in my opinion. Without further ado, the updated class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">reversefold</span>.<span style="color: #006600;">util</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">errors</span>.<span style="color: #006600;">IllegalOperationError</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Dictionary</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">describeType</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">getQualifiedClassName</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * An abstract class to emulate Enum type.
	 * 
	 * Subclasses should follow this pattern:
	 * 
	 * package com.example {
	 * 	public class TestEnum extends Enum {
	 * 		public static const ONE : TestEnum = new TestEnum(1);
	 * 		public static const TWO : TestEnum = new TestEnum(2);
	 * 		public static const THREE : TestEnum = new TestEnum(3);
	 * 		
	 * 		public static function get values() : Vector.&lt;testenum&gt; {
	 * 			return Vector.&lt;/testenum&gt;&lt;testenum&gt;(Enum.getValues(TestEnum));
	 * 		}
	 * 		
	 * 		{
	 * 			initEnumConstant(TestEnum);
	 * 		}
	 * 	}
	 * }
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Enum <span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> sequence : Dictionary = <span style="color: #000000; font-weight: bold;">new</span> Dictionary<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * To protect from instantiation after static initializing.
		 */</span>
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> values : Dictionary = <span style="color: #000000; font-weight: bold;">new</span> Dictionary<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//.&lt;vector .&lt;Enum&gt;&gt;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> valuesByName : Dictionary = <span style="color: #000000; font-weight: bold;">new</span> Dictionary<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//.&lt;object&gt;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Function to call for each enum type declared and in static init.
		 */</span>
		protected <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> initEnumConstant<span style="color: #66cc66;">&#40;</span>inType : <span style="color: #000000; font-weight: bold;">Class</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> className : <span style="color: #0066CC;">String</span> = getQualifiedClassName<span style="color: #66cc66;">&#40;</span>inType<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> typeXML : <span style="color: #0066CC;">XML</span> = describeType<span style="color: #66cc66;">&#40;</span>inType<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> newValues : Vector.<span style="color: #66cc66;">&lt;</span>enum<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;/</span>enum<span style="color: #66cc66;">&gt;&lt;</span>enum<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> newValuesByName : <span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
			<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> constantXML : <span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> typeXML.<span style="color: #006600;">constant</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span> : <span style="color: #0066CC;">String</span> = constantXML.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">name</span>;
				<span style="color: #000000; font-weight: bold;">var</span> constant : Enum = inType<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#93;</span>;
				constant._label = <span style="color: #0066CC;">name</span>;
				newValues.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>constant<span style="color: #66cc66;">&#41;</span>;
				newValuesByName<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">name</span>.<span style="color: #0066CC;">toUpperCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> = constant;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #808080; font-style: italic;">//sort by ordinal</span>
			values<span style="color: #66cc66;">&#91;</span>className<span style="color: #66cc66;">&#93;</span> = newValues.<span style="color: #0066CC;">sort</span><span style="color: #66cc66;">&#40;</span>
				<span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>lhs : Enum, rhs : Enum<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #b1b100;">return</span> lhs._ordinal <span style="color: #66cc66;">&gt;</span> rhs._ordinal ? <span style="color: #cc66cc;">1</span> : <span style="color: #66cc66;">&#40;</span>lhs._ordinal <span style="color: #66cc66;">&lt;</span> rhs._ordinal ? -<span style="color: #cc66cc;">1</span> : <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#41;</span>;
			valuesByName<span style="color: #66cc66;">&#91;</span>className<span style="color: #66cc66;">&#93;</span> = newValuesByName;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getValues<span style="color: #66cc66;">&#40;</span>inType : <span style="color: #000000; font-weight: bold;">Class</span><span style="color: #66cc66;">&#41;</span> : Vector.<span style="color: #66cc66;">&lt;</span>Enum<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> Vector.<span style="color: #66cc66;">&lt;/</span>enum<span style="color: #66cc66;">&gt;&lt;</span>enum<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span>values<span style="color: #66cc66;">&#91;</span>getQualifiedClassName<span style="color: #66cc66;">&#40;</span>inType<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getByName<span style="color: #66cc66;">&#40;</span>inType : <span style="color: #000000; font-weight: bold;">Class</span>, inName : <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> : Enum <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> Enum<span style="color: #66cc66;">&#40;</span>valuesByName<span style="color: #66cc66;">&#91;</span>getQualifiedClassName<span style="color: #66cc66;">&#40;</span>inType<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span>inName.<span style="color: #0066CC;">toUpperCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getByOrdinal<span style="color: #66cc66;">&#40;</span>inType : <span style="color: #000000; font-weight: bold;">Class</span>, inOrdinal : <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span> : Enum <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> values : Vector.<span style="color: #66cc66;">&lt;/</span>enum<span style="color: #66cc66;">&gt;&lt;</span>enum<span style="color: #66cc66;">&gt;</span> = getValues<span style="color: #66cc66;">&#40;</span>inType<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>inOrdinal <span style="color: #66cc66;">&gt;</span>= values.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;There is no enum value for ordinal &quot;</span> + inOrdinal + <span style="color: #ff0000;">&quot; in class &quot;</span> + getQualifiedClassName<span style="color: #66cc66;">&#40;</span>inType<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> values<span style="color: #66cc66;">&#91;</span>inOrdinal<span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Enum label.
		 */</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _label : <span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> label<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _label;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _ordinal : uint;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> ordinal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : uint <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _ordinal;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Enum<span style="color: #66cc66;">&#40;</span>inOrdinal : <span style="color: #0066CC;">int</span> = -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> className : <span style="color: #0066CC;">String</span> = getQualifiedClassName<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>values<span style="color: #66cc66;">&#91;</span>className<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Cannot instantiate anymore: &quot;</span> + className<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>inOrdinal == -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> seq : uint;
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>sequence<span style="color: #66cc66;">&#91;</span>className<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					seq = <span style="color: #cc66cc;">0</span>;
				<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
					seq = sequence<span style="color: #66cc66;">&#91;</span>className<span style="color: #66cc66;">&#93;</span> + <span style="color: #cc66cc;">1</span>;
				<span style="color: #66cc66;">&#125;</span>
				_ordinal = seq;
				sequence<span style="color: #66cc66;">&#91;</span>className<span style="color: #66cc66;">&#93;</span> = seq;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
				_ordinal = inOrdinal;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> ordinal + <span style="color: #ff0000;">&quot; &quot;</span> + label;
		<span style="color: #66cc66;">&#125;</span> 
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&lt;/</span>enum<span style="color: #66cc66;">&gt;&lt;/</span>object<span style="color: #66cc66;">&gt;&lt;/</span>vector<span style="color: #66cc66;">&gt;&lt;/</span>testenum<span style="color: #66cc66;">&gt;</span></pre></div></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.reversefold.com/blog/2010/12/23/java-style-typesafe-enumerations-in-as3-round-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More Fractal Letters</title>
		<link>http://www.reversefold.com/blog/2009/02/10/more-fractal-letters/</link>
		<comments>http://www.reversefold.com/blog/2009/02/10/more-fractal-letters/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 19:16:03 +0000</pubDate>
		<dc:creator>papercrane</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Fractal]]></category>

		<guid isPermaLink="false">http://www.reversefold.com/blog/?p=123</guid>
		<description><![CDATA[I&#8217;ve continued adding bits to my fractal letters over the past few weeks and have finally finished everything to print out my full e-mail address. The @ symbol was particularly interesting and I think it turned out pretty nice. The pictures link to the updated app. Enjoy, and as usual, don&#8217;t slide the slider up [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve continued adding bits to my <a title="Fractal Letters" href="http://www.reversefold.com/blog/2009/01/20/fractal-letters/">fractal letters</a> over the past few weeks and have finally finished everything to print out my full e-mail address. The @ symbol was particularly interesting and I think it turned out pretty nice.</p>
<div id="attachment_125" class="wp-caption aligncenter" style="width: 560px"><img class="size-full wp-image-125" title="Fractal Email - first iteration" src="http://www.reversefold.com/blog/wp-content/uploads/2009/02/fractal_email_11.png" alt="fractal_email_11" width="550" height="298" /><p class="wp-caption-text">Fractal Email - first iteration</p></div>
<p style="text-align: left;">
<div id="attachment_127" class="wp-caption aligncenter" style="width: 560px"><img class="size-full wp-image-127" title="Fractal Email - third iteration" src="http://www.reversefold.com/blog/wp-content/uploads/2009/02/fractal_email_3.png" alt="Fractal Email - third iteration" width="550" height="295" /><p class="wp-caption-text">Fractal Email - third iteration</p></div>
<div id="attachment_128" class="wp-caption aligncenter" style="width: 560px"><img class="size-full wp-image-128" title="Fractal Email - fifth iteration" src="http://www.reversefold.com/blog/wp-content/uploads/2009/02/fractal_email_5.png" alt="Fractal Email - fifth iteration" width="550" height="294" /><p class="wp-caption-text">Fractal Email - fifth iteration</p></div>
<p>The pictures link to the updated app. Enjoy, and as usual, don&#8217;t slide the slider up to the max unless you&#8217;re willing to wait while your entire browser hangs for several minutes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.reversefold.com/blog/2009/02/10/more-fractal-letters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fractal Letters</title>
		<link>http://www.reversefold.com/blog/2009/01/20/fractal-letters/</link>
		<comments>http://www.reversefold.com/blog/2009/01/20/fractal-letters/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 08:08:23 +0000</pubDate>
		<dc:creator>papercrane</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexBuilder]]></category>
		<category><![CDATA[Fractal]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[l-system]]></category>

		<guid isPermaLink="false">http://www.reversefold.com/blog/?p=116</guid>
		<description><![CDATA[On the way home last Thursday I decided to try creating fractal letters. The idea was to replace each &#8220;line&#8221; in a simple version of a letter with a copy of itself but allow for the aspect ratio of its dimensions to change so that the result is still recognizable as a letter. This is [...]]]></description>
			<content:encoded><![CDATA[<p>On the way home last Thursday I decided to try creating fractal letters. The idea was to replace each &#8220;line&#8221; in a simple version of a letter with a copy of itself but allow for the aspect ratio of its dimensions to change so that the result is still recognizable as a letter. This is something like an <a title="L-system" href="http://en.wikipedia.org/wiki/L-system">L-system</a>, of which the <a title="Dragon curve" href="http://en.wikipedia.org/wiki/Dragon_curve">Dragon curve</a> is one. After a weekend&#8217;s worth of work I have what amounts to thirteen different fractal letter algorithms for six different letters. 1 P, 3 A, 2 E, 2 R, 2 C, 3 N. Yes, those spell PAPERCRANE. Here is the first iteration (just the letters).</p>
<div id="attachment_117" class="wp-caption alignnone" style="width: 510px"><a href="http://www.reversefold.com/flex/fractalLetters/"><img class="size-full wp-image-117" title="Fractal Letters, iteration 1" src="http://www.reversefold.com/blog/wp-content/uploads/2009/01/fractalletters_1.png" alt="Fractal Letters, iteration 1" width="500" height="234" /></a><p class="wp-caption-text">Fractal Letters, iteration 1</p></div>
<p>And here is the fifth iteration:</p>
<div id="attachment_118" class="wp-caption alignnone" style="width: 510px"><a href="http://www.reversefold.com/flex/fractalLetters/"><img class="size-full wp-image-118" title="Fractal Letters, iteration 5" src="http://www.reversefold.com/blog/wp-content/uploads/2009/01/fractalletters_5.png" alt="Fractal Letters, iteration 5" width="500" height="251" /></a><p class="wp-caption-text">Fractal Letters, iteration 5</p></div>
<p>Some letters have variations in how they are drawn or how they repeat, or both (hence the 2 lines). The bottom N uses an algorithm I worked out which didn&#8217;t change the aspect ratio and had only one repetition per line. Both of the N variants in the words use two repetitions per line and constrict the width faster than the height, which leaves the N recognizable. The idea here, after all, was to make letters which had a cool fractal look but could still be read.</p>
<p>Click either of the pictures to view the flex app and play with the iterations yourself. Just drag (or click on) the slider on the bottom of the app to change the iteration.</p>
<p>Stay tuned, I have another blog post coming up soon specifically about that N on the bottom, the math required to create the algorithm, and some interesting (and beautiful) results I got when implementing a test program.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.reversefold.com/blog/2009/01/20/fractal-letters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Falling Away</title>
		<link>http://www.reversefold.com/blog/2008/10/28/falling-away/</link>
		<comments>http://www.reversefold.com/blog/2008/10/28/falling-away/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 18:33:06 +0000</pubDate>
		<dc:creator>papercrane</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[bitmapdata]]></category>
		<category><![CDATA[flash 10]]></category>

		<guid isPermaLink="false">http://www.reversefold.com/wordpress/?p=49</guid>
		<description><![CDATA[I had a new idea last night on my way home for a simple use of Flash 10&#8242;s 3D to do a simple visualization. Imagine that you are looking down at the ground from high up. Suddenly the screen falls away and starts falling to the ground. Then the ground you were looking at falls [...]]]></description>
			<content:encoded><![CDATA[<p>I had a new idea last night on my way home for a simple use of Flash 10&#8242;s 3D to do a simple visualization. Imagine that you are looking down at the ground from high up. Suddenly the screen falls away and starts falling to the ground. Then the ground you were looking at falls away and you rezlize that it was only a screen. Repeat.</p>
<p><a href="http://www.reversefold.com/flash/falling_away/"><img class="alignnone" title="Falling Away Screenshot" src="http://www.reversefold.com/flash/falling_away/screenshot.jpg" alt="" width="440" height="331" /></a></p>
<p>This screenshot shows the app running with a flickr satellite photo feed displaying on each falling plane. Unfortunately, since my code uses <tt>BitmapData.draw()</tt>, this won&#8217;t work from the web as I don&#8217;t want to run a flickr proxy. The linked version simply colors the planes, but you can get the idea from it. Right click the movie to view its code. If you run it locally with <tt>USE_FLICKR = true</tt> you can see the full effect.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.reversefold.com/blog/2008/10/28/falling-away/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash 10 Camp, 3D, Sound Creation, and IK</title>
		<link>http://www.reversefold.com/blog/2008/10/12/flash-10-camp-3d-sound-creation-and-ik/</link>
		<comments>http://www.reversefold.com/blog/2008/10/12/flash-10-camp-3d-sound-creation-and-ik/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 04:54:02 +0000</pubDate>
		<dc:creator>papercrane</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[flash 10]]></category>
		<category><![CDATA[flashcamp]]></category>
		<category><![CDATA[ik]]></category>
		<category><![CDATA[sound]]></category>

		<guid isPermaLink="false">http://www.reversefold.com/wordpress/?p=45</guid>
		<description><![CDATA[I&#8217;ve just come home from Flash(10)Camp and am winding down. I had a lot of fun, saw some coll stuff, and even won Best Audio (with my team) with our app Flash Tones. I was actually very surprised, there were a lot of well done apps, including others that generated sound but I guess we [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just come home from <a title="FlashCamp" href="http://www.flashcamp.org/">Flash(10)Camp</a> and am winding down. I had a lot of fun, saw some coll stuff, and even won Best Audio (with my team) with our app <a title="Flash Tones" href="http://www.reversefold.com/flashCamp/flashTones/">Flash Tones</a>.</p>
<p><a href="http://www.reversefold.com/flashCamp/flashTones/"><img class="alignnone" title="Flash Tones" src="http://www.reversefold.com/flashCamp/flashTones/screenshot.png" alt="" width="438" height="318" /></a></p>
<p>I was actually very surprised, there were a lot of well done apps, including others that generated sound but I guess we just had the app polished well enough. Thanks to Rod for that, he gave us the last few bits that really made it look nice. You&#8217;ll need Flash Player 10 and a web cam if you want to try it out.</p>
<p>All of the features I saw in Flash Player 10 were ones I&#8217;d seen before, except for the sound generation. Things were more in depth and better put together this time, though. The sound generation is nice, but complicated and hard to make it do what you&#8217;re expecting. Of course, I&#8217;m assuming you know almost nothing about the specifics of sound, like I do.</p>
<p>IK is fun, but I I focused on the other 2 as I didn&#8217;t have any IK idea that seemed particularly interesting.</p>
<p>The 3D is very nice, being able to move and rotate objects in all three dimensions opens up a lot of new possibilities. I had a lot of fun creating some simple squares and rotating them, then applying various blend modes and filters. Here are 2 of my favorites:</p>
<p><a href="http://www.reversefold.com/flashCamp/knockoutSquares/"><img class="alignnone" title="Knockout Squares" src="http://www.reversefold.com/flashCamp/knockoutSquares/screenshot.png" alt="" width="437" height="316" /></a></p>
<p><a href="http://www.reversefold.com/flashCamp/redSquares/"><img class="alignnone" title="Red Squares" src="http://www.reversefold.com/flashCamp/redSquares/screenshot.png" alt="" width="435" height="318" /></a></p>
<p>Those were fun but then someone mentioned webcams. I successfully connected up webcam video to my project and then spent several hours getting the video mapped to each of the rotating squares then getting it all matched up with the video behind it. I then added edge detection (thanks to <a title="Sobel Edge Detection" href="http://lukewalsh.co.uk/blog/2008/06/sobel-edge-detection-in-flash.html">Luke Walsh&#8217;s post</a>), added some more blending and filters and voila!</p>
<p><a href="http://www.reversefold.com/flashCamp/blueSquares/"><img class="alignnone" title="Blue Squares" src="http://www.reversefold.com/flashCamp/blueSquares/screenshot.png" alt="" width="437" height="316" /></a></p>
<p>I was quite proud of that and still think it looks cool. I wish I&#8217;d shown it earlier at the Hackathon but then again we won an award so I guess I&#8217;m just being greedy.</p>
<p>As an added bonus, here&#8217;s an earlier version of Flash Tones which warbled in an interesting way. Try putting your hand up at the very right edge of the screen.</p>
<p><a href="http://www.reversefold.com/flashCamp/flashTones/warble/"><img class="alignnone" title="Warbling Flash Tones" src="http://www.reversefold.com/flashCamp/flashTones/warble/screenshot.png" alt="" width="437" height="317" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.reversefold.com/blog/2008/10/12/flash-10-camp-3d-sound-creation-and-ik/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

