<?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; Particle</title>
	<atom:link href="http://www.rickigregersen.com/category/particle/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.1</generator>
		<item>
		<title>Fake Gravity Fluid</title>
		<link>http://www.rickigregersen.com/2009/08/31/fake-gravity-fluid/</link>
		<comments>http://www.rickigregersen.com/2009/08/31/fake-gravity-fluid/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 22:01:41 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Particle]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flow field]]></category>
		<category><![CDATA[fun]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=196</guid>
		<description><![CDATA[I was playing around with the Traer Physics Library for processing/java. It is really fast but even though I had done some small experiments with it a year or so back, I still had to dig out the manual and refresh some basic stuff. Well Im looking into the whole FluidSolver thing, again, and I [...]]]></description>
			<content:encoded><![CDATA[<p>I was playing around with the <a href="http://www.cs.princeton.edu/~traer/physics/">Traer Physics Library</a> for processing/java. It is really fast but even though I had done some small experiments with it a year or so back, I still had to dig out the manual and refresh some basic stuff.<br />
Well Im looking into the whole FluidSolver thing, again, and I thought it could be fun to do a fast and crude Newtonian approach and just go for an effect that looks a bit like it, but is far more simple.</p>
<p><img src="http://www.rickigregersen.com/wp-content/uploads/fluid.png" alt="16834 particles fakes fluid" /></p>
<p><a href="http://www.rickigregersen.com/wp-content/uploads/fluid_applet/index.html">Example and code here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2009/08/31/fake-gravity-fluid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing Tentacles</title>
		<link>http://www.rickigregersen.com/2009/08/08/processing-tentacles/</link>
		<comments>http://www.rickigregersen.com/2009/08/08/processing-tentacles/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 16:16:38 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[Particle]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=185</guid>
		<description><![CDATA[I just did a quick port to processing, important to notice that these classes are &#8220;as is&#8221;, but still, the speed of Java compared to Flash is&#8230; well lets just say the gap isn&#8217;t quite gone yet EDIT: forgot some int/float math that made the tentacles look bulky&#8230; better now. Example and code here:]]></description>
			<content:encoded><![CDATA[<p>I just did a quick port to processing, important to notice that these classes are &#8220;as is&#8221;, but still, the speed of Java compared to Flash is&#8230; well lets just say the gap isn&#8217;t quite gone yet <img src='http://www.rickigregersen.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>EDIT: forgot some int/float math that made the tentacles look bulky&#8230; better now.<br />
<a href="http://www.rickigregersen.com/wp-content/uploads/applet/index.html">Example and code here:</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2009/08/08/processing-tentacles/feed/</wfw:commentRss>
		<slash:comments>0</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>Webcam Flow field in Flash</title>
		<link>http://www.rickigregersen.com/2009/05/25/webcam-flow-field-in-flash/</link>
		<comments>http://www.rickigregersen.com/2009/05/25/webcam-flow-field-in-flash/#comments</comments>
		<pubDate>Mon, 25 May 2009 21:02:48 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Particle]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=93</guid>
		<description><![CDATA[I was lurking about over at Justin Windle&#8217;s blog Soulwire, wish my blog had an alter ego with a cool name.. He had been building some flow fields using Perlin noise, which my colleague think is Merlins evil brother for some reason. I was writing a vector library for a particle engine Im going to publish here [...]]]></description>
			<content:encoded><![CDATA[<p>I was lurking about over at Justin Windle&#8217;s blog <a href="http://blog.soulwire.co.uk/flash/actionscript-3/perlin-noise-flow-field/">Soulwire</a>, wish my blog had an alter ego with a cool name..</p>
<p><div id="attachment_96" class="wp-caption alignleft" style="width: 540px"><img class="size-medium wp-image-96" title="flowfield" src="http://www.rickigregersen.com/wp-content/uploads/flowfiledorange.png" alt="It was a bit to dark, the background is disturbing the image and so on.." width="530" height="400" /><p class="wp-caption-text">Now I know how Neo felt..</p></div><br />
<div id="attachment_96" class="wp-caption alignleft" style="width: 540px"><img class="size-medium wp-image-96" title="flowfield" src="http://www.rickigregersen.com/wp-content/uploads/flowfiled.png" alt="It was a bit to dark, the background is disturbing the image and so on.." width="530" height="400" /><p class="wp-caption-text">Which makes this Keanu Reeves..</p></div><br />
He had been building some flow fields using Perlin noise, which my colleague think is Merlins evil brother for some reason.</p>
<p>I was writing a vector library for a particle engine Im going to publish here some day and thought that implementing theSoulwire flow field would be nice. Justin has been so kind as to put out the source, which is awesome  when your code is that good and visually stunning. As I played around with the code I got an idea, I think it is inspired by something I saw on the <a href="http://www.processing.org">Processing site</a> the idea was to use the input from my webcam as the noise map, instead of the <del datetime="2009-05-25T20:12:34+00:00">M</del>Perlin noise. I made a quick mockup, that actually looks quite promising. It needs some sort of effect, maybe an IR webcam, a 5&#215;5 meter black wall to project it on, before it is ready, also the manipulation of the webcam image before it get&#8217;s read by the particles could give it a little extra. It is ticking along quite well on my Macbook Air, running the webcam and 5000 vectors.</p>
<p><object width="530" height="800" data="http://www.rickigregersen.com/wp-content/uploads/FlowfieldBumpmapWebcam.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/flowfieldweb.swf" /></object></p>
<p>For now I&#8217;ll just put the source code up here:</p>
<p>(It is build using Eclipse (Flex Builder Plugin), so it extends UIComponent, not something I would recommend, but if someone can tell me how to add Sprites to the stage of an AIR app, I will surley change it)</p>
<pre lang="java">
package
{
	import com.rickigregersen.flow_bump.Arrow;

	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.ColorTransform;
	import flash.media.Camera;
	import flash.media.Video;

	import mx.core.UIComponent;

	public class Main extends UIComponent
	{
		//theese are the values I had fun playing with, but you might want something a bit more crazy:)

		private static const TRAIL : Number = 0.95;
		private static const BOOST : int = 110;
		private static const VECTORS : int = 1000;
		private static const BLUR : int = 4;
		private static const SCALE : Number = 6.0;
		private static const BACKGROUND : uint = 0x000000;
		;

		private static var fading : ColorTransform = new ColorTransform( 1, 1, 1, TRAIL );
		private static var blurFilter : BlurFilter = new BlurFilter( BLUR, BLUR, 3 )
		private static var grayMatrix : Array = [                       0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0, 0, 0, 1, 0 ];
		private var grayFilter : ColorMatrixFilter = new ColorMatrixFilter( grayMatrix );
		private var brightMatrix : Array = [                      1, 0, 0, 0, BOOST, 0, 1, 0, 0, BOOST, 0, 0, 1, 0, BOOST, 0, 0, 0, 1, 0 ]
		private var brightFilter : ColorMatrixFilter = new ColorMatrixFilter( brightMatrix );

		private var camBMD : BitmapData;
		private var camBMP : Bitmap;
		private var renderBMD : BitmapData;
		private var renderBMP : Bitmap;
		private var vid : Video;
		private var cam : Camera;
		private var w : int, h : int;
		private var flowImage : Sprite;

		public function Main( _w : int, _h : int )
		{
			//width and height, also a sprite for holding the little particles;
			w = _w;
			h = _h;
			flowImage = new Sprite();
			//get the video;
			cam = Camera.getCamera();
			vid = new Video( w, h );
			vid.attachCamera( cam );

			//make a bitmap for drawing the video into
			camBMD = new BitmapData( w, h, false, BACKGROUND );
			camBMP = new Bitmap( camBMD );

			//a bitmap to stuff it all into and give some sort of effect
			renderBMD = new BitmapData( w, h, false, BACKGROUND );
			renderBMP = new Bitmap( renderBMD );

			//add the cam bmp and the rendered bmp
			addChild( camBMP );
			camBMP.y = h;

			addChild( renderBMP );
			//build the little vectors
			buildVectors();
		}

		private function buildVectors() : void
		{
			//place, rotate and scale them randomly
			var a : Arrow;

			for ( var i : int = 0; i < VECTORS; i++ )
			{
				a = new Arrow();
				a.x = Math.random() * w;
				a.y = Math.random() * h;
				a.rotation = Math.random() * 360;
				a.scaleX = a.scaleY = Math.random() + 0.1;
				flowImage.addChild( a );
			}
			addEventListener( Event.ENTER_FRAME, update, false, 0, true );
		}

		private function update( event : Event ) : void
		{
			//draw the cam to the stage, appy the grayscale Matrix, sometimes blur and brightfilters too
			camBMD.draw( vid );
			camBMP.filters = [                         grayFilter /*, blurFilter, brightFilter */  ];

			var a : Arrow;
			var brightness : Number;
			var radians : Number;
			var angle : Number;
			var speed : Number;
			var pixel : int;

			for ( var i : int = 0; i < VECTORS; i++ )
			{
				a = flowImage.getChildAt( i ) as Arrow;
				//get the brightness values of the pixel positioned directly under the vector
				pixel = camBMD.getPixel( a.x, a.y );
				brightness = pixel / 0xFFFFFF;
				//adjust spped and angle acording to the brightness
				speed = 0.1 + brightness * a.speed;
				angle = 360 * brightness * a.wander;
				radians = angle * Math.PI / 180;
				//make sure the vector is moving in the same direction as it's velocity
				a.x += Math.cos( radians ) * a.speed;
				a.y += Math.sin( radians ) * a.speed;
				//scale and rotate the vector according to brightness and
				a.rotation = angle;
				a.scaleX = a.scaleY = 0.1 + brightness * SCALE;
				//wrap around
				if ( a.x > w )
					a.x = 0;
				else if ( a.x < 0 )
					a.x = w;
				if ( a.y > h )
					a.y = 0;
				else if ( a.y < 0 )
					a.y = h;

			}

			//apply the colortransform, it determines the transparency of the bitmaps being stacked
			renderBMD.colorTransform( renderBMD.rect, fading );
			//draw the Sprite that hold all the vectors.
			renderBMD.draw( flowImage );

		}
	}
}
</pre>
<p>Here is the Arrow Class:</p>
<pre lang="java">package com.rickigregersen.flow_bump
{
	import flash.display.Shape;

	public class Arrow extends Shape
	{
		public var speed : Number = Math.random() * 3;
		public var wander : Number = Math.random() * 0.5;

		public function Arrow()
		{
			draw();
		}

		private function draw() : void
		{
			/* 			graphics.clear();
			   graphics.lineStyle( 0, 0xFF0000, 0.4 );
			   graphics.moveTo( 0, 0 );
			   graphics.lineTo( 3, 0 );
			   graphics.moveTo( 2, -1 );
			   graphics.lineTo( 3, 0 );
			 graphics.lineTo( 2, 1 ); */

			/* 			graphics.beginFill( 0xFF0000, 0.9 );
			   graphics.drawEllipse( 0, 0, 6, 2 );
			 graphics.endFill(); */

			/*
			   graphics.beginFill( 0x00FF00, 0.9 );
			   graphics.drawCircle( 0, 0, 5 );
			   graphics.endFill();
			 */
			graphics.clear();
			graphics.beginFill( 0xff6600, 1.0 );
			graphics.moveTo( -1, -0.5 );
			graphics.lineTo( 1, 0 );
			graphics.lineTo( -1, 0.5 );
			graphics.lineTo( -1, -0.5 );
			graphics.endFill();
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2009/05/25/webcam-flow-field-in-flash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
