<?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>mostly a codeBlog &#187; AS3</title>
	<atom:link href="http://www.rickigregersen.com/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rickigregersen.com</link>
	<description>whatever I am currently programming... and I truly digress</description>
	<lastBuildDate>Mon, 21 Jun 2010 15:40:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>SporeTree</title>
		<link>http://www.rickigregersen.com/2009/08/11/sporetree/</link>
		<comments>http://www.rickigregersen.com/2009/08/11/sporetree/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 21:21:02 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[spore]]></category>
		<category><![CDATA[tree]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=193</guid>
		<description><![CDATA[This time the spores turned into a tree. It is by no means perfect, the branches does not move upwards with the stem as it should, were this a real orange colored scary spore tree. This was just some &#8220;while Im doing nothing, let&#8217;s put whatever in the &#8216;fun&#8217; category&#8221; but if anyone would like [...]]]></description>
			<content:encoded><![CDATA[<p>This time the <a href="http://www.rickigregersen.com/?paged=2">spores</a> turned into a tree. It is by no means perfect, the branches does not move upwards with the stem as it should, were this a real orange colored scary spore tree.</p>
<p>This was just some &#8220;while Im doing nothing, let&#8217;s put whatever in the &#8216;fun&#8217; category&#8221; <img src='http://www.rickigregersen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  but if anyone would like the code, throw me a comment and I&#8217;ll send it off. I is uncommented and messy.</p>
<p><object width="512" height="750" data="http://www.rickigregersen.com/wp-content/uploads/BitmapSporeGrowingTree.swf" type="application/x-shockwave-flash"><param name="quality" value="high" /><param name="scale" value="exactfit" /><param name="salign" value="l" /><param name="wmode" value="transparent" /><param name="src" value="http://www.rickigregersen.com/wp-content/uploads/BitmapSporeGrowingTree.swf" /></object></h4>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2009/08/11/sporetree/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>RandomWalk</title>
		<link>http://www.rickigregersen.com/2009/08/06/randomwalk/</link>
		<comments>http://www.rickigregersen.com/2009/08/06/randomwalk/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 18:32:55 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Particle]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[flash builder 4]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=180</guid>
		<description><![CDATA[Im looking into some of the random walk stuff out there and I stumbled upon www.actionsnippet.com and his RandomWalk experiments, great site by the way, bring coffee. The thing that was cool about his way of doing it was that he constrains the &#8220;walkers&#8221; to only move: up, down, left and right. Absolutely no diagonal [...]]]></description>
			<content:encoded><![CDATA[<p>Im looking into some of the random walk stuff out there and I stumbled upon <a href="http://www.actionsnippet.com">www.actionsnippet.com</a> and his RandomWalk experiments, great site by the way, bring coffee.<br />
The thing that was cool about his way of doing it was that he constrains the &#8220;walkers&#8221; to only move: up, down, left and right. Absolutely no diagonal movement. This produces a strange grid looking pattern.</p>
<p><object width="512" height="512" data="http://www.rickigregersen.com/wp-content/uploads/RandomWalk.swf" type="application/x-shockwave-flash"><param name="quality" value="high" /><param name="scale" value="exactfit" /><param name="salign" value="l" /><param name="wmode" value="transparent" /><param name="src" value="http://www.rickigregersen.com/wp-content/uploads/RandomWalk.swf" /></object></h4>
<p>The code:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">/*&lt;pre lang=&quot;actionscript&quot;&gt;*/</span><br />
<span style="color: #11740a; font-style: italic;">//playing around with something Zevan Rosser from http://actionsnippet.com/?p=1236 did</span><br />
<span style="color: #11740a; font-style: italic;">//on his blog</span><br />
<br />
<span style="display:block;background-color:#ffff66">package <span style="color: #002200;">&#123;</span><br /></span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; import flash.display.<span style="color: #002200;">*</span>;<br />
<span style="display:block;background-color:#ffff66">&nbsp; &nbsp; import flash.events.<span style="color: #002200;">*</span>;<br /></span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>SWF<span style="color: #002200;">&#40;</span> width<span style="color: #002200;">=</span><span style="color: #bf1d1a;">&quot;512&quot;</span>, height <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">&quot;512&quot;</span>, backgroundColor <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">&quot;0x222222&quot;</span>, frameRate <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">&quot;120&quot;</span> <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; public class RandomWalk extends Sprite <br />
<span style="display:block;background-color:#ffff66">&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br /></span>&nbsp; &nbsp; &nbsp; &nbsp; private var _canvas<span style="color: #002200;">:</span>BitmapData;<br />
&nbsp; &nbsp; &nbsp; &nbsp; private var _count<span style="color: #002200;">:</span><span style="color: #a61390;">int</span> <span style="color: #002200;">=</span> <span style="color: #2400d9;">100</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; private var _movers<span style="color: #002200;">:</span>Vector.&lt;Mover&gt;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; public function RandomWalk<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var w<span style="color: #002200;">:</span>Number <span style="color: #002200;">=</span> <span style="color: #2400d9;">512</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var h<span style="color: #002200;">:</span>Number <span style="color: #002200;">=</span> <span style="color: #2400d9;">512</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scaleX<span style="color: #002200;">=</span>scaleY <span style="color: #002200;">=</span> <span style="color: #2400d9;">0.25</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _canvas <span style="color: #002200;">=</span> new BitmapData<span style="color: #002200;">&#40;</span> w <span style="color: #002200;">*</span> <span style="color: #2400d9;">4</span>, h <span style="color: #002200;">*</span> <span style="color: #2400d9;">4</span>, <span style="color: #a61390;">false</span>, 0x222222 <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #002200;">&#40;</span> new Bitmap<span style="color: #002200;">&#40;</span> _canvas <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _movers <span style="color: #002200;">=</span> new Vector.&lt;Mover&gt;<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span> var i<span style="color: #002200;">:</span><span style="color: #a61390;">int</span> <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; _count; i<span style="color: #002200;">++</span> <span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _movers<span style="color: #002200;">&#91;</span> i <span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> new Mover<span style="color: #002200;">&#40;</span> _canvas, w <span style="color: #002200;">*</span> <span style="color: #2400d9;">1.5</span> <span style="color: #002200;">+</span> Math.random<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> w, h <span style="color: #002200;">*</span> <span style="color: #2400d9;">1.5</span> <span style="color: #002200;">+</span> Math.random<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> h <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addEventListener<span style="color: #002200;">&#40;</span> Event.ENTER_FRAME, onRun <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; private function onRun<span style="color: #002200;">&#40;</span> evt<span style="color: #002200;">:</span>Event <span style="color: #002200;">&#41;</span><span style="color: #002200;">:</span><span style="color: #a61390;">void</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>var i<span style="color: #002200;">:</span><span style="color: #a61390;">int</span> <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #2400d9;">200</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>var j<span style="color: #002200;">:</span><span style="color: #a61390;">int</span> <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; j &lt; _count; j<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _movers<span style="color: #002200;">&#91;</span> j <span style="color: #002200;">&#93;</span>.run<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
import flash.display.BitmapData;<br />
class Mover <br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; public var x<span style="color: #002200;">:</span>Number;<br />
&nbsp; &nbsp; public var y<span style="color: #002200;">:</span>Number;<br />
&nbsp; &nbsp; public var velX<span style="color: #002200;">:</span>Number;<br />
&nbsp; &nbsp; public var velY<span style="color: #002200;">:</span>Number;<br />
&nbsp; &nbsp; public var speed<span style="color: #002200;">:</span>Number;<br />
&nbsp; &nbsp; private var _canvas<span style="color: #002200;">:</span>BitmapData;<br />
&nbsp; &nbsp; private var _color<span style="color: #002200;">:</span>uint;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; public function Mover<span style="color: #002200;">&#40;</span> canvas<span style="color: #002200;">:</span>BitmapData, xp<span style="color: #002200;">:</span>Number, yp<span style="color: #002200;">:</span>Number <span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _color <span style="color: #002200;">=</span> 0xFF6600;<span style="color: #11740a; font-style: italic;">//Math.random() * 0xFFFFFF;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _canvas <span style="color: #002200;">=</span> canvas;<br />
&nbsp; &nbsp; &nbsp; &nbsp; x <span style="color: #002200;">=</span> xp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #002200;">=</span> yp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; velX <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; velY <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; speed<span style="color: #002200;">=</span>Math.random<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">5</span> <span style="color: #002200;">-</span> <span style="color: #2400d9;">2.5</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; public function run<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">:</span><span style="color: #a61390;">void</span> <br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; x <span style="color: #002200;">+=</span> velX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #002200;">+=</span> velY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; _canvas.setPixel<span style="color: #002200;">&#40;</span> x, y, _color <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; var dir<span style="color: #002200;">:</span>Number <span style="color: #002200;">=</span> <span style="color: #a61390;">int</span><span style="color: #002200;">&#40;</span> Math.random<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">4</span> <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>dir <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velX <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velY <span style="color: #002200;">=-</span> speed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>dir <span style="color: #002200;">==</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velX <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velY <span style="color: #002200;">=</span> speed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>dir <span style="color: #002200;">==</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velX <span style="color: #002200;">=-</span> speed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velY <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>dir <span style="color: #002200;">==</span> <span style="color: #2400d9;">3</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velX <span style="color: #002200;">=</span> speed;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velY <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">/*&lt;/pre&gt;*/</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2009/08/06/randomwalk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Homegrown Tentacles</title>
		<link>http://www.rickigregersen.com/2009/08/06/homegrown-tentacles/</link>
		<comments>http://www.rickigregersen.com/2009/08/06/homegrown-tentacles/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 18:03:40 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Particle]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[Filters]]></category>
		<category><![CDATA[flash builder 4]]></category>
		<category><![CDATA[fun]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=173</guid>
		<description><![CDATA[I had been scurrying about over on the Soulwire blog, again, and looking at the tentacles. I did some experiments of my own, but the tentacles never came out right, not organic enough. I wrote Justin and asked him how he did it and he was really cool about helping out with a code example [...]]]></description>
			<content:encoded><![CDATA[<p>I had been scurrying about over on the Soulwire blog, again, and looking at the tentacles. I did some experiments of<br />
my own, but the tentacles never came out right, not organic enough. I wrote Justin and asked him how he did it and he was really cool about helping out with a code example of how he did that part.</p>
<p>The Soulwire Tentacles was an experiment in PixelBender speed and usability, so he makes it look as if the tentacles are really growing, i.e. starts out small and each &#8220;joint&#8221; grows as the tentacles grows. Mine is just a look into the random-organic way they grow. Also I was trying to see what kinds of speed I would get by using the Bitmap approach.</p>
<p>Here are the <a href="http://blog.soulwire.co.uk/flash/actionscript-3/pixel-bender-growing-tentacles/">Soulwire Tentacles</a></p>
<p>And here are my Tentacles&#8230; that came out wrong&#8230; <img src='http://www.rickigregersen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><object width="512" height="512" data="http://www.rickigregersen.com/wp-content/uploads/BitmapSpore.swf" type="application/x-shockwave-flash"><param name="quality" value="high" /><param name="scale" value="exactfit" /><param name="salign" value="l" /><param name="wmode" value="transparent" /><param name="src" value="http://www.rickigregersen.com/wp-content/uploads/BitmapSpore.swf" /></object></h4>
<p>The code:</p>
<pre lang="actionscript">
/**
*
 * @BitmapSpore.as	:	inspired by http://blog.soulwire.co.uk/flash/actionscript-3/pixel-bender-growing-tentacles/
 * @Date  08/06-09
 * @Ricki Gregersen
*/

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;

	[SWF( width="512", height = "512", backgroundColor = "0x222222", frameRate = "30" )]

	public class BitmapSpore extends Sprite
	{
		private static var fading : ColorTransform = new ColorTransform( 1, 1, 1, 0.99999 );
		private static var _blur : BlurFilter = new BlurFilter( 1, 1, 2 );

		private var _bmd:BitmapData;
		private var _bmp:Bitmap;
		private var _container:Sprite;

		public function BitmapSpore()
		{
			_bmd = new BitmapData( 512, 512, true, 0x222222 );
			_bmp = new Bitmap( _bmd );
			addChild( _bmp );
			var s:Spore;
			addChild( _container = new Sprite() );
			for( var i:int = 0; i < 500; i++ )
			{
				s = new Spore( 256, 256, range( 0.01, 0.05 ), range( 2.0, 3.0 ), range( 0.2, 1.0 ));
				s.scaleX = s.scaleY = Math.random() * 2;
				_container.addChild( s );
			}
			addEventListener( Event.ENTER_FRAME, update );
		}

		private function update( event:Event ):void
		{
			var n:int = _container.numChildren;
			var s:Spore;

			for( var i:int = 0; i < n; i++ )
			{
				s = Spore( _container.getChildAt( i ));
				s.move();
				s.x = s.loc.x;
				s.y = s.loc.y;
			}
			_bmp.filters = [  _blur ];
			_bmd.colorTransform( _bmd.rect, fading );
			_bmd.draw( _container );
		}

		private function range(min:Number, max:Number = NaN):Number
		{
			if(isNaN(max)) {max = min; min = 0}
				return min + (Math.random() * (max - min));
		} 

	}
}
	import flash.geom.Point;
	import flash.display.Shape;

	class Spore extends Shape
	{
		public var loc:Point;

		private var angStep:Number;
		private var posStep:Number;
		private var curl:Number;
		private var n:Number = 0;
		private var a:Number = Math.random() * Math.PI * 2;

		function Spore( xPos:Number, yPos:Number, aStep:Number, pStep:Number, c:Number )
		{
			loc = new Point( xPos, yPos );
			angStep = aStep;
			posStep = pStep;
			curl = c;
			graphics.lineStyle( 0, 0x222222, 0.7 );
			graphics.beginFill( 0xFF6600, 0.7 );
			graphics.drawCircle( 0, 0, 5 );
			graphics.endFill();
		}
		public function move():void
		{
			n += Math.random() * (angStep - -angStep) + -angStep;
			n *= 0.9 + curl * 0.1;
			a += n;
			loc.x += Math.cos( a ) * posStep;
			loc.y += Math.sin( a ) * posStep;
			this.scaleX = this.scaleY *= 0.98;
			var s:Number = this.scaleX = this.scaleY;
			if( s < 0.1 )
			{
				loc.x = loc.y = 256;
				this.scaleX = this.scaleY = Math.random() * 2;
			}
		}
	}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2009/08/06/homegrown-tentacles/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Perlin Noise used to drive vector flow field</title>
		<link>http://www.rickigregersen.com/2009/06/20/perlin-noise-used-to-drive-vector-flow-field/</link>
		<comments>http://www.rickigregersen.com/2009/06/20/perlin-noise-used-to-drive-vector-flow-field/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 12:07:12 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[flash builder 4]]></category>
		<category><![CDATA[flow field]]></category>
		<category><![CDATA[noise]]></category>
		<category><![CDATA[Perlin]]></category>
		<category><![CDATA[vectors]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=166</guid>
		<description><![CDATA[This post is essentially the same as <a href="http://www.rickigregersen.com/?p=159#content">this one</a>, only difference is that a BitmapData.perlinNoise() is used instead of the BitmapData.draw(video) to produce a background that influences the flow field.]]></description>
			<content:encoded><![CDATA[<p>This post is essentially the same as <a href="http://www.rickigregersen.com/?p=159#content">this one</a>, only difference is that a BitmapData.perlinNoise() is used instead of the BitmapData.draw(video) to produce a background that influences the flow field.</p>
<p>I have not posted the code to this one because the two are so similar, but if anyone want me to, just leave a comment and I&#8217;ll get right on posting it:) or send it to you.</p>
<p><object width="490" height="550" data="http://www.rickigregersen.com/wp-content/uploads/VectorFlowField02.swf" type="application/x-shockwave-flash"><param name="quality" value="medium" /><param name="scale" value="exactfit" /><param name="salign" value="l" /><param name="wmode" value="transparent" /><param name="src" value="http://www.rickigregersen.com/wp-content/uploads/VectorFlowField02.swf" /></object></h4>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2009/06/20/perlin-noise-used-to-drive-vector-flow-field/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Evil &amp; Loud Perlin noise</title>
		<link>http://www.rickigregersen.com/2009/05/28/evil-loud-perlin-noise/</link>
		<comments>http://www.rickigregersen.com/2009/05/28/evil-loud-perlin-noise/#comments</comments>
		<pubDate>Thu, 28 May 2009 18:42:54 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[noise]]></category>
		<category><![CDATA[Perlin]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=122</guid>
		<description><![CDATA[In regards to my previous Perlin Flowfield post, it was a bit strange because I could simply not remember the basics about Perlin noise. Yes, as my colleague I falsely believed Perlin to be the evil brother of Merlin. I have previously used Perlin noise in Processing, it is a bit different in some of [...]]]></description>
			<content:encoded><![CDATA[<p>In regards to my previous <a href="http://www.rickigregersen.com/?p=93#content">Perlin Flowfield</a> post, it was a bit strange because I could simply not remember the basics about Perlin noise. Yes, as my colleague I falsely believed Perlin to be the evil brother of Merlin.</p>
<p>I have previously used Perlin noise in Processing, it is a bit different in some of the aspects of how you &#8220;access&#8221; it. In Processing you sort of get the values representing the noise iteration, whereas In Flash you actually build a noise Bitmap and read pixels from this to produce numerical noise. I Processing I guess you would do the opposite, i.e. building all the noise values into a bitmap to get something similar to the noise below.</p>
<p><object width="530" height="680" data="http://www.rickigregersen.com/wp-content/uploads/PerlinNoiseAdjust.swf" type="application/x-shockwave-flash"><param name="quality" value="medium" /><param name="scale" value="exactfit" /><param name="salign" value="l" /><param name="wmode" value="transparent" /><param name="src" value="http://www.rickigregersen.com/wp-content/uploads/PerlinNoiseAdjust.swf" /></object></p>
<p>So I build this little app to play around with the parameters and to see how much detail one can get away with, before the calculation load gets to heavy for practical use. The values that can be adjusted below are those that go into the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#perlinNoise()">BitmapData.perlinNoise method</a> If you would like to put in more controls or whatever you feel like doing with this small app then: <a href="http://www.rickigregersen.com/wp-content/uploads/PerlinAdjuster.zip">Snatch the entire Flex project here (SDK 3.3)</a>, swf included.</p>
<p>I recalled that when dabbling with Perlin noise, a year ago, in Processing I found <a href="http://www.noisemachine.com/talk1/">Ken Perlin&#8217;s talk on&#8230; well, noise I guess <img src='http://www.rickigregersen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </a> It is very interesting and even though words like <em>permutations</em> and <em>fractals</em> are used to some extend it is mainly an interesting story about this invention. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2009/05/28/evil-loud-perlin-noise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encapsulate some of the Event and try/catch clutter in AS3 and Flex</title>
		<link>http://www.rickigregersen.com/2009/04/20/encapsulate-some-of-the-event-and-trycatch-clutter-in-as3-and-flex/</link>
		<comments>http://www.rickigregersen.com/2009/04/20/encapsulate-some-of-the-event-and-trycatch-clutter-in-as3-and-flex/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 20:03:53 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[try/catch]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=43</guid>
		<description><![CDATA[A few months back I finally got to clean up some of my classes in an old project. I realized that it was way overdue with a custom PictureLoader Class, a lot of the clutter that made my classes hard to read was try catch and Event handling. When loading a simple piece of graphics [...]]]></description>
			<content:encoded><![CDATA[<p>A few months back I finally got to clean up some of my classes in an old project. I realized that it was way overdue with a custom PictureLoader Class, a lot of the clutter that made my classes hard to read was try catch and Event handling.  When loading a simple piece of graphics into an AIR app(Flash, Flex also of course) you will go through at least these steps:</p>
<ol>
<li>declare loader, url and eventListener.</li>
<li>write listener method</li>
<li>start loading</li>
<li>catch complete event and add the loader to the displayList</li>
</ol>
<p>Ok, not that much work and only a bit of clutter, however I am programming these AIR apps for a 52&#8243; touch screen, meaining no mouse or keyboard, and any exception not caught will result in the UI being rendered useless and me having to VPN into the system and restart it. I really do not want to do this so here is the list that everyone should abide by when loading anything <img src='http://www.rickigregersen.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<ol>
<li>declare loader, url and eventListener for ProgressEvent, IOErrorEvent and CompleteEvent</li>
<li>write listener methods for all of the above events</li>
<li>wrap the loader into a try/catch block to catch exceptions</li>
<li>catch complete or error event and remove all the EventListeners</li>
<li>cast the content of the loader into the appropriate type</li>
<li>copy this new content into a new object so that the loader can be null&#8217;ed and memory freed up</li>
</ol>
<p>Ok, suddenly a lot of work and subsequently heaps of clutter. This is a result of the Event driven way of ActionScript 3.0 but a small price for the OOP architecture it now builds upon.  I wished to encapsulate all the Event logic into the loader and have that deal with it, the Event code adds clutter. The solution uses the same approach as the Proxy Class so if You tried extending that this will make perfect sense. The main idea is to instantiate a PictureLoader object and pass it the methods that should be executed when events happen and let the PictureLoader handle all garbage collection and event clutter (Ok I&#8217;ll stop using the word clutter now, promise).</p>
<pre lang="actionscript">/**
* Author: Ricki Gregersen www.rickigregersen.com
* GPL: All code is snatch and grab
*/
package com.rickigregersen.loaders
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;

	public class PictureLoader extends Loader
	{
		private var pic:Bitmap;
		private var loader:Loader
		private var percent:int;
		private var failFunction:Function;
		private var progressFunction:Function;
		private var successFunction:Function;

		public function PictureLoader()
		{
			//the worlds blankiest blank...
		}
		public function loadPicture(url:String, success:Function = null,  progress:Function = null, fail:Function = null):void
		{
			//set the local functions to your global functions
			failFunction = fail;
			progressFunction = progress;
			successFunction	= success;
			//make the needed objects ready
			pic = new Bitmap();
			loader = new Loader();
			//Add a listener for all the different events the could be fired
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, pictureProgress, false, 0, true);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, pictureFailed, false, 0, true);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, pictureLoaded, false, 0, true);
			//Wrap the load method in a try-catch to catch any wildcard errors that could break the VM
			try{
				loader.load(new URLRequest(url));
			}catch(error:Error){
				pictureFailed();
			}
		}
		//getters for the percent loaded and the picture
		public function get progress():int
		{
			return percent;
		}
		public function get picture():Bitmap
		{
			return pic;
		}
		//Functions to catch the events
		private function pictureProgress(event:Event):void
		{
			percent = (loader.contentLoaderInfo.bytesLoaded / loader.contentLoaderInfo.bytesTotal) * 100;
			//call the parents progressFunction to alert it that a loadProgress has happend
			progressFunction();
		}

		private function pictureLoaded(event:Event):void
		{
			//cast the picture into a bitmap, before this the picture is of type "loader.content"
			pic = (Bitmap)(event.target.content);
			//remove the eventlistener
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, pictureLoaded);
			loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, pictureFailed);
			loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, pictureProgress);
			//make sure to free the memory and null the loader
			loader.unloadAndStop(true);
			loader = null;
			//call the parents pictureLoaded function to alert it the picture was loaded and ready to be picked up
			successFunction();
			//successFunction(pic); could have been used, just send the parent function a reference to the picture.
			//But I like getter/setters. As long as the method in the parent accepts a bitmap as input you don't have to worry about it
			//in here.
		}
		private function pictureFailed(event:Event = null):void
		{
			//Loading failed, so clean the loader and alert the parent
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, pictureLoaded);
			loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, pictureFailed);
			loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, pictureProgress);
			loader.unloadAndStop(true);
			loader = null;
			failFunction();
		}
	}
}</pre>
<p>This is how it is used, notice that this is complete with all the logic for listening for the complete, progress and error events.</p>
<pre lang="actionscript">			import com.rickigregersen.loaders.PictureLoader;

			private var picLoader:PictureLoader;
			private var pic:Bitmap;
			private var container:Sprite;

			private function init():void
			{
				picLoader = new PictureLoader();
				picLoader.loadPicture("assets/picture.png", picLoaded, picProgress, picFailed);
			}

			private function picProgress():void
			{
				trace(picLoader.progress);
			}
			private function picLoaded():void
			{
				pic = picLoader.picture;
				rawChildren.addChild(pic);
			}
			private function picFailed():void
			{
				trace("error loading picture");
			}</pre>
<p>The functions passed to the PictureLoader are not mandatory, they are all set to null as default.</p>
<p>This means that the really short version of using this Class is like this:</p>
<pre lang="actionscript">
			import com.rickigregersen.loaders.PictureLoader;

			private var picLoader:PictureLoader;
			private var pic:Bitmap;
			private var container:Sprite;

			private function init():void
			{
				picLoader = new PictureLoader();
				picLoader.loadPicture("assets/picture.png", picLoaded);
			}

			private function picLoaded():void
			{
				rawChildren.addChild(picLoader.picture);
			}
</pre>
<p>The use of <em>rawChildren.addChild(picLoader.picture)</em> is because this originates from a UIComponent in Flex so all other places you would use <em>addChild</em>.</p>
<p>So when building Components or just Classes that handle lots of Events and loading of external assets, this approach is something to consider.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2009/04/20/encapsulate-some-of-the-event-and-trycatch-clutter-in-as3-and-flex/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
