<?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>Vershun's Brain Dump &#187; Visualizing Swarms</title>
	<atom:link href="http://www.vershun.com/category/computers/visualizing-swarms/feed" rel="self" type="application/rss+xml" />
	<link>http://www.vershun.com</link>
	<description>Worthless Mind Excretion</description>
	<lastBuildDate>Thu, 08 Jul 2010 01:38:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Barebones application for visualizing swarms (2D)</title>
		<link>http://www.vershun.com/computers/visualizing-swarms/barebones-application-for-visualizing-swarms-2d.html</link>
		<comments>http://www.vershun.com/computers/visualizing-swarms/barebones-application-for-visualizing-swarms-2d.html#comments</comments>
		<pubDate>Sun, 17 May 2009 04:36:41 +0000</pubDate>
		<dc:creator>Vershun</dc:creator>
				<category><![CDATA[Visualizing Swarms]]></category>

		<guid isPermaLink="false">http://www.vershun.com/?p=254</guid>
		<description><![CDATA[So I&#8217;ve decided to play around a bit for my own giggles and make some swarm stuff.  Emergent behavior is the bee&#8217;s knees and I think it will be a lot of fun to code up some visual representations of it.
This is the very first step in the processes.  It&#8217;s not quite a &#8220;framework,&#8221; but [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve decided to play around a bit for my own giggles and make some swarm stuff.  Emergent behavior is the bee&#8217;s knees and I think it will be a lot of fun to code up some visual representations of it.</p>
<p>This is the very first step in the processes.  It&#8217;s not quite a &#8220;framework,&#8221; but more of a template.  Click to activate the ants, slide to change the speed.</p>
<p><object width="505" height="375" data="http://www.vershun.com/projects/ants_template/ants.swf" type="application/x-shockwave-flash"><param name="quality" value="high" /><param name="bgcolor" value="#869ca7" /><param name="allowScriptAccess" value="sameDomain" /><param name="src" value="http://www.vershun.com/projects/ants_template/srcview" /></object></p>
<p>You can right click and view source.  The code is very rudimentary and the only slightly interesting part is how the ants decide to move.</p>
<blockquote>
<pre>var stuckCounter:int = 90;

do
{
	var randomAngle:uint = rotation + ((Math.random() * stuckCounter) - (stuckCounter / 2));
	var randomDistance:uint = Math.random() * 70 + 10;

	var randX:int = randomDistance * Math.cos(randomAngle * (Ant.TO_RADIANS));
	var randY:int = randomDistance * Math.sin(randomAngle * (Ant.TO_RADIANS));
	stuckCounter++;
} while (environment.isObstructionInPath(x, y, x + randX, y + randY));</pre>
</blockquote>
<p>The code is pretty self explanatory (hopefully), but basically the ant is choosing a random direction within its scope (45 degrees both left and right of it&#8217;s current rotation), generates a random distance to travel, and checks with the environment to make sure there&#8217;s no obstructions within its projected trajectory.  If there&#8217;s an obstruction, add 1 degree to the randomizer and repeat.  Using randomly chosen angles along with a slow increase in the randomized range helps give a more realistic look of obstacle avoidance than other methods (say, flipping rotation).</p>
<p>I&#8217;ll be adding more to this section when I get some motivated down time to play, but this week it&#8217;s all about the R&#038;R.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vershun.com/computers/visualizing-swarms/barebones-application-for-visualizing-swarms-2d.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
