<?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 efnx code blog. &#187; game</title>
	<atom:link href="http://efnx.com/tag/game/feed/" rel="self" type="application/rss+xml" />
	<link>http://efnx.com</link>
	<description>code. blog.</description>
	<lastBuildDate>Wed, 18 Jan 2012 20:48:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>My Lisp Game is Done!</title>
		<link>http://efnx.com/my-lisp-game-is-done/</link>
		<comments>http://efnx.com/my-lisp-game-is-done/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 09:55:16 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[lisp]]></category>
		<category><![CDATA[game]]></category>

		<guid isPermaLink="false">http://efnx.com/my-lisp-game-is-done/</guid>
		<description><![CDATA[I just checked in the &#8216;final&#8217; code to github. Check out my first program in lisp!]]></description>
			<content:encoded><![CDATA[<p>I just checked in the &#8216;final&#8217; code to github. Check out my first program in lisp!<br />
<div class="wp-caption aligncenter" style="width: 410px"><a href="http://github.com/schell/kabukitheatre.bourtange/"><img alt="Bourtange, a fort defense game writting in Lisp" src="http://github.com/schell/kabukitheatre.bourtange/raw/master/screenshot.png" title="Bourtange" width="400" height="300" /></a><p class="wp-caption-text">Bourtange!</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/my-lisp-game-is-done/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lisp Game Progress</title>
		<link>http://efnx.com/lisp-game-progress/</link>
		<comments>http://efnx.com/lisp-game-progress/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 20:36:05 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[lisp]]></category>
		<category><![CDATA[game]]></category>

		<guid isPermaLink="false">http://efnx.com/?p=291</guid>
		<description><![CDATA[So after my first (almost) 30 days of learning lisp, I have a playable game. The gameplay is a cross between tower defense and orbient. You control a planet-base (the core) in the center of the screen. This core comes equipped with one weapon, the core-blast. Enemies are generated at the edge of the screen, [...]]]></description>
			<content:encoded><![CDATA[<p>So after my first (almost) <a href="http://efnx.com/lisp-game-competition/">30 days of learning lisp</a>, I have a playable game. The gameplay is a cross between <a href="http://en.wikipedia.org/wiki/Tower_defense">tower defense</a> and <a href="http://en.wikipedia.org/wiki/Orbient">orbient</a>. You control a planet-base (the core) in the center of the screen. This core comes equipped with one weapon, the core-blast. Enemies are generated at the edge of the screen, in the spawning-belt, and are drawn toward your core by gravity. When enemies collide with the core, the core looses life. Life is displayed as a green outline around the core and when your core is out of life, it explodes. When an enemy dies, which happens either by colliding with your core, being hit by a blast or being thrown past the spawning belt, you gain resources. Resources are displayed by purple boxes in the upper left. You can spend these resources on extra cores and weapons in the weapon-store, which is displayed in the upper right. Below is a screen shot of the game in action.<br />
<a href="http://efnx.com/domains/efnx.com/wp-content/uploads/2010/08/Screen-shot-2010-08-01-at-12.03.49-PM.png" rel="lightbox"><img src="http://efnx.com/domains/efnx.com/wp-content/uploads/2010/08/Screen-shot-2010-08-01-at-12.03.49-PM-300x243.png" alt="Screen Shot" title="Screen shot 2010-08-01 at 12.03.49 PM" width="300" height="243" class="alignleft size-medium wp-image-290" /></a><br />
A lot of work still remains to be done, but I hit the 30 day deadline with this first draft. Luckily, the contest hosts have <a href="http://dto.github.com/notebook/2010expo.html">extended the due date</a> to August 10th. By then I plan to fix some bugs, add more weapons, enemies, a game-over screen and do some optimization.  I feel accomplished after learning lisp, though I know I&#8217;ve only seen the tip of the iceberg and have found my new favorite language. To the hosts of the competition, thanks! You guys have made me a better programer. </p>
<p>The source to the game is <a href="http://github.com/schell/kabukitheatre.bourtange">here</a> and you can download and build the game as you please. Send me a message with your thoughts on my game or my code!</p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/lisp-game-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lisp Game Competition</title>
		<link>http://efnx.com/lisp-game-competition/</link>
		<comments>http://efnx.com/lisp-game-competition/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 18:02:12 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[lisp]]></category>
		<category><![CDATA[30 days]]></category>
		<category><![CDATA[game]]></category>

		<guid isPermaLink="false">http://efnx.com/lisp-game-competition/</guid>
		<description><![CDATA[A friend and I have decided to write a game in LISP in 30 days. The game will be entered in the 2010 lisp games expo. My good friend Aaron Maus is a lisper, and wanted to make a game. I&#8217;ve never programmed in lisp. We have 30 days to program a game for this [...]]]></description>
			<content:encoded><![CDATA[<p>A friend and I have decided to write a game in LISP in 30 days. The game will be entered in <a href="http://dto.github.com/notebook/2010expo.html">the 2010 lisp games expo</a>. </p>
<p>My good friend <a href="http://lostandsupine.com/">Aaron Maus</a> is a lisper, and wanted to make a game. I&#8217;ve never programmed in lisp. We have 30 days to program a game for this contest. Super fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/lisp-game-competition/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>AS3 – Creating a Convex Polygon from Unordered Points</title>
		<link>http://efnx.com/as3-creating-a-convex-polygon-from-unordered-points/</link>
		<comments>http://efnx.com/as3-creating-a-convex-polygon-from-unordered-points/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 23:24:58 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=215</guid>
		<description><![CDATA[Let&#8217;s pretend you have an application that lets users create shapes to be used in a physics simulation and that the user must click on the screen to set the vertices of the shape. Many physics engines only support convex polygons, or shapes that don&#8217;t have inlets, bites, or coves, basically shapes that don&#8217;t have [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s pretend you have an application that lets users create shapes to be used in a <a href="http://www.box2d.org/">physics simulation</a> and that the user must click on the screen to set the vertices of the shape. Many physics engines only support <a href="http://en.wikipedia.org/wiki/Convex_and_concave_polygons">convex polygons</a>, or shapes that don&#8217;t have inlets, bites, or coves, basically shapes that don&#8217;t have inward facing edges. With this limitation we have to be able to restrict [read as "guide"] the user to make only convex polygons. For this we are going to need an algorithm that takes an unordered set of points and finds the <a href="http://en.wikipedia.org/wiki/Convex_hull">convex hull</a> that encloses those points. This way the user can click and add points at random, if desired, and your program will keep track of what points create a convex polygon, while the others are thrown away [or dealt with however you see fit].</p>
<p><strong><a href="http://www.cs.princeton.edu/courses/archive/spr09/cos226/demo/ah/GrahamScan.html">The Graham Scan Algorithm</a></strong> is a process of ordering a random set of points and then calculating jumps to the points in that set that constitute a convex polygon. In this algorithm there are three steps. First is to find a corner point, usually the topmost, leftmost point in the set. The second step is to order all other points by the polar angle between the corner point and the point in question. The last step is to traverse the set, taking each proceeding subset of three points (n, n-1, n-2) to determine whether the angle made by these three points is a left turn, right turn, or a straight line. If the turn made is our desired turn [which is usually left - but in Flash it's right, due to the flipped y-axis] then we add that point to the convex hull. If the turn is not our desired turn, we get rid of that point and move on. </p>
<p>Here is an example that shows first the data set drawn from point to point. Each successive line gets progressively whiter. In the second step we find the corner point, order the other points and then show the outer polygon.<br />
<div id="attachment_216" class="wp-caption aligncenter" style="width: 466px"><a href="http://blog.efnx.com/wp-content/uploads/2009/09/Screen-shot-2009-09-21-at-4.11.10-PM.png" rel="lightbox"><img src="http://blog.efnx.com/wp-content/uploads/2009/09/Screen-shot-2009-09-21-at-4.11.10-PM.png" alt="Example" title="Graham Scan Example" width="456" height="224" class="size-full wp-image-216" /></a><p class="wp-caption-text">Example</p></div></p>
<p>Here&#8217;s the code for the class:</p>
<div class="codecolorer-container actionscript3 twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3f5fbf;">/**<br />
&nbsp;*&nbsp; Use this class freely - 2009 blog.efnx.com<br />
&nbsp;*/</span><br />
<br />
<span style="color: #9900cc; font-weight: bold;">package</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> GrahamScan <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; The Graham scan is a method of computing the convex hull of a finite set of points <br />
&nbsp; &nbsp; &nbsp;* &nbsp;in the plane with time complexity O(n log n). It is named after Ronald Graham, who <br />
&nbsp; &nbsp; &nbsp;* &nbsp;published the original algorithm in 1972. The algorithm finds all vertices of <br />
&nbsp; &nbsp; &nbsp;* &nbsp;the convex hull ordered along its boundary. It may also be easily modified to report <br />
&nbsp; &nbsp; &nbsp;* &nbsp;all input points that lie on the boundary of their convex hull.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> GrahamScan<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; Returns a convex hull given an unordered array of points.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> convexHull<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> findHull<span style="color: #000000;">&#40;</span> order<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; Orders an array of points counterclockwise.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> order<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;GrahamScan::order()&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// first run through all the points and find the upper left [lower left]</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> p<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a> = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> n<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> &nbsp; = <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot; &nbsp; p:&quot;,p,&quot;d:&quot;,data[i]);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&lt;</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot; &nbsp; d.y &lt; p.y / d is new p.&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> == p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&lt;</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot; &nbsp; d.y == p.y, d.x &lt; p.x / d is new p.&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// next find all the cotangents of the angles made by the point P and the</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// other points</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> sorted&nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// we need arrays for positive and negative values, because Array.sort</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// will put sort the negatives backwards.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> pos &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> neg &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// add points back in order</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> a &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">b</span> &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> cot <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">/</span>a<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>cot <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; neg<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>point<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> cotangent<span style="color: #000066; font-weight: bold;">:</span>cot<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>point<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> cotangent<span style="color: #000066; font-weight: bold;">:</span>cot<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// sort the arrays</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sortOn</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;cotangent&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NUMERIC</span> <span style="color: #000066; font-weight: bold;">|</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DESCENDING</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; neg<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sortOn</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;cotangent&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NUMERIC</span> <span style="color: #000066; font-weight: bold;">|</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DESCENDING</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sorted = neg<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span>pos<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> ordered <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ordered<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>p == sorted<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>point<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">continue</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ordered<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>sorted<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>point<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> ordered<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*&nbsp; Given an array of points ordered counterclockwise, findHull will <br />
&nbsp; &nbsp; &nbsp;* &nbsp;filter the points and return an array containing the vertices of a<br />
&nbsp; &nbsp; &nbsp;* &nbsp;convex polygon that envelopes those points.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> findHull<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;GrahamScan::findHull()&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> n &nbsp; <span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> &nbsp; &nbsp;= <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> hull<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a>&nbsp; = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// add the pivot</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// makes first vector</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>direction<span style="color: #000000;">&#40;</span>hull<span style="color: #000000;">&#91;</span>hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> hull<span style="color: #000000;">&#91;</span>hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hull<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> hull<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #339966; font-weight: bold;">function</span> direction<span style="color: #000000;">&#40;</span>p1<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a><span style="color: #000066; font-weight: bold;">,</span> p2<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a><span style="color: #000066; font-weight: bold;">,</span> p3<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=point%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:point.html"><span style="color: #004993;">Point</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &gt; 0 &nbsp;is right turn</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// == 0 is collinear</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// &lt; 0 &nbsp;is left turn</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// we only want right turns, usually we want right turns, but</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// flash's grid is flipped on y.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span> p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>p3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>p3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span> p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/as3-creating-a-convex-polygon-from-unordered-points/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Game Progress 1</title>
		<link>http://efnx.com/game-progress-1/</link>
		<comments>http://efnx.com/game-progress-1/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 16:41:08 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[machinista]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=207</guid>
		<description><![CDATA[I&#8217;ve been working on another game lately, it&#8217;s called Machinista &#8211; it&#8217;s a game where you control motors in a 2D physics simulation. The entire thing is built around Box2D, which is a great physics system. Last night I worked on using Brownian Bridge fractals for explosions &#8211; check it out! Use keys W, A, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on another game lately, it&#8217;s called Machinista &#8211; it&#8217;s a game where you control motors in a 2D physics simulation. The entire thing is built around Box2D, which is a great physics system. Last night I worked on using Brownian Bridge fractals for explosions &#8211; <a href="http://slaughterballoon.com/Machinista">check it out</a>! Use keys W, A, S, D and shift+click to control the tank and make explosions, respectively. </p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/game-progress-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

