<?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.</title>
	<atom:link href="http://blog.efnx.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.efnx.com</link>
	<description>Would you like your piece of code or your pizza cold?</description>
	<lastBuildDate>Tue, 22 Dec 2009 22:39:15 +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>DIY Webserver Using PureMVC++</title>
		<link>http://blog.efnx.com/diy-webserver-using-puremvc/</link>
		<comments>http://blog.efnx.com/diy-webserver-using-puremvc/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 22:33:13 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/diy-webserver-using-puremvc/</guid>
		<description><![CDATA[To test out my newly ported PureMVC++ implementation I decided to write an example webserver. I&#8217;ve always wanted to write one, and I didn&#8217;t realize just how easy it is (to make a VERY rudimentary version). 
The server parses your http request and then spits it back out at you, with some nice html.

That&#8217;s it! [...]]]></description>
			<content:encoded><![CDATA[<p>To test out my newly ported PureMVC++ implementation I decided to write an example webserver. I&#8217;ve always wanted to write one, and I didn&#8217;t realize just how easy it is (to make a VERY rudimentary version). </p>
<p>The server parses your http request and then spits it back out at you, with some nice html.<br />
<a href="http://blog.efnx.com/wp-content/uploads/2009/12/Screen-shot-2009-12-22-at-2.35.47-PM.png" rel="lightbox"><img src="http://blog.efnx.com/wp-content/uploads/2009/12/Screen-shot-2009-12-22-at-2.35.47-PM-300x229.png" alt="Screen shot 2009-12-22 at 2.35.47 PM" title="Screen shot 2009-12-22 at 2.35.47 PM" width="300" height="229" class="size-medium wp-image-273" /></a><br />
That&#8217;s it! Source code is here:<br />
<a href="http://github.com/efnx/PureMVC-Plus-Plus/tree/master/example/httpserver/">http://github.com/efnx/PureMVC-Plus-Plus/tree/master/example/httpserver/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.efnx.com/diy-webserver-using-puremvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PureMVC++ &#8211; A  C++ MVC framework (ported from AS3)</title>
		<link>http://blog.efnx.com/puremvc-a-c-mvc-framework-ported-from-as3/</link>
		<comments>http://blog.efnx.com/puremvc-a-c-mvc-framework-ported-from-as3/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 23:26:54 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=229</guid>
		<description><![CDATA[I had some time over the past month to port the popular PureMVC application architecture from AS3, to C++. I learned a ton about C++ and it turned out to be a rather smooth process. The code is up on github.
Differences in the C++ version

Notification names and types are ints!
At first I used strings for [...]]]></description>
			<content:encoded><![CDATA[<p>I had some time over the past month to port the popular <a href="http://puremvc.org">PureMVC</a> application architecture from AS3, to C++. I learned a ton about C++ and it turned out to be a rather smooth process. The code is up on <a href="http://wiki.github.com/efnx/PureMVC-Plus-Plus" title="PureMVC at github">github</a>.</p>
<h3>Differences in the C++ version</h3>
<dl>
<dt>Notification names and types are ints!</dt>
<dd>At first I used strings for notification names and types, just like in other ports. I did this until I was writing the first sample application. At that moment I realize in C++ you can&#8217;t switch on strings! There&#8217;s no support for writing a switch statement on the type std::string. I simply didn&#8217;t know that. So code like this just won&#8217;t compile:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">switch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;somestring&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;notthisone&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;not gonna happen&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;northisone&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;also not gonna happen&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;somestring&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;this one gets evaluated&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">default</span>:<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>C++ only allows you to switch on ints, so to save us from having to write something like this:</p>
<div class="codecolorer-container cpp twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>note<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getName<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">&quot;notthisstring&quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;not gonna happen&quot;</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>note<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getName<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">&quot;northisstring&quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;also not going to happen&quot;</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>...</div></div>
<p>I decided to make note names and types ints. This way we can enumerate our notification names and types like so:</p>
<div class="codecolorer-container cpp twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">class</span> n_name<br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">enum</span> name<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; NIL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; STARTUP, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666;">// triggers the app startup sequence</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SET,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// sets something</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; GET,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// makes a request to get something</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; DISPLAY,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// display something</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; QUIT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666;">// quit the app</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>and then handle the notification with ints:</p>
<div class="codecolorer-container cpp twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">int</span> name <span style="color: #000080;">=</span> note<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getName<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">switch</span><span style="color: #008000;">&#40;</span>name<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">case</span> n_name<span style="color: #008080;">::</span><span style="color: #007788;">STARTUP</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Startup the app!&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">case</span> n_name<span style="color: #008080;">::</span><span style="color: #007788;">QUIT</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Shutdown...&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">default</span><span style="color: #008080;">:</span><br />
<span style="color: #008000;">&#125;</span></div></div>
</dd>
<p></p>
<dt>IFacade no longer contains a <span class="code">registerCommand</span> method</dt>
<dd>I tried my best to figure out a way to implement <a href="http://en.wikipedia.org/wiki/State_(computer_science)">stateless</a> commands in C++. The way the AS3 version accomplishes this is by passing around references to classes. In that port handling references to classes in an abstract way is easy because AS3 has built in <a href="http://en.wikipedia.org/wiki/Type_introspection">type introspection</a>. In order to do the same thing in C++ we&#8217;d have to depend on something from the boost library. That&#8217;s not an option. Instead I gave Facade a templated method to replace IFacade&#8217;s <span class="code">registerCommand</span> (conveniently called <span class="code">registerCommand</span>). So instead of calling <span class="code">registerCommand(noteName, CommandClassName)</span>, one makes a call like this: <span class="code">registerCommand&lt;CommandClassName&gt;(noteName)</span>. This calls a special template function created by the compiler that adds <span class="code">CommandClassName</span> to a templated Observer, which is added to the View&#8217;s observer list.</dd>
</dl>
<p>That covers it for now. In the coming weeks I&#8217;ll probably be adding example code to this post, as well as example applications to the repo. If you&#8217;re interested in the project, keep up to date with the repo at <a href="http://wiki.github.com/efnx/PureMVC-Plus-Plus" title="PureMVC at github">github</a> and soon we&#8217;ll have a repo at PureMVC.org. I&#8217;ve added some temporary <a href="http://civiliansoftware.com/pmvcpp" title"PureMVC++ documentation">documentation</a> for you to use as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.efnx.com/puremvc-a-c-mvc-framework-ported-from-as3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AS3 &#8211; Creating a Convex Polygon from Unordered Points</title>
		<link>http://blog.efnx.com/as3-creating-a-convex-polygon-from-unordered-points/</link>
		<comments>http://blog.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[Uncategorized]]></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>0<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> 0<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 and 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>0<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>1<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> 2<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> 1<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> 0<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://blog.efnx.com/as3-creating-a-convex-polygon-from-unordered-points/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Nested Tuple</title>
		<link>http://blog.efnx.com/php-nested-tuple/</link>
		<comments>http://blog.efnx.com/php-nested-tuple/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 00:55:02 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=211</guid>
		<description><![CDATA[Here&#8217;s a quick nested tuple [list of head and tail, where tail is the list minus the head]. I wrote this for a current project I&#8217;m working on. It works with any parameters except one array. If you only pass one array, it will convert your one array into a list of Tuples.
&#60;?php
/**
&#160;* Tuple is [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick nested tuple [list of head and tail, where tail is the list minus the head]. I wrote this for a current project I&#8217;m working on. It works with any parameters except one array. If you only pass one array, it will convert your one array into a list of Tuples.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* Tuple is a list of variables. Really it is a head and a tail, where the tail<br />
&nbsp;* is also a Tuple. (Tuple(n)=head + Tuple(n-1))<br />
&nbsp;*/</span><br />
<br />
<span style="color: #000000; font-weight: bold;">class</span> Tuple<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$head</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$tail</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/func_num_args"><span style="color: #990000;">func_num_args</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// get all the arguments and package them as an array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/func_get_args"><span style="color: #990000;">func_get_args</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// take the first element and use that as the head of the list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">head</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_shift"><span style="color: #990000;">array_shift</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// if there are still args left, make a new list and use that as tail</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// pass the remainder</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Tuple<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>Here&#8217;s some usage and output:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$list</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Tuple<span style="color: #009900;">&#40;</span>1<span style="color: #339933;">,</span> 2<span style="color: #339933;">,</span> 3<span style="color: #339933;">,</span> 4<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$list</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>That prints out:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Tuple Object<br />
<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#91;</span>head<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#91;</span>tail<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Tuple Object<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#91;</span>head<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#91;</span>tail<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Tuple Object<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#91;</span>head<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#91;</span>tail<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Tuple Object<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#91;</span>head<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#91;</span>tail<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><br />
<br />
<span style="color: #009900;">&#41;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.efnx.com/php-nested-tuple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Game Progress 1</title>
		<link>http://blog.efnx.com/game-progress-1/</link>
		<comments>http://blog.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://blog.efnx.com/game-progress-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>30 30 Second Songs In 30 Days</title>
		<link>http://blog.efnx.com/30-30-second-songs-in-30-days/</link>
		<comments>http://blog.efnx.com/30-30-second-songs-in-30-days/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 19:23:23 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Atair]]></category>
		<category><![CDATA[efnx]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/30-30-second-songs-in-30-days/</guid>
		<description><![CDATA[My friend Judah and I are going to collaborate on an album of 30 30 second songs, and will be releasing it August 1st, 2009.
]]></description>
			<content:encoded><![CDATA[<p>My friend Judah and I are going to collaborate on an album of 30 30 second songs, and will be releasing it August 1st, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.efnx.com/30-30-second-songs-in-30-days/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Universal Law of Deadlines</title>
		<link>http://blog.efnx.com/the-universal-law-of-deadlines/</link>
		<comments>http://blog.efnx.com/the-universal-law-of-deadlines/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 22:08:55 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[deadlines]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/the-universal-law-of-deadlines/</guid>
		<description><![CDATA[A friend and I were talking about deadlines, as we&#8217;re often thrown into a rushed project together, and I came up with this equation which seems to accurately model a coming deadline in the information industry.
Scivally-Nagler&#8217;s Law
workload + stress = 1/&#40;deadline - now&#41;;
]]></description>
			<content:encoded><![CDATA[<p>A friend and I were talking about deadlines, as we&#8217;re often thrown into a rushed project together, and I came up with this equation <b>which seems to accurately model a coming deadline in the information industry.</b></p>
<h2>Scivally-Nagler&#8217;s Law</h2>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">workload + stress = 1<span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#40;</span>deadline - now<span style="color: #66cc66;">&#41;</span>;</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.efnx.com/the-universal-law-of-deadlines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 &#8211; Drawing Circles With IGraphicsData</title>
		<link>http://blog.efnx.com/as3-drawing-circles-with-igraphicsdata/</link>
		<comments>http://blog.efnx.com/as3-drawing-circles-with-igraphicsdata/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 16:20:06 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[fp10]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=195</guid>
		<description><![CDATA[Drawing circles with Flash 10's new IGraphicsData API is easy. Here is a function that will populate a GraphicsPath object with points and commands for drawing a circle approximation.]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been working on a game  with some of my free time. It&#8217;s a slow process made a little bit faster through the use of <a href="http://www.box2d.org/">Box2D</a>, which is a great 2D physics lib. In my game the user controls a robot that wheels around and smashes other robots. I decided that I would write some functions for drawing geometric primitives, and that I would draw everything into one sprite, or two, depending on how many layers I&#8217;d need. In an attempt to squeeze out some more frames per second I switched these functions over to use flash 10+ IGraphicsData API. It&#8217;s interesting, to say the least. When using the new API we loose the ability to easily draw rectangles and circles. We can still use familiar functions like moveTo, lineTo and curveTo &#8211; so I&#8217;ve written a function that draws a circle using these. It uses some fun almost calculus [parametrization of a curve in so many points] minus any derivatives or integrals. Is that still calculus? Meh. Here&#8217;s what happens:</p>
<p>We create a new GraphicsStroke [the line], a new GraphicsSolidFill [the fill], a new GraphicsPath [the path] and an IGraphicsData Vector to store them all in.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> _stroke :GraphicsStroke &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #000000; font-weight: bold;">new</span> GraphicsStroke<span style="color: #66cc66;">&#40;</span>1<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; _stroke.<span style="color: #006600;">fill</span> = <span style="color: #000000; font-weight: bold;">new</span> GraphicsSolidFill<span style="color: #66cc66;">&#40;</span>0xFF00FF, 1<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> _fill &nbsp; :GraphicsSolidFill &nbsp;&nbsp; &nbsp; = <span style="color: #000000; font-weight: bold;">new</span> GraphicsSolidFill<span style="color: #66cc66;">&#40;</span>0xF0F0F0, 1<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> _path &nbsp; :GraphicsPath &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #000000; font-weight: bold;">new</span> GraphicsPath<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> _graph&nbsp; :Vector.<span style="color: #66cc66;">&lt;</span>IGraphicsData<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>IGraphicsData<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Now what we&#8217;ll need to do is populate the path with some commands and some points. To do this, we can use GraphicsPath&#8217;s familiar functions moveTo, lineTo and curveTo. These functions will fill path.command and path.data with commands and data, respectively. The parameters to each command are stored in the data array, where as a number representing each command are stored in the command array. You can read more about it <a href="http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS749610B4-4709-4f75-BBA0-650BF52623CA.html">here</a>. So here is a function that will fill your path with points and commands to form a circle.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> r_addCircle<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_x</span>:<span style="color: #0066CC;">Number</span>, <span style="color: #0066CC;">_y</span>:<span style="color: #0066CC;">Number</span>, r:<span style="color: #0066CC;">Number</span>, path:GraphicsPath, numPoints:<span style="color: #0066CC;">int</span> = 8<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> twoPI:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> curve:<span style="color: #0066CC;">Number</span> = 1 + 1<span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#40;</span>numPoints<span style="color: #66cc66;">*</span>1.75<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; path.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_x</span> + r<span style="color: #66cc66;">&#41;</span>, <span style="color: #0066CC;">_y</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">1</span>; i <span style="color: #66cc66;">&lt;</span>= numPoints; i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> th&nbsp; :<span style="color: #0066CC;">Number</span> = twoPI <span style="color: #66cc66;">*</span> i<span style="color: #66cc66;">/</span>numPoints;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> thm :<span style="color: #0066CC;">Number</span> = twoPI <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span>i-0.5<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span>numPoints;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> px:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_x</span> + r <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>th<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> py:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_y</span> + r <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>th<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> hx:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_x</span> + r <span style="color: #66cc66;">*</span> curve <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>thm<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> hy:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_y</span> + r <span style="color: #66cc66;">*</span> curve <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>thm<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; path.<span style="color: #0066CC;">curveTo</span><span style="color: #66cc66;">&#40;</span>hx, hy, px, py<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>In this function _x and _y represent the center of the circle, r is the radius and path is your GraphicsPath. numPoints refers to the number of points you&#8217;d like to use for approximating your circle. The more points, the more &#8220;perfect&#8221; the circle will look, although more points will tax your frameRate. We can get a pretty nice looking circle with 8 points. 4 looks a little boxy, but around 8 is nice. Experiment. Here&#8217;s the next step &#8211; we&#8217;ll add the points to our path and then add the stroke, fill and path to our Vector and then have a sprite draw our graphics data:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">r_addCircle<span style="color: #66cc66;">&#40;</span>50, 50, 50, _path, 2<span style="color: #66cc66;">&#41;</span>;<br />
r_addCircle<span style="color: #66cc66;">&#40;</span>150, 50, 50, _path, 4<span style="color: #66cc66;">&#41;</span>;<br />
r_addCircle<span style="color: #66cc66;">&#40;</span>250, 50, 50, _path, 6<span style="color: #66cc66;">&#41;</span>;<br />
r_addCircle<span style="color: #66cc66;">&#40;</span>350, 50, 50, _path, 8<span style="color: #66cc66;">&#41;</span>;<br />
<br />
_graph.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>_stroke, _fill, _path<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
<span style="color: #000000; font-weight: bold;">var</span> sprite:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>sprite<span style="color: #66cc66;">&#41;</span>; &nbsp; <br />
<br />
sprite.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawGraphicsData</span><span style="color: #66cc66;">&#40;</span>_graph<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>This should draw 4 circle approximations of different resolution. This is what it looks like:<br />
<div id="attachment_197" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.efnx.com/wp-content/uploads/2009/06/Picture-1.png" rel="lightbox"><img src="http://blog.efnx.com/wp-content/uploads/2009/06/Picture-1-300x206.png" alt="approximated circles" title="approximated circles" width="300" height="206" class="size-medium wp-image-197" /></a><p class="wp-caption-text">approximated circles</p></div></p>
<p>You can see that as n [numPoints] increases, the closer to an actual circle our object becomes. I hope this entry helps some of you out there save a little time.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.efnx.com/as3-drawing-circles-with-igraphicsdata/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hannspree HF237 + Macbook Pro 2.16Ghz</title>
		<link>http://blog.efnx.com/hannspree-hf237-macbook-pro-2-16ghz/</link>
		<comments>http://blog.efnx.com/hannspree-hf237-macbook-pro-2-16ghz/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 07:20:51 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hannspree]]></category>
		<category><![CDATA[lcd]]></category>
		<category><![CDATA[rambles]]></category>
		<category><![CDATA[rants]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/hannspree-hf237-macbook-pro-2-16ghz/</guid>
		<description><![CDATA[I bought a new monitor today &#8211; a Hannspree 23&#8243;. I only paid about $180 for it, so it seemed like a sweet deal. TOTALLY WRONG. This thing hurts my eyes it&#8217;s so sh*tty. Some pixels are sharp, others are blurry. It&#8217;s like the monitor itself is stretching and interpolating the pixel points from my [...]]]></description>
			<content:encoded><![CDATA[<p>I bought a new monitor today &#8211; a Hannspree 23&#8243;. I only paid about $180 for it, so it seemed like a sweet deal. TOTALLY WRONG. This thing hurts my eyes it&#8217;s so sh*tty. Some pixels are sharp, others are blurry. It&#8217;s like the monitor itself is stretching and interpolating the pixel points from my video card. Text is UNREADABLE on most resolutions and no amount of settings fidgetry seems to fix it. The pixels just don&#8217;t line up. This thing is auto-dithering my pixel art. I&#8217;m taking it back tomorrow and getting my money back. I&#8217;d rather have a used, scuffed up LCD from two years ago. Tried and true.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.efnx.com/hannspree-hf237-macbook-pro-2-16ghz/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Altered States</title>
		<link>http://blog.efnx.com/altered-states/</link>
		<comments>http://blog.efnx.com/altered-states/#comments</comments>
		<pubDate>Sun, 03 May 2009 07:14:03 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/altered-states/</guid>
		<description><![CDATA[I just saw this movie called Altered States, it&#8217;s pretty interesting &#8211; a little cheesy at times, but check out these screen shots:









Man, they don&#8217;t make movies like they used to. 
]]></description>
			<content:encoded><![CDATA[<p>I just saw this movie called Altered States, it&#8217;s pretty interesting &#8211; a little cheesy at times, but check out these screen shots:</p>
<p><a href="http://www.flickr.com/photos/schellefnx/archives/date-posted/2009/05/03/" alt="altered states screenshots" ><br />
<img src="http://farm4.static.flickr.com/3569/3496547754_2ce093fb5d_m.jpg" /><br />
<img src="http://farm4.static.flickr.com/3652/3496548106_055d5a0449_m.jpg" /><br />
<img src="http://farm4.static.flickr.com/3317/3495729467_33309207e8_m.jpg" /><br />
<img src="http://farm4.static.flickr.com/3355/3496548322_44874b6427_m.jpg" /><br />
<img src="http://farm4.static.flickr.com/3608/3495730161_f216afa71a_m.jpg" /><br />
<img src="http://farm4.static.flickr.com/3615/3496548760_05d89c63c0_m.jpg" /><br />
<img src="http://farm4.static.flickr.com/3411/3495730705_f28f7ca39f_m.jpg" /><br />
</a><br />
Man, they don&#8217;t make movies like they used to. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.efnx.com/altered-states/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
