<?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>nodename &#187; ActionScript</title>
	<atom:link href="http://nodename.com/blog/category/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://nodename.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 05 Feb 2010 05:06:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Trees Grow</title>
		<link>http://nodename.com/blog/2009/12/14/trees-grow/</link>
		<comments>http://nodename.com/blog/2009/12/14/trees-grow/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 13:54:48 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[geometry]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=194</guid>
		<description><![CDATA[Constrained minimum spanning trees as shape fills, the moving version of my earlier post The Name of the Node. <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/12/14/trees-grow/">Trees Grow</a></span>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#theMovie {
margin: 0 auto;
width: 640px;
border-width: 1;
border-style : solid ;
border-color : black ;
}
</style>
<p>Constrained minimum spanning trees as shape fills, the moving version of my earlier post <a href="http://nodename.com/blog/2009/05/12/the-name-of-the-node/">The Name of the Node</a>. On each frame one point is added, all the points move, and their spanning trees are drawn. Character: JIE2, &#8220;knot&#8221;.</p>
<div id="theMovie"><object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/BHO6zeW9sQA&#038;hl=en&#038;fs=1&#038;rel=0&#038;ap=%2526fmt%3D18"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BHO6zeW9sQA&#038;hl=en&#038;fs=1&#038;rel=0&#038;ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></div>
<p>(Be sure to view the movie in 480p.)</p>
<p>Note that since the segments are filled with trees, which may branch but never loop, the KOU3 (&#8220;mouth&#8221;) in the lower right quadrant is never a closed box. In every frame there is an escape path from the inside to the outside.</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/12/14/trees-grow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Roll Over, Delaunay: Voronoi Library Goes Open-Source</title>
		<link>http://nodename.com/blog/2009/12/03/roll-over-delaunay-voronoi-library-goes-open-source/</link>
		<comments>http://nodename.com/blog/2009/12/03/roll-over-delaunay-voronoi-library-goes-open-source/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 04:28:55 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Delaunay]]></category>
		<category><![CDATA[Voronoi]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=377</guid>
		<description><![CDATA[I've released the as3delaunay library on github! <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/12/03/roll-over-delaunay-voronoi-library-goes-open-source/">Roll Over, Delaunay: Voronoi Library Goes Open-Source</a></span>]]></description>
			<content:encoded><![CDATA[<p>A few people have asked for the code for my <a href="http://nodename.com/blog/2009/05/11/a-voronoi-toy/">Voronoi Toy</a>.  I haven&#8217;t made the entire program public yet, but I have released the underlying <a href="http://github.com/nodename/as3delaunay">as3delaunay library</a>, which I originally ported from Steven Fortune&#8217;s C implementation of his plane-sweep algorithm.</p>
<p>In addition to the Voronoi diagram and the Delaunay triangulation, the library also provides the convex hull, minimum and maximum <a href="http://nodename.com/blog/2009/05/12/the-name-of-the-node/">spanning trees</a>, and several other related geometric entities.</p>
<p>You can download the source and compile it, or just get the compiled swc from the downloads page.</p>
<p>So far I have had two users, JakeTastic (<a href="http://jaketastic.com/blog/voronoi-shattering-complete/">Voronoi shattering complete!</a>) and Li (<a href="http://www.lidev.com.ar/?p=303">Faster Voronoi Noise</a>); thanks to them both for jumping on, and to Jake also for finding the two bugs :-)</p>
<p>There&#8217;s no documentation yet, but there is a <a href="http://github.com/nodename/as3delaunayTestRunner">test suite</a> which incorporates an example of using the library for nearest-site queries, and there&#8217;s also a <a href="http://groups.google.com/group/as3delaunay">mailing list</a>, where I&#8217;ve archived Fortune&#8217;s paper and his C code, as well as a growing page of interesting <a href="http://groups.google.com/group/as3delaunay/web/resources">links</a> related to Voronoi/Delaunay.</p>
<p>The library is hosted on github, so YOU can conveniently modify, fix, or enhance it!</p>
<p>Roadmap for possible enhancements:<br />
Generalize to support weighted Voronoi diagrams, both additive and multiplicative (This is described in Fortune&#8217;s paper)<br />
Generalize to use an arbitrary polygon as a boundary<br />
&#8230; what else?</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/12/03/roll-over-delaunay-voronoi-library-goes-open-source/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Implementing Enumerated Types in ActionScript 3</title>
		<link>http://nodename.com/blog/2009/09/05/implementing-enumerated-types-in-actionscript-3/</link>
		<comments>http://nodename.com/blog/2009/09/05/implementing-enumerated-types-in-actionscript-3/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 03:39:33 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[enumerated types]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=363</guid>
		<description><![CDATA[<p>This is about implementing an enum in AS3 with value restriction ( i.e. the programmer should be unable to diminish or add to the set of values) and type safety.</p>
<p>We&#8217;ll implement the data type as a Class.  In order to keep the programmer from adding to the set of values, we need to disallow invocation <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/09/05/implementing-enumerated-types-in-actionscript-3/">Implementing Enumerated Types in ActionScript 3</a></span>]]></description>
			<content:encoded><![CDATA[<p>This is about implementing an enum in AS3 with value restriction ( i.e. the programmer should be unable to diminish or add to the set of values) and type safety.</p>
<p>We&#8217;ll implement the data type as a Class.  In order to keep the programmer from adding to the set of values, we need to disallow invocation of the constructor.</p>
<p>Back when AS3 came out, there was much talk about the lack of private constructors and what to do about it, especially with regard to implementing the Singleton pattern. My favorite of the solutions is to define a file-level class and require it (the class, not an instance!) as a constructor parameter.</p>
<p>From there we can proceed just as Daniel Savarese describes in <a href="http://www.devx.com/getHelpOn/10MinuteSolution/20442/1763">Implementing Enumerated Types in Java</a>. </p>
<p>I don&#8217;t show how to implement an ordering on the enum values.  See the Savarese article for that, too.</p>
<pre>
package
{
	import flash.errors.IllegalOperationError;

	public final class PailContents
	{
		public static const WATER:PailContents = new PailContents(PrivateConstructorEnforcer, "water");
		public static const CHICKENFEED:PailContents = new PailContents(PrivateConstructorEnforcer, "chicken feed");
		public static const MILK:PailContents = new PailContents(PrivateConstructorEnforcer, "milk");
		public static const OATS:PailContents = new PailContents(PrivateConstructorEnforcer, "oats");

		private var _name:String;

		public function PailContents(lock:Class, name:String)
		{
			super();
			if (lock != PrivateConstructorEnforcer)
			{
				throw new IllegalOperationError("Invalid constructor access");
			}
			_name = name;
		}

		// don't forget to implement toString() to support implicit conversion to String for trace() etc:
		public function toString():String
		{
			return _name;
		}

	}
}

// defined outside the package, and therefore visible only within this source file:
class PrivateConstructorEnforcer {}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/09/05/implementing-enumerated-types-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Crystals, Evil Rangers, and Voronoi without an Engine</title>
		<link>http://nodename.com/blog/2009/07/01/crystals-evil-rangers-and-voronoi-without-an-engine/</link>
		<comments>http://nodename.com/blog/2009/07/01/crystals-evil-rangers-and-voronoi-without-an-engine/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 20:41:03 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[Voronoi]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=205</guid>
		<description><![CDATA[<p>In Flash we can HARNESS THE POWER OF BITMAPDATA (as it might be put in a conference session blurb) to grow Voronoi regions under differing conditions, without doing any algebra.  Click on the image to launch the Voronoi Generator.</p>
<p>

 </p>
<p>Variations on Voronoi Diagrams, from Geometry in Action:</p>
<p>One way of getting Voronoi diagrams is by growing <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/07/01/crystals-evil-rangers-and-voronoi-without-an-engine/">Crystals, Evil Rangers, and Voronoi without an Engine</a></span>]]></description>
			<content:encoded><![CDATA[<p>In Flash we can HARNESS THE POWER OF BITMAPDATA (as it might be put in a conference session blurb) to grow Voronoi regions under differing conditions, without doing any algebra.  Click on the image to launch the Voronoi Generator.</p>
<p><center><br />
<a href="/wpEmbeds/GenerateVoronoi/GenerateVoronoi.swf" rel="shadowbox;width=800;height=650"><img src="/wpEmbeds/GenerateVoronoi/Disconnected.jpg" alt="Disconnected!" /></a><br />
 </center></p>
<p><a href="http://www.ics.uci.edu/~eppstein/gina/scot.drysdale.html#var">Variations on Voronoi Diagrams</a>, from <a href="http://www.ics.uci.edu/~eppstein/geom.html">Geometry in Action</a>:</p>
<blockquote><p>One way of getting Voronoi diagrams is by growing crystals. If you start a number of crystals, all growing at the same rate, and all starting at the same time, you get a number of growing circles. As these circles meet, straight line boundaries appear between them. Eventually, the entire plane will be filled up. Each crystal will exactly fill up the Voronoi region of its point of origin.</p>
<p>This is a little too simple. In reality, crystals start growing at different times. Even if they still grow at the same rate, if they start at different times, they will no longer meet in straight lines. Instead, they will meet in hyperbolic segments. The diagram you get is called the &#8220;additively weighted Voronoi diagram&#8221;. It&#8217;s defined just like the usual Voronoi diagram, but each site has a weight, and you measure distance to a site, you add its weight to the usual Euclidean distance.</p>
<p>Now suppose instead that all the crystals start at the same time, but grow at different rates. Now you get what&#8217;s called the &#8220;multiplicatively weighted Voronoi diagram&#8221;. Once again, each site is given a weight, but when you measure the distance to a site, you multiply by its weight. Now the boundaries between different regions are segments of circles.</p>
<p>This model still has some problems. For example, in a multiplicatively weighted Voronoi diagram, it&#8217;s possible for a region to be disconnected [ see picture above -- AS ]. Obviously, this can&#8217;t happen with real crystals. So there&#8217;s yat another version which treats existing crystals as obstacles, and lets fast-growing crystals grow around the slower ones. Now the boundaries between neighboring regions are sort of tear-shaped. This variation is called the &#8220;multiplicatively weighted crystal growth Voronoi diagram.&#8221;</p>
<p>There are several other variations. You can change the metric from the normal Euclidean distance to L<sub>1</sub>, or L<sub>p</sub>, or L<sub>infinity</sub>, or even stranger distance functions. You can weight the sites additively and mulitplicatively. You can change the sites from points to line segments or circles or polygons. You can generalize to higher dimensions. You can associate points with the farthest site, instead of their nearest site. And so on.</p>
<p>Different applications of Voronoi diagrams require different variations. For example, motion planning algorithms for circular robots often use the Voronoi diagram of the obstacles. If there is a path from one location to another, then there must be a path that follows the edges of the Voronoi diagram, since those edges are by definition as far from the obstacles as possible.</p></blockquote>
<p>The &#8220;L<sub>1</sub> metric&#8221; is called the <em>Manhattan metric</em> or <em>city-block distance</em>.  &#8220;Manhattan metric&#8221; is a misnomer, though, because in Manhattan the east-west blocks are much longer than the north-south blocks.</p>
<p>The crystal-growth model is equivalent to the &#8220;evil forest ranger model,&#8221; in which instead of watching for forest fires, the rangers set fire to their lookouts, sometimes at different times, and the fires may spread at different rates.  Voronoi diagrams indeed find application in crystallography and in forest-fire modelling.</p>
<p>And <a href="http://hoosiermuse.wordpress.com/2009/06/01/gary-snyder-in-the-north-cascades/">here</a> is a post about a far-from-evil lookout.</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/07/01/crystals-evil-rangers-and-voronoi-without-an-engine/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Marching Squares: Boundary detection</title>
		<link>http://nodename.com/blog/2009/06/18/marching-squares-boundary-detection/</link>
		<comments>http://nodename.com/blog/2009/06/18/marching-squares-boundary-detection/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 23:30:59 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[morph]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=173</guid>
		<description><![CDATA[A little code for a change. <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/06/18/marching-squares-boundary-detection/">Marching Squares: Boundary detection</a></span>]]></description>
			<content:encoded><![CDATA[<p>A little code for a change.</p>
<p><a href="http://www.sakri.net/blog/2009/05/28/detecting-edge-pixels-with-marching-squares-algorithm/#comments">Sakri</a> was working on this, and I ported a class from Java which I believe he adapted into his final implementation.  It&#8217;s a basic tool for morphing, 3D surface reconstruction, and <a href="http://en.nicoptere.net/?p=166">vectorization</a>.</p>
<p>I&#8217;ve cleaned up my version of it and I offer it here.  The important function signature looks like this:</p>
<pre>
public static function perimeter(data:BitmapData, x:int, y:int):Vector.&lt;Point&gt;
</pre>
<p>It returns a list of pixels representing the boundary between opaque and transparent pixels, starting from a single boundary point that you provide.</p>
<p>You can get a boundary point using Sakri&#8217;s and Mario&#8217;s <a href="http://www.quasimondo.com/archives/000683.php">EdgeFinder class</a>.</p>
<p>Download the <a href="http://nodename.com/wpEmbeds/MarchingSquares/MarchingSquares.as">source</a>.</p>
<p>How it works:  <a href="http://en.wikipedia.org/wiki/Marching_squares">Marching Squares on Wikipedia</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/06/18/marching-squares-boundary-detection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mona Voronita</title>
		<link>http://nodename.com/blog/2009/05/18/mona-voronita/</link>
		<comments>http://nodename.com/blog/2009/05/18/mona-voronita/#comments</comments>
		<pubDate>Tue, 19 May 2009 02:39:45 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Delaunay]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[Voronoi]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=139</guid>
		<description><![CDATA[<p>Click on the image to see 1000 Voronoi points in motion.  Keyboard controls as in the Voronoi Toy.</p>
<p>If the popup won&#8217;t go away when you click the X, click in the movie and hit &#8220;s&#8221; to stop the moving points.</p>
<p>

 </p>
<p>I couldn&#8217;t <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/05/18/mona-voronita/">Mona Voronita</a></span>]]></description>
			<content:encoded><![CDATA[<p>Click on the image to see 1000 Voronoi points in motion.  Keyboard controls as in the <a href="http://nodename.com/blog/2009/05/11/a-voronoi-toy/" target="_blank">Voronoi Toy</a>.</p>
<p>If the popup won&#8217;t go away when you click the X, click in the movie and hit &#8220;s&#8221; to stop the moving points.</p>
<p><center><br />
<a href="/wpEmbeds/MonaVoronita/bin/MonaVoronita.swf" rel="shadowbox;width=298;height=425"><img src="/wpEmbeds/MonaVoronita/MonaOnCrack.jpg" alt="" /></a><br />
 </center></p>
<p>I couldn&#8217;t resist, <a href="http://www.dasprinzip.com/prinzipiell/2008/08/25/voronoi-tesselations/" target="_blank">Frank</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/05/18/mona-voronita/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Props from the Master</title>
		<link>http://nodename.com/blog/2009/05/14/props-from-the-master/</link>
		<comments>http://nodename.com/blog/2009/05/14/props-from-the-master/#comments</comments>
		<pubDate>Thu, 14 May 2009 15:52:04 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=133</guid>
		<description><![CDATA[<p>Jim Armstrong, the Flash community&#8217;s primary math whiz, has encouraged me in the past, and today he did so publicly.  I&#8217;m very grateful for this recommendation.</p>
<p>Here&#8217;s the crass part:  I&#8217;m available for contract or permanent work, locally or remotely.  I live in New York City.  CV, references, and samples of my work <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/05/14/props-from-the-master/">Props from the Master</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="http://algorithmist.wordpress.com/">Jim Armstrong</a>, the Flash community&#8217;s primary math whiz, has encouraged me in the past, and today he did so <a href="http://algorithmist.wordpress.com/2009/05/14/alan-shaws-flash-experiments/">publicly</a>.  I&#8217;m very grateful for this recommendation.</p>
<p>Here&#8217;s the crass part:  I&#8217;m available for contract or permanent work, locally or remotely.  I live in New York City.  CV, references, and samples of my work are available.  Please hit the <a href="http://nodename.com/blog/contact/">Contact</a> link to get in touch.</p>
<p>See you in <a href="http://www.flashbelt.com/">Minneapolis</a>?</p>
<p>And we&#8217;ll now return to tech talk&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/05/14/props-from-the-master/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Name of the Node: Image Fill with Spanning Trees</title>
		<link>http://nodename.com/blog/2009/05/12/the-name-of-the-node/</link>
		<comments>http://nodename.com/blog/2009/05/12/the-name-of-the-node/#comments</comments>
		<pubDate>Tue, 12 May 2009 18:31:19 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Delaunay]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[Voronoi]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=118</guid>
		<description><![CDATA[<p>I&#8217;ve rendered some images using the Voronoi Toy from my last post.</p>
<p>I&#8217;ve used my logo 結 (as in 結點 &#8220;node&#8221;) as the input image, run Sakri Rosenstrom&#8217;s image segmentation algorithm on it, dropped 10,000 random points into the segments, and drawn the minimum spanning tree of each set of points, thus creating a sort of space-filling <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/05/12/the-name-of-the-node/">The Name of the Node: Image Fill with Spanning Trees</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve rendered some images using the <a href="http://nodename.com/blog/2009/05/11/a-voronoi-toy/">Voronoi Toy</a> from my last post.</p>
<p>I&#8217;ve used my logo <a href="http://en.wiktionary.org/wiki/結">結</a> (as in 結點 &#8220;node&#8221;) as the input image, run Sakri Rosenstrom&#8217;s <a href="http://www.sakri.net/blog/2009/03/03/extracting-positive-and-negative-shapes-from-a-bitmapdata/">image segmentation algorithm</a> on it, dropped 10,000 random points into the segments, and drawn the minimum spanning tree of each set of points, thus creating a sort of space-filling tree.</p>
<p>The idea for this kind of fill comes from <a href="http://quasimondo.com/">Mario Klingemann</a>&#8216;s presentation at FITC.</p>
<p>Click on each image for a larger version.</p>
<p><center></p>
<p>
<a href="/wpEmbeds/NameoftheNode/JieSpanningLarge.jpg" rel="shadowbox;width=800;height=800"><img src="/wpEmbeds/NameoftheNode/JieSpanningSmall.jpg" alt="" /></a>
</p>
<p>
<a href="/wpEmbeds/NameoftheNode/JieSpanningNegativeLarge.jpg" rel="shadowbox;width=1161;height=1162"><img src="/wpEmbeds/NameoftheNode/JieSpanningNegativeSmall.jpg" alt="" /></a>
</p>
<p></center></p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/05/12/the-name-of-the-node/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Relaxing in the Plane: A Voronoi Toy</title>
		<link>http://nodename.com/blog/2009/05/11/a-voronoi-toy/</link>
		<comments>http://nodename.com/blog/2009/05/11/a-voronoi-toy/#comments</comments>
		<pubDate>Tue, 12 May 2009 01:43:11 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Delaunay]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[Voronoi]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=68</guid>
		<description><![CDATA[relax, v.
10. Chiefly Physics.  To return towards a state of equilibrium. (OED)
 <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/05/11/a-voronoi-toy/">Relaxing in the Plane: A Voronoi Toy</a></span>]]></description>
			<content:encoded><![CDATA[<p>relax, v.<br />
10. Chiefly Physics.  To return towards a state of equilibrium. (OED)</p>
<p>Here&#8217;s the planar analog of my earlier post <a href="http://nodename.com/blog/2008/09/19/distributing-points-on-the-sphere/">Distributing Points on the Sphere</a>.  This time I&#8217;ve ported Steve Fortune&#8217;s <a href="http://netlib.org/voronoi/sweep2">C implementation</a> of his sweepline algorithm for Voronoi diagrams, and applied <a href="http://en.wikipedia.org/wiki/Lloyd's_algorithm">Lloyd&#8217;s algorithm</a> to change the input values (the point locations) iteratively so the output function (the stress or energy) approaches a minimum.  Lloyd&#8217;s algorithm works by repeatedly computing the Voronoi diagram and moving each point to the centroid of its region.  Soon the points converge to an even distribution.  You can see this in action by starting the app by clicking on the image, and then pressing the &#8220;r&#8221; key.</p>
<p>While I was at it I built out some more of the basic Voronoi-related geometric structures: the <a href="http://en.wikipedia.org/wiki/Delaunay_triangulation">Delaunay triangulation</a>, the <a href="http://en.wikipedia.org/wiki/Convex_hull">convex hull</a>, the <a href="http://cgm.cs.mcgill.ca/~orm/ontri.html">onion</a>, and the <a href="http://en.wikipedia.org/wiki/Euclidean_minimum_spanning_tree">minimum spanning tree</a>.</p>
<p>I&#8217;ve had fun playing with this app, changing the display options while moving, adding, or removing points.  I hope you enjoy it.</p>
<p><center><br />
<a href="/wpEmbeds/VoronoiToy/bin/PlanePointsApp.swf" rel="shadowbox;width=860;height=650"><img src="/wpEmbeds/VoronoiToy/Creeper.jpg" alt="" /></a></p>
<p>(The app is built for Flash Player 10.)<br />
 </center></p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/05/11/a-voronoi-toy/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Displace My Shiny Metal Ass</title>
		<link>http://nodename.com/blog/2008/10/25/bender-saves-the-day/</link>
		<comments>http://nodename.com/blog/2008/10/25/bender-saves-the-day/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 04:14:43 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[DisplacementMapFilter]]></category>
		<category><![CDATA[Pixel Bender]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=67</guid>
		<description><![CDATA[... in which it is revealed that Bender's Big Score was actually to provide full floating-point precision to the DisplacementMapFilter! <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2008/10/25/bender-saves-the-day/">Displace My Shiny Metal Ass</a></span>]]></description>
			<content:encoded><![CDATA[<p>A couple of years ago I said, in <a href="http://nodename.com/blog/2006/01/11/prospects-for-immersive-panoramas-in-flash/">Prospects for Immersive Panoramas in Flash</a>:</p>
<blockquote><p>The displacement map in Flash provides only one byte of precision for each of x and y, which means it can map a pixel value from one of at most 128 discrete locations on one side, and only 127 on the other. So when you map pixels over larger distances (which you can do using the scaleX and scaleY parameters of the DisplacementMapFilter constructor), you lose precision.</p></blockquote>
<p>And Psyark said this, in <a href="http://nodename.com/blog/2006/01/16/psyarks-displacementmapfilter-tutorial/" target="_blank">Psyark&#8217;s DisplacementMapFilter Tutorial</a>:</p>
<blockquote><p>Image quality can be improved by using as much as possible of the 0&#215;00～0xFF range of each of the map image components. I won’t go into detail on the procedure, but these are the main points:</p>
<p>1. Multiply the map’s X component by N with 0&#215;80 as a center<br />
2. Divide the map’s scaleX by N</p>
<p>If N is so large that the range 0&#215;00～0xFF is exceeded, adjust it appropriately.</p></blockquote>
<p>So it has been standard practice to set the scaleX and scaleY parameters heuristically to minimize image degradation.</p>
<p>Well in Flash 10 that is all moot, thanks to PixelBender!</p>
<p>Click <a href="/wpEmbeds/BenderDemo/bin/BenderDemo.html" target="_blank">here</a> to open BenderDemo in a new window (requires Flash Player 10 of course).</p>
<p>The program uses a slightly modified version of Ryan Taylor&#8217;s <a href="http://www.boostworthy.com/blog/?p=245">Pixel Bender DisplacementMapFilter</a>.  I&#8217;ve also written an ActionScript wrapper class, DisplacementMapShader, for it.  Both  images are generated using the DisplacementMapShader, the left one with a BitmapData displacement map just as in the DisplacementMapFilter, and the right one using a ByteArray of floats as the displacement map.</p>
<p>There are some interesting API differences between the shader and the built-in DisplacementMapFilter.  Let&#8217;s compare the constructor calls:</p>
<pre>
_displacementMapFilter = new DisplacementMapFilter(_map as BitmapData, null,
BitmapDataChannel.BLUE, BitmapDataChannel.GREEN,
_outputSize, _outputSize,
DisplacementMapFilterMode.COLOR, 0xc0c0c0);

_displacementMapShader = new DisplacementMapShader(_map, new Point(_outputSize/2, _outputSize/2),
BitmapDataChannel.BLUE, BitmapDataChannel.GREEN,
2, 2);
</pre>
<p>First we note the mapPoint parameter, which is defined as &#8220;A value that contains the offset of the upper-left corner of the target display object from the upper-left corner of the map image.&#8221;  We pass <strong>null</strong> to the DisplacementMapFilter to signify that we want the map to be aligned with the input image.  But for the DisplacementMapShader we pass <strong>new Point(_outputSize/2, _outputSize/2)</strong>.  Recall that a Shader has no concept of the image size or location; it operates over a potentially infinite coordinate system.  I believe that this parameter indicates where the origin of the coordinate system is to be located.</p>
<p>Then we have the scaleX and scaleY parameters, &#8220;The multiplier to use to scale the x displacement result from the map calculation&#8221; and &#8220;The multiplier to use to scale the y displacement result from the map calculation.&#8221;  What this means is that the range of the displacement channel data (0 to 255 for the DisplacementMapFilter; 0 to 1 for the DisplacementMapShader), which specifies the range from max negative displacement to max positive displacement, is mapped to the interval we pass in this parameter.  For the DisplacementMapFilter we pass <strong>_outputSize</strong>, indicating a range of the image size, i.e. half that many pixels in the positive direction and half that many pixels in the negative direction.  For the Shader, we pass the value 2, indicating that we want a max negative displacement of 1 and a max positive displacement of 1.  We&#8217;re saying that we want the displacement map to cover a width of two units; this combined with the mapPoint indicates that the map covers a square of width 2 centered at the origin.</p>
<p>Download the <a href="http://nodename.com/wpEmbeds/BenderDemo/BenderDemo.zip">source archive</a>.  Bender saves the day!</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2008/10/25/bender-saves-the-day/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
