<?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>bgstaal</title>
	<atom:link href="http://bgstaal.net/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://bgstaal.net/blog</link>
	<description>Action speaks louder than words</description>
	<lastBuildDate>Mon, 19 Mar 2012 21:40:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>DMX tube experiment</title>
		<link>http://bgstaal.net/blog/?p=451</link>
		<comments>http://bgstaal.net/blog/?p=451#comments</comments>
		<pubDate>Mon, 19 Mar 2012 21:40:01 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[experiments]]></category>
		<category><![CDATA[dmx]]></category>
		<category><![CDATA[light]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[openframeworks]]></category>
		<category><![CDATA[resonate]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=451</guid>
		<description><![CDATA[Experiment made at @nanikawa's workshop at Resonate 2012. Uses openCV to track phone position and DMX Pro to communicate with the dmx fixture over serial port. ------------ Made with openFrameworks, DMXPro, ofxUI &#38; ofxOpenCV ------------ Code at github.com/bgstaal/DMX-tube-experiment]]></description>
			<content:encoded><![CDATA[<p><iframe src="http://player.vimeo.com/video/38801821?portrait=0&amp;color=ffffff" frameborder="0" width="600" height="337"></iframe></p>
<p>Experiment made at @nanikawa's workshop at Resonate 2012. Uses openCV to track phone position and DMX Pro to communicate with the dmx fixture over serial port.<br />
------------<br />
Made with openFrameworks, DMXPro, ofxUI &amp; ofxOpenCV<br />
------------<br />
Code at <a href="https://github.com/bgstaal/DMX-tube-experiment" rel="nofollow" target="_blank">github.com/bgstaal/DMX-tube-experiment</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=451</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Long Time No See</title>
		<link>http://bgstaal.net/blog/?p=448</link>
		<comments>http://bgstaal.net/blog/?p=448#comments</comments>
		<pubDate>Wed, 01 Jun 2011 20:51:47 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[other]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=448</guid>
		<description><![CDATA[Yeah, I know. Every post in this blog starts out with an excuse for why it is the first post in a decade. The reason for my one year blog neglectance this time around is actually not the result of me being lazy though. Quite the contrary! I've basically just been really busy diving in [...]]]></description>
			<content:encoded><![CDATA[<p>Yeah, I know. Every post in this blog starts out with an excuse for why it is the first post in a decade. The reason for my one year blog neglectance this time around is actually not the result of me being lazy though. Quite the contrary! I've basically just been really busy diving in to a lot of new stuff I've been wanting to learn for some time and have not found the time to tell anyone about it. </p>
<p>Basically I've been trying to become efficient at Javascript development, while trying to pick up on some iOS stuff, while trying to learn C++ & openFrameworks, while having a look at some Java development and in the process getting more into advanced graphics programming with openGL/GLSL, computer vision and physical interaction, as well as trying to learn some more math/physics. On top of that, I have a new found love for electronics prototyping through the Arduino platformt. To say the least my brain is starting to get a bit sweaty!</p>
<p>Anyways. I've decided it might be time to take a small step back from all the consuming and actually start producing! In the process, I hope to find some time to share some of my explorations as well. So let's see if we can't blow some life in to this old blog of mine shall we?</p>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=448</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hairy photos</title>
		<link>http://bgstaal.net/blog/?p=432</link>
		<comments>http://bgstaal.net/blog/?p=432#comments</comments>
		<pubDate>Wed, 03 Feb 2010 22:51:58 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[Fashion]]></category>
		<category><![CDATA[other]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[benjamin]]></category>
		<category><![CDATA[canon]]></category>
		<category><![CDATA[haircut]]></category>
		<category><![CDATA[hairdresser]]></category>
		<category><![CDATA[photographt]]></category>
		<category><![CDATA[toni&guy]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=432</guid>
		<description><![CDATA[[Click photos for full view] I did these photos for a friend of mine who were representing Toni &#38; Guy in the fight for the Norwegian title "Årets Frisør". We were on a very limited budget (If we can use the word budget at all) so we ended up using the cheapest kind of industrial [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bgstaal.net/blog/wp-content/uploads/2010/02/031.jpg"><img class="alignnone size-full wp-image-424" title="041" src="http://bgstaal.net/blog/wp-content/uploads/2010/02/041.jpg" alt="041" width="600" height="400" /></a></p>
<p><a href="http://bgstaal.net/blog/wp-content/uploads/2010/02/011.jpg"><img class="alignnone size-full wp-image-430" title="101" src="http://bgstaal.net/blog/wp-content/uploads/2010/02/101.jpg" alt="101" width="600" height="400" /></a></p>
<p><a href="http://bgstaal.net/blog/wp-content/uploads/2010/02/021.jpg"><img class="alignnone size-full wp-image-426" title="061" src="http://bgstaal.net/blog/wp-content/uploads/2010/02/061.jpg" alt="061" width="600" height="400" /></a></p>
<p>[Click photos for full view]</p>
<p>I did these photos for a friend of mine who were representing Toni &amp; Guy in the fight for the Norwegian title "Årets Frisør". We were on a very limited budget (If we can use the word budget at all) so we ended up using the cheapest kind of industrial lighting and black rug taped to the wall. The backdrops were created separately from a bunch of cityscape photos I caught downtown of Oslo, late fall 2009. Still, I think the result came out pretty nice.</p>
<p>A bunch of thankyous to Daniel for lending me a helping hand &amp; offering creative input, the splendid models, Charlotte, Thea &amp; Julie, who showed up for free &amp; did an awesome job (considering the circumstances), Charlotte nr. 2 for doing the makeup &amp; of course Benjamin, the hairdresser.</p>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=432</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Perspective projection in flash</title>
		<link>http://bgstaal.net/blog/?p=57</link>
		<comments>http://bgstaal.net/blog/?p=57#comments</comments>
		<pubDate>Wed, 06 Jan 2010 12:36:15 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Perspective Projection]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[matrices]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[mesh]]></category>
		<category><![CDATA[point]]></category>
		<category><![CDATA[point 3d]]></category>
		<category><![CDATA[vector]]></category>
		<category><![CDATA[vertex]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=57</guid>
		<description><![CDATA[A while back I was working on a project for a client when I ran into some issues trying to implement a semi 3d design concept. When I did the sketches in photoshop I thought it was gonna be a breeze to implement, but after the design was approved by the client and the deadline was set, I really ran into some trouble. I can´t really go into specifics about this particular project, but the bottom line was that I needed to apply the rules of 3d perspective in some situations, while bending the same rules to fit a dynamic two dimensional layout in other. The result I was looking for just couldn´t be achieved by applying the built in 3d features of Flash 10, or any of the other open source 3d libraries like <a href="http://blog.papervision3d.org/">papervision3d</a> or <a href="http://away3d.com/">away3d</a>. At least not without having a great deal of in depth knowledge of how these libraries work from the ground up. That is why I decided to get my hands dirty with the basics of 3d math.]]></description>
			<content:encoded><![CDATA[
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_SpinningCube_583469435"
			class="flashmovie"
			width="600"
			height="330">
	<param name="movie" value="posts/perspectiveprojection/SpinningCube.swf" />
	<param name="bgcolor" value="#f4f4f4" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="posts/perspectiveprojection/SpinningCube.swf"
			name="fm_SpinningCube_583469435"
			width="600"
			height="330">
		<param name="bgcolor" value="#f4f4f4" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>A while back I was working on a project for a client when I ran into some issues trying to implement a semi 3d design concept. When I did the sketches in photoshop I thought it was gonna be a breeze to implement, but after the design was approved by the client and the deadline was set, I really ran into some trouble. I can´t really go into specifics about this particular project, but the bottom line was that I needed to apply the rules of 3d perspective in some situations, while bending the same rules to fit a dynamic two dimensional layout in other. The result I was looking for just couldn´t be achieved by applying the built in 3d features of Flash 10, or any of the other open source 3d libraries like <a href="http://blog.papervision3d.org/">papervision3d</a> or <a href="http://away3d.com/">away3d</a>. At least not without having a great deal of in depth knowledge of how these libraries work from the ground up. That is why I decided to get my hands dirty with the basics of 3d math.</p>
<p>I found a couple of articles on the subject while browsing for some theory, but since I'm no mathematician, It took me a while to wrap my head around the concepts and really understand the theory, as well as how to take advantage of this in actionscript. After a while though, I finally pieced together the parts I needed to build some simple 3d geometry from scratch, while having full control over each point in both 2d and 3d space. Later on I structured the formulas and functions needed to execute these tasks, into three simple classes that are easy to use, even if you don’t understand the underlying math. Later on I'll explain how to make use of these classes to build the example you see at the very beginning of this article, but first I will try to explain my understanding of the underlying theories.</p>
<h3>Some quick theory.</h3>
<p>Perspective projection is the theory of how to display and move 2d coordinates in relation to each other to make the illusion of 3d space on a flat surface. In our case: it helps us place, draw and move things in the display list, in a way that makes them seem like they exist in 3d space. When doing 3d in flash it can be helpful to imagine the stage as a plane which we view through a camera viewfinder, and that the objects we want to draw are floating behind it. Take a look at the following illustration:</p>
<p>￼<img class="alignnone size-full wp-image-226" title="figure11" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/figure11.jpg" alt="figure11" width="600" height="400" /></p>
<p>Here we see the stage from above, with a camera pointed directly at it's center, and a cube floating behind it. We also see some dotted lines drawn from the center of the camera to each of the cubes corners and the points where these lines intersect with the stage (marked with four small dots). These dots show us where the corner points of the cube should be drawn to create the illusion that we are looking for. The placement of these points clearly show that the four corner points further away from the camera, are placed closer to the where the camera is pointed. The result of drawing this on the stage would look something like this:</p>
<p><img class="alignnone size-full wp-image-227" title="figure2" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/figure2.jpg" alt="figure2" width="600" height="400" /><br />
￼</p>
<h3>The Field of View and the focal length</h3>
<p>Take a look at figure 1 again and take notice of the terms ‘Field of View’ &amp; ‘Focal Length’. These terms are very essential to the concept of perspective projection as they lay down the ground rules for how scale and distance is depicted:</p>
<p><strong>The field of view</strong> is the angle of the observers (or the camera’s) field of vision. It is a value between 0 and 180, where a value close to 180 exaggerates the perspective, as if the image was shot with a fisheye lens, while a value closer to 0 “flattens” the image and under-exaggerates distances between points.</p>
<p><strong>The Focal Length</strong> on the other hand is the z-distance from the observer (camera) to the viewing plane (in this case the stage). This value is closely coupled with the field of view as this distance will have to vary depending on the field of vision, for the outer boundaries of the <a href="http://en.wikipedia.org/wiki/Viewing_frustum">viewing frustum</a> to line up with the stage (more on this later). The focal length is also the main component in the simple formula that is used to calculate the scale and offset (commonly reffered to as the t value) of each point:</p>
<p>￼<img class="alignnone size-full wp-image-232" title="formula" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/formula.jpg" alt="formula" width="600" height="123" /></p>
<p>What we can read from this formula is that the scale and offset of each point is in fact the ratio between the distance from the camera to the stage, and the distance from the camera to the point. The only thing which is left then is to apply the scale and offset to each point by multiplying the x, y, and scale by the t value:</p>
<p><em>example (in pseudo code);</em></p>
<pre class="actionscript">focalLength = <span style="color: #000000;">1000</span>;
&nbsp;
point3d.<span style="color: #000000;">x</span> = <span style="color: #000000;">100</span>;
point3d.<span style="color: #000000;">y</span> = <span style="color: #000000;">50</span>;
point3d.<span style="color: #000000;">z</span> = <span style="color: #000000;">100</span>;
&nbsp;
t = focalLength / <span style="color: #000000;">&#40;</span>focalLength + point3d.<span style="color: #000000;">z</span><span style="color: #000000;">&#41;</span>; <span style="color: #333333; font-style: italic; background-color: #fffde2">// 1000 / (1000+100) == 0.9;</span>
&nbsp;
point2d.<span style="color: #000000;">x</span> = point3d.<span style="color: #000000;">x</span> * t;  <span style="color: #333333; font-style: italic; background-color: #fffde2">// 100 * 0.9 == 90;</span>
point2d.<span style="color: #000000;">y</span> = point3d.<span style="color: #000000;">y</span> * t; <span style="color: #333333; font-style: italic; background-color: #fffde2">// 50 * 1.1 == 45;</span>
point2d.<span style="color: #000000;">scale</span> = <span style="color: #000000;">1</span> * t; <span style="color: #333333; font-style: italic; background-color: #fffde2">// 1 * 0.9 == 0.9;</span>
&nbsp;
<span style="color: #333333; font-style: italic; background-color: #fffde2">/* The projected versjon of 3dPoint (100, 50, 100)
is therefore point2d (90, 45); with a scale of 0.9*/</span></pre>
<h3>Putting theory to practice</h3>
<p>To make these concepts a bit easier to work with in actionscript I wrote three simple classes which provides a good foundation for doing custom 3d transformations and perspective projection in Flash: <a href="http://www.bgstaal.net/docs/perspectiveprojection/net/bgstaal/perspectiveprojection/Point2d.html">Point2d</a>, <a href="http://www.bgstaal.net/docs/perspectiveprojection/net/bgstaal/perspectiveprojection/Point3d.html">Point3d</a> &amp; <a href="http://www.bgstaal.net/docs/perspectiveprojection/net/bgstaal/perspectiveprojection/Matrix3d.html">Matrix3d</a>.  This is the same kind of classes that make up the foundation for well known 3d libraries like papervision3d and away3d, only these classes are a bit easier to work with outside the context of a framework. (There is also a set of equivalent object types that ship with flash player 10 but I have experienced some bugs and actual miscalculations when using them and it seems I am <a href="http://blog.andre-michelle.com/2008/what-is-wrong-with-the-matrix3dtransformvector/#comments">not the only one</a>)</p>
<p>Well, enough with the shit chat, let's get started with building our spinning cube! But first:</p>
<p><a href="http://www.bgstaal.net/blog/posts/perspectiveprojection/perspectiveprojection.zip">&gt; Download source &amp; example class</a><br />
<a href="http://www.bgstaal.net/docs/perspectiveprojection/">&gt; Take a look at  the API documentation</a></p>
<p>Ok. The first thing we will do is set up the base class, it´s imports and class properties, before populating these properties with some values:</p>
<pre class="actionscript"><span style="color: #c000ff;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #7800ff;">import</span> __AS3__.<span style="color: #000000;">vec</span>.<span style="color: #000000;">Vector</span>;
&nbsp;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">display</span>.<span style="color: #000000;">Sprite</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">events</span>.<span style="color: #000000;">Event</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">geom</span>.<span style="color: #000000;">Point</span>;
&nbsp;
	<span style="color: #7800ff;">import</span> net.<span style="color: #000000;">bgstaal</span>.<span style="color: #000000;">perspectiveprojection</span>.<span style="color: #000000;">Matrix3d</span>;
	<span style="color: #7800ff;">import</span> net.<span style="color: #000000;">bgstaal</span>.<span style="color: #000000;">perspectiveprojection</span>.<span style="color: #000000;">Point2d</span>;
	<span style="color: #7800ff;">import</span> net.<span style="color: #000000;">bgstaal</span>.<span style="color: #000000;">perspectiveprojection</span>.<span style="color: #000000;">Point3d</span>;
&nbsp;
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span>widht=<span style="color: #d800ff;">&quot;600&quot;</span>, height=<span style="color: #d800ff;">&quot;330&quot;</span>, backgroundColor=<span style="color: #d800ff;">&quot;0xFFFDE2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #7800ff;">public</span> <span style="color: #c000ff;">class</span> SpinningCube extends Sprite
	<span style="color: #000000;">&#123;</span>
		<span style="color: #7800ff;">private</span> <span style="color: #7800ff;">const</span> COLOR:Number = 0x000000;
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _cubeWidth:Number;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _cubeHeight:Number;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _cubeDepth:Number;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _cubeX:Number;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _cubeY:Number;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _projectionCenter:Point;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fieldOfView:Number;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _focalLength:Number;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _pivotPoint:Point3d;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _3dPoints:Vector.;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _2dPoints:Vector.;
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _rotationX:Number = <span style="color: #000000;">0</span>;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _rotationY:Number = <span style="color: #000000;">0</span>;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _rotationZ:Number = <span style="color: #000000;">0</span>;
&nbsp;
		<span style="color: #7800ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SpinningCube<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			init<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
		<span style="color: #000000;">&#123;</span>
			setProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #333333; font-style: italic; background-color: #fffde2">/**
		 * Set the inital properties for our perspective projection scene
		*/</span>
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setProperties <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
		<span style="color: #000000;">&#123;</span>
			<span style="color: #333333; font-style: italic; background-color: #fffde2">// set the size properties of the cube</span>
			_cubeWidth = <span style="color: #000000;">200</span>;
			_cubeHeight = <span style="color: #000000;">200</span>;
			_cubeDepth = <span style="color: #000000;">200</span>;
&nbsp;
			<span style="color: #333333; font-style: italic; background-color: #fffde2">// Set the position of the cube to the center of the stage</span>
			_cubeX = <span style="color: #000000;">&#40;</span>stage.<span style="color: #000000;">stageWidth</span> - _cubeWidth<span style="color: #000000;">&#41;</span>/<span style="color: #000000;">2</span>;
			_cubeY = <span style="color: #000000;">&#40;</span>stage.<span style="color: #000000;">stageHeight</span> - _cubeHeight<span style="color: #000000;">&#41;</span>/<span style="color: #000000;">2</span>;
&nbsp;
			<span style="color: #333333; font-style: italic; background-color: #fffde2">// Set the projection center (vanishing point) to the center of the stage</span>
			_projectionCenter = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #000000;">&#40;</span>stage.<span style="color: #000000;">stageWidth</span>/<span style="color: #000000;">2</span>, stage.<span style="color: #000000;">stageHeight</span>/<span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #333333; font-style: italic; background-color: #fffde2">// Set the pivot point to be at the 3d center of the cube</span>
			_pivotPoint = <span style="color: #000000; font-weight: bold;">new</span> Point3d<span style="color: #000000;">&#40;</span>_cubeX + <span style="color: #000000;">&#40;</span>_cubeWidth/<span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>, _cubeY + <span style="color: #000000;">&#40;</span>_cubeHeight/<span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>, _cubeDepth/<span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #333333; font-style: italic; background-color: #fffde2">// Set the the field of view to a numver between 1 &amp;amp; 179.</span>
			_fieldOfView = <span style="color: #000000;">55</span>;
&nbsp;
			<span style="color: #333333; font-style: italic; background-color: #fffde2">// Calculate the focal length based on the width of the stage and the field of view.</span>
			<span style="color: #000000; font-weight: bold;">var</span> a:Number = _fieldOfView/<span style="color: #000000;">2</span>;
			<span style="color: #000000; font-weight: bold;">var</span> b:Number = <span style="color: #000000;">90</span> - a;
			<span style="color: #000000; font-weight: bold;">var</span> bRad:Number = b/<span style="color: #000000;">180</span>*Math.<span style="color: #000000;">PI</span>;
			<span style="color: #000000; font-weight: bold;">var</span> opposite:Number = stage.<span style="color: #000000;">stageWidth</span>/<span style="color: #000000;">2</span>;
&nbsp;
			_focalLength = opposite * Math.<span style="color: #000000;">tan</span><span style="color: #000000;">&#40;</span>bRad<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<p>All of these class properties should be self explanatory by now, except for maybe pivotPoint &amp; projectionCenter:</p>
<p><strong>The pivot point</strong> is basically the registration point of the object we are applying transformations to. In this case; The point which the cube is rotated around.</p>
<p><strong>The projection center</strong> is where we would like the center of our imaginary camery to be directed. In this case; The dead center of the stage.</p>
<p>Also take notice of how the <strong>focal length</strong> is calculated (the last couple of lines in the setProperties method) based on the field of view and the stage width. This is done so that the projections coordinate system is aligned with the stage coordinate system. The following figure demonstrates how these calculations are done by splitting the <a href="http://en.wikipedia.org/wiki/Viewing_frustum">viewing frustum</a> into two right angled triangles and applying some simple <a href="http://en.wikipedia.org/wiki/Trigonometry">trigonometry</a>:</p>
<p><img class="alignnone size-full wp-image-265" title="figure3" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/figure3.jpg" alt="figure3" width="600" height="400" /></p>
<p>Next, we set up the 'create3dPoints' method to create the eight corner points of our cube:</p>
<pre class="actionscript"><span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> create3dPoints <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	_3dPoints = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #000000;"><span style="color: #000000;">&#40;</span></span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #333333; font-style: italic; background-color: #fffde2">// add points to create a rectangle of the supplied width and height</span>
	<span style="color: #333333; font-style: italic; background-color: #fffde2">// at the supplied x and y coordinates and a z value of 0</span>
	_3dPoints.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point3d<span style="color: #000000;">&#40;</span>_cubeX, _cubeY, <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	_3dPoints.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point3d<span style="color: #000000;">&#40;</span>_cubeX + _cubeWidth, _cubeY, <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	_3dPoints.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point3d<span style="color: #000000;">&#40;</span>_cubeX + _cubeWidth, _cubeY + _cubeHeight, <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	_3dPoints.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point3d<span style="color: #000000;">&#40;</span>_cubeX, _cubeY + _cubeHeight, <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #333333; font-style: italic; background-color: #fffde2">// then add the same points again with a z value of the supplied depth</span>
	_3dPoints.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point3d<span style="color: #000000;">&#40;</span>_cubeX, _cubeY, _cubeDepth<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	_3dPoints.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point3d<span style="color: #000000;">&#40;</span>_cubeX + _cubeWidth, _cubeY, _cubeDepth<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	_3dPoints.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point3d<span style="color: #000000;">&#40;</span>_cubeX + _cubeWidth, _cubeY + _cubeHeight, _cubeDepth<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	_3dPoints.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point3d<span style="color: #000000;">&#40;</span>_cubeX, _cubeY + _cubeHeight, _cubeDepth<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>Then we set up the projectPoints method which loops through the our eight corner points, calls the project() method (with the focal lenght and projection center supplied as parameters) on each of the instances and populates the _2dPoints Vector with Point2d instances.</p>
<pre class="actionscript"><span style="color: #333333; font-style: italic; background-color: #fffde2">/**
 * Loops through and projects the 3d points to create a vector of 2d points.
 */</span>
<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> projectPoints <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	_2dPoints = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #000000;"><span style="color: #000000;">&#40;</span></span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #7800ff;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:int = <span style="color: #000000;">0</span>; i &amp;lt; _3dPoints.<span style="color: #000000;">length</span>; i++<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> point3d:Point3d = _3dPoints<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>;
&nbsp;
		<span style="color: #333333; font-style: italic; background-color: #fffde2">// calls the project function on each point3d wich reaturns a point2d</span>
		<span style="color: #000000; font-weight: bold;">var</span> point2d:Point2d = point3d.<span style="color: #000000;">project</span><span style="color: #000000;">&#40;</span>_focalLength, _projectionCenter<span style="color: #000000;">&#41;</span>;
		_2dPoints.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span>point2d<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<p>If we take a look at the internals of the Point3d.project() function, we recognize the formula for calculation of the t-value at the first line. The next step would normally  be to offset the x &amp;  y coordinates by this value, but before we can do that we have to make shure that the projection is performed around the cameras projection center. This is done by negatively offsetting the coordinates by the projection center's coordinates, applying the perspective projection, and then reversing the offset. If we just applied the projection right away the final result would look as if the camera was pointed at the top left corner of the stage (0, 0).</p>
<pre class="actionscript"><span style="color: #7800ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> project <span style="color: #000000;">&#40;</span>focalLength:Number, projectionCenter:Point = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>:Point2d
<span style="color: #000000;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> t:Number = focalLength / <span style="color: #000000;">&#40;</span>focalLength+z<span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #7800ff;">if</span> <span style="color: #000000;">&#40;</span>!projectionCenter<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		projectionCenter = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> xOffset:Number = projectionCenter.<span style="color: #000000;">x</span>;
	<span style="color: #000000; font-weight: bold;">var</span> yOffset:Number = projectionCenter.<span style="color: #000000;">y</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> x:Number = this.<span style="color: #000000;">x</span>;
	<span style="color: #000000; font-weight: bold;">var</span> y:Number = this.<span style="color: #000000;">y</span>;
	<span style="color: #000000; font-weight: bold;">var</span> z:Number = this.<span style="color: #000000;">z</span>;
&nbsp;
	x -= xOffset;
	y -= yOffset;
&nbsp;
	x = <span style="color: #000000;">&#40;</span>x*t<span style="color: #000000;">&#41;</span>+xOffset;
	y = <span style="color: #000000;">&#40;</span>y*t<span style="color: #000000;">&#41;</span>+yOffset;
&nbsp;
	<span style="color: #7800ff;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Point2d<span style="color: #000000;">&#40;</span>x, y, t<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>All that is left now before we can get some visual feedback is to draw the points on screen.</p>
<p>To do that we first set up the drawPoints() function:</p>
<pre class="actionscript"><span style="color: #333333; font-style: italic; background-color: #fffde2">/**
 * Draws a circle on stage as a visual representation of each point. Notice that we multiply the radius of each circle by the Point2d instance's t-value to make the scaling of each point smaller or bigger depending on its distance from the camera and thus enhancing the illusion of 3d space.
 */</span>
<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawPoints <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> radius:Number = <span style="color: #000000;">5</span>;
&nbsp;
	graphics.<span style="color: #000000;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #7800ff;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:int = <span style="color: #000000;">0</span>; i &amp;lt; _2dPoints.<span style="color: #000000;">length</span>; i++<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> point2d:Point2d = _2dPoints<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>;
		graphics.<span style="color: #000000;">beginFill</span><span style="color: #000000;">&#40;</span>COLOR<span style="color: #000000;">&#41;</span>;
		graphics.<span style="color: #000000;">drawCircle</span><span style="color: #000000;">&#40;</span>point2d.<span style="color: #000000;">x</span>, point2d.<span style="color: #000000;">y</span>, radius*point2d.<span style="color: #000000;">t</span><span style="color: #000000;">&#41;</span>;
		graphics.<span style="color: #000000;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<p>Then we add add another method to collect all function calls related to the projection:</p>
<pre class="actionscript"><span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createProjection <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	create3dPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	projectPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	drawPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>and make sure we call it from the init function:</p>
<pre class="actionscript"><span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	setProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	createProjection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>Compile &amp; run the application and you should get the following result:</p>
<p><img class="alignnone size-full wp-image-281" title="result1" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/result1.jpg" alt="result1" width="600" height="330" /></p>
<p>I know. Not too exciting yet... But at least we can see that we have done something right! The four corner points at the back of the cube are rendered smaller, and closer to each other, which gives them the appearance of being further away from the camera. Let's move on to the next step and add some rotation by putting the Matrix3d Class to use:</p>
<pre class="actionscript"><span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> rotate3dPoints <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> rotationMatrix:Matrix3d = Matrix3d.<span style="color: #000000;">createRotationMatrix</span><span style="color: #000000;">&#40;</span>_rotationX, _rotationY, _rotationZ<span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #7800ff;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:int = <span style="color: #000000;">0</span>; i &amp;lt; _3dPoints.<span style="color: #000000;">length</span>; i++<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> point3d:Point3d = _3dPoints<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>;
		point3d.<span style="color: #000000;">applyMatrix</span><span style="color: #000000;">&#40;</span>rotationMatrix, _pivotPoint<span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<p>Since all the functionality of creating and multiplying matrices is abstracted in to the Matrix3d class, adding rotation to the cube is as simple as calling a single static function to create a rotation matrix before applying it to the 3d points. We don't even have to think of how these calculations are done, it just works! (that is if we actually supply something else then 0, 0, 0 as parameters, which we will do pretty soon) If you are anything like me though, you would wanna know every little part of how these calculations are done. That is why I will try to explain, as briefly as i can, the basics of matrices and how this is applied to 3d mathematics: (If you're really not that in to masochism you can skip this part and go right on with finishing the application)</p>
<h3>Matrices</h3>
<p>A matrix is basically a two dimensional array (or table) of values. Like this one:</p>
<pre>[1, 0, 0, 0
 0, 1, 0, 0
 0, 0, 1, 0]</pre>
<p>Pretty simple right? Maybe too simple? Well, the power of matrices lies not in the structures themselves but in the way they can be applied to / multiplied with other matrices of various dimensions. They are multiplied in a way where each value in a row is the result of the first value in that row multiplied with the first value in that collumn plus the second value in that row multiplied with the second value in that row and so on:</p>
<p><img class="alignnone size-full wp-image-292" title="figure4" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/figure4.jpg" alt="figure4" width="600" height="600" /></p>
<p>By studying the multiply() function closely we can see the same pattern emerging:</p>
<pre class="actionscript"><span style="color: #7800ff;">public</span> <span style="color: #7800ff;">static</span> <span style="color: #000000; font-weight: bold;">function</span> multiply <span style="color: #000000;">&#40;</span>a:Matrix3d, b:Matrix3d<span style="color: #000000;">&#41;</span>:Matrix3d
<span style="color: #000000;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> c:Matrix3d = <span style="color: #000000; font-weight: bold;">new</span> Matrix3d<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	c.<span style="color: #000000;">n11</span> = a.<span style="color: #000000;">n11</span> * b.<span style="color: #000000;">n11</span> + a.<span style="color: #000000;">n12</span> * b.<span style="color: #000000;">n21</span> + a.<span style="color: #000000;">n13</span> * b.<span style="color: #000000;">n31</span>;
	c.<span style="color: #000000;">n12</span> = a.<span style="color: #000000;">n11</span> * b.<span style="color: #000000;">n12</span> + a.<span style="color: #000000;">n12</span> * b.<span style="color: #000000;">n22</span> + a.<span style="color: #000000;">n13</span> * b.<span style="color: #000000;">n32</span>;
	c.<span style="color: #000000;">n13</span> = a.<span style="color: #000000;">n11</span> * b.<span style="color: #000000;">n13</span> + a.<span style="color: #000000;">n12</span> * b.<span style="color: #000000;">n23</span> + a.<span style="color: #000000;">n13</span> * b.<span style="color: #000000;">n33</span>;
	c.<span style="color: #000000;">n14</span> = a.<span style="color: #000000;">n11</span> * b.<span style="color: #000000;">n14</span> + a.<span style="color: #000000;">n12</span> * b.<span style="color: #000000;">n24</span> + a.<span style="color: #000000;">n13</span> * b.<span style="color: #000000;">n34</span> + a.<span style="color: #000000;">n14</span>;
&nbsp;
	c.<span style="color: #000000;">n21</span> = a.<span style="color: #000000;">n21</span> * b.<span style="color: #000000;">n11</span> + a.<span style="color: #000000;">n22</span> * b.<span style="color: #000000;">n21</span> + a.<span style="color: #000000;">n23</span> * b.<span style="color: #000000;">n31</span>;
	c.<span style="color: #000000;">n22</span> = a.<span style="color: #000000;">n21</span> * b.<span style="color: #000000;">n12</span> + a.<span style="color: #000000;">n22</span> * b.<span style="color: #000000;">n22</span> + a.<span style="color: #000000;">n23</span> * b.<span style="color: #000000;">n32</span>;
	c.<span style="color: #000000;">n23</span> = a.<span style="color: #000000;">n21</span> * b.<span style="color: #000000;">n13</span> + a.<span style="color: #000000;">n22</span> * b.<span style="color: #000000;">n23</span> + a.<span style="color: #000000;">n23</span> * b.<span style="color: #000000;">n33</span>;
	c.<span style="color: #000000;">n24</span> = a.<span style="color: #000000;">n21</span> * b.<span style="color: #000000;">n14</span> + a.<span style="color: #000000;">n22</span> * b.<span style="color: #000000;">n24</span> + a.<span style="color: #000000;">n23</span> * b.<span style="color: #000000;">n34</span> + a.<span style="color: #000000;">n24</span>;
&nbsp;
	c.<span style="color: #000000;">n31</span> = a.<span style="color: #000000;">n31</span> * b.<span style="color: #000000;">n11</span> + a.<span style="color: #000000;">n32</span> * b.<span style="color: #000000;">n21</span> + a.<span style="color: #000000;">n33</span> * b.<span style="color: #000000;">n31</span>;
	c.<span style="color: #000000;">n32</span> = a.<span style="color: #000000;">n31</span> * b.<span style="color: #000000;">n12</span> + a.<span style="color: #000000;">n32</span> * b.<span style="color: #000000;">n22</span> + a.<span style="color: #000000;">n33</span> * b.<span style="color: #000000;">n32</span>;
	c.<span style="color: #000000;">n33</span> = a.<span style="color: #000000;">n31</span> * b.<span style="color: #000000;">n13</span> + a.<span style="color: #000000;">n32</span> * b.<span style="color: #000000;">n23</span> + a.<span style="color: #000000;">n33</span> * b.<span style="color: #000000;">n33</span>;
	c.<span style="color: #000000;">n34</span> = a.<span style="color: #000000;">n31</span> * b.<span style="color: #000000;">n14</span> + a.<span style="color: #000000;">n32</span> * b.<span style="color: #000000;">n24</span> + a.<span style="color: #000000;">n33</span> * b.<span style="color: #000000;">n34</span> + a.<span style="color: #000000;">n34</span>;
&nbsp;
	<span style="color: #7800ff;">return</span> c;
<span style="color: #000000;">&#125;</span></pre>
<p>We abide to the same rules when applying transformation matrices to points. By treating the point as a one dimensional Matrix (also called a vector) and cross multiplying the values in its single column with each of the values in the transformation matrix's rows, we get a new transformed version of that point:</p>
<p>These concepts can be a bit hard to grasp but the bottom line is that this special way of "cross-calculating" the values gives each cell in the table special properties when it comes to transformation. The most obvious ones is the diagnoal values from the top left cell to the third bottom cell. These cells are the ones that relate directly to the scale of each dimension:</p>
<pre>[x, 0, 0, 0
 0, y, 0, 0
 0, 0, z, 0]</pre>
<p>The following matrix (called the identity matrix) for instance, will multiply the x, y and z scale by 1, and therefore leave the subject unchanged:</p>
<pre>[1, 0, 0, 0
 0, 1, 0, 0
 0, 0, 1, 0]</pre>
<p>Rotation matrices look a bit more complicated but is really quite simple to use too. Here are the rotation matrices for all three axes: ("r" being the level of rotation we want to add, in radians)</p>
<pre class="actionscript"><span style="color: #333333; font-style: italic; background-color: #fffde2">// x-rotation (roll)</span>
<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>
 <span style="color: #000000;">0</span>, cos<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, sin<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, <span style="color: #000000;">0</span>
 <span style="color: #000000;">0</span>, -sin<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, cos<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, <span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>
&nbsp;
<span style="color: #333333; font-style: italic; background-color: #fffde2">// y-rotation (pitch)</span>
<span style="color: #000000;">&#91;</span>cos<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, <span style="color: #000000;">0</span>, sin<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, <span style="color: #000000;">0</span>
 <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>
 -sin<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, <span style="color: #000000;">0</span>, cos<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, <span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>
&nbsp;
<span style="color: #333333; font-style: italic; background-color: #fffde2">// z-rotation (yaw)</span>
<span style="color: #000000;">&#91;</span>cos<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, sin<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>
 -sin<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, cos<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>
 <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span></pre>
<p>You might also be wondering what the fourth collumn in the matrix is for? Since there is no fourth row in the matrix, the values in the fourth column has no values to be multiplied with and is therefore just added to the result. Any value placed in one of the cells in this column will therefore be added as an offset (also called translation) along that axis. The following matrix is an example of an translation matrix witch will offset the subject by 2 pixels along the y axis.</p>
<pre>[1, 0, 0, 0
 0, 1, 0, 2
 0, 0, 1, 0]</pre>
<p>The Matrix3d class has methods for creating all these types of transformations through the static methods createScalingMatrix(), createXRotationMatrix(), createYRotationMatrix(), createZRotationMatrix(), createRotationMatrix() &amp; createTranslationMatrix(). do multiplication through the static methods multiply() &amp; multiplySeveral() &amp; apply the transformations to Point3d instances throught the apply() method on either a Matrix3d object (which returns a new Point3d instance) or a Point3d object (which applyes the transformations to that particular instance).</p>
<h3>Finishing up</h3>
<p>Ok. So now we have set up our geometry, projected &amp; drawn it on stage, and written the method responsible for rotating the cube. Next, we will add a call to this method from the createProjection() function: (Note: It is important to add this function call before calling the project() and draw() methods as we want to add the rotation before actually drawing the geometry on stage)</p>
<pre class="actionscript"><span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createProjection <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	create3dPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	rotate3dPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	projectPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	drawPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>If we run the application now we won´t see any changes to the output because the _rotationX, _rotationY &amp; _rotationZ properties are still set to 0. We could very easily add some rotation instantly by setting these properties to something else then zero, but since we want the cube to rotate over time we set up an enter frame listener, call the createProjection() method from there, and then increment one or several rotation properties by the desired amount:</p>
<pre class="actionscript"><span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	setProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	createProjection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	addEventListener<span style="color: #000000;">&#40;</span>Event.<span style="color: #000000;">ENTER_FRAME</span>, enterFrameHandler<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<pre class="actionscript"><span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> enterFrameHandler <span style="color: #000000;">&#40;</span>e:Event<span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	createProjection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	_rotationX += <span style="color: #000000;">4</span>;
	_rotationY += <span style="color: #000000;">4</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>Recompiling and running the app now should give something like the following result:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_SpinningCube3_590733031"
			class="flashmovie"
			width="600"
			height="330">
	<param name="movie" value="posts/perspectiveprojection/SpinningCube3.swf" />
	<param name="bgcolor" value="#f4f4f4" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="posts/perspectiveprojection/SpinningCube3.swf"
			name="fm_SpinningCube3_590733031"
			width="600"
			height="330">
		<param name="bgcolor" value="#f4f4f4" />
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Now we can clearly see that the points are moving in relation to each other in a way that seems in tune with our perception of 3d space. Still, we have left out a crucial part of making the cube seem volumetric: Drawing the lines that connect the points together. I have intentionally left this part out until now to emphasize the fact that computed 3d geometry is nothing more then a collection of points in 3d space (refereed to as vertices in 3d lingo) that together make up a mesh. To make it more obvious, let's connect the dots by adding a drawLines() function:</p>
<pre class="actionscript"><span style="color: #333333; font-style: italic; background-color: #fffde2">/**
 * Draws the lines that connects the eight corners of the cube
 */</span>
<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawLines <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	graphics.<span style="color: #000000;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">1</span>, COLOR<span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #333333; font-style: italic; background-color: #fffde2">// draw the first rectangle</span>
	graphics.<span style="color: #000000;">moveTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">3</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">3</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #333333; font-style: italic; background-color: #fffde2">// draw the second rectangle</span>
	graphics.<span style="color: #000000;">moveTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">5</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">5</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">6</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">6</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">7</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">7</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #333333; font-style: italic; background-color: #fffde2">// draw lines between the corners of the rectangles</span>
	graphics.<span style="color: #000000;">moveTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	graphics.<span style="color: #000000;">moveTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">5</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">5</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	graphics.<span style="color: #000000;">moveTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">6</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">6</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	graphics.<span style="color: #000000;">moveTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">3</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">3</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
	graphics.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>_2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">7</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">x</span>, _2dPoints<span style="color: #000000;">&#91;</span><span style="color: #000000;">7</span><span style="color: #000000;">&#93;</span>.<span style="color: #000000;">y</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>and call that function from the createProjection() method:</p>
<pre class="actionscript"><span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createProjection <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
<span style="color: #000000;">&#123;</span>
	create3dPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	rotate3dPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	projectPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	drawPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	drawLines<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>Recompiling and running the application now should result in something like the spinning cube at the top of this article.</p>
<p>Now we can see clearly that the points in fact make up the geometry of a cube. Still, this simple mesh is not very interesting, and it the process of making it seems maybe a bit too elaborate for such a simple result. If we just wanted to make wireframe 3d-primitives (or even more advanced textured geometry) it would take a lot less work to just use a library like <a href="http://away3d.com/">away3d</a> or <a href="http://blog.papervision3d.org/">papervision3d</a>. The real power of using this manual approach lies in the control we now have of each point in both 2d and 3d space. At anytime we can easily replace the dull, circular representation of each point with any displayObject to create something like a spinning cube of menu-items or a sphere of photos as an alternative to the well known photo carousel. Once we start playing with these concepts the possibilities are endless!</p>
<p>I will follow up this article shortly with some pretty interesting examples of what can be achieved by putting these techniques to use.</p>
<p><em>[Note: The preceding examples are structured in a way that aims to make the code readable and is no way optimized to ensure high performance]</em></p>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=57</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How well do you know Norwegian geography?</title>
		<link>http://bgstaal.net/blog/?p=365</link>
		<comments>http://bgstaal.net/blog/?p=365#comments</comments>
		<pubDate>Tue, 08 Dec 2009 10:56:34 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Graphic Design]]></category>
		<category><![CDATA[Interactive Design]]></category>
		<category><![CDATA[My Work]]></category>
		<category><![CDATA[ditt distrikt]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[norway]]></category>
		<category><![CDATA[oslo]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=365</guid>
		<description><![CDATA[We just launched a quiz game over at Bleed, as a fun way of promoting Ditt Distrikt's new community information services. The game challenges the user to play against other's from their local area to see who has the most geography skills. While doing so, the players also contribute to raising their home county's average [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-383" title="screen061" src="http://bgstaal.net/blog/wp-content/uploads/2009/12/screen061.jpg" alt="screen061" width="600" height="384" /></p>
<p><img class="alignnone size-full wp-image-380" title="screen031" src="http://bgstaal.net/blog/wp-content/uploads/2009/12/screen031.jpg" alt="screen031" width="600" height="384" /></p>
<p><img class="alignnone size-full wp-image-381" title="screen041" src="http://bgstaal.net/blog/wp-content/uploads/2009/12/screen041.jpg" alt="screen041" width="600" height="402" /></p>
<p><img class="alignnone size-full wp-image-385" title="screen101" src="http://bgstaal.net/blog/wp-content/uploads/2009/12/screen101.jpg" alt="screen101" width="600" height="384" /></p>
<p><img class="alignnone size-full wp-image-384" title="screen071" src="http://bgstaal.net/blog/wp-content/uploads/2009/12/screen071.jpg" alt="screen071" width="600" height="384" /></p>
<p>We just launched a quiz game over at <a title="bleed" href="http://bleed.no" target="_self">Bleed</a>, as a fun way of promoting <a title="ditt distrikt" href="http://www.dittdistrikt.no" target="_self">Ditt Distrikt's</a> new community information services. The game challenges the user to play against other's from their local area to see who has the most geography skills. While doing so, the players also contribute to raising their home county's average score in the pursuit of being the best county in Norway.</p>
<p>Design, art direction &amp; development by <a href="http://www.bgstaal.net">me.</a></p>
<p>You can check out the game at <a href="http://www.dittdistrikt-spillet.no" target="_self">dittdistrikt-spillet.no</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=365</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>There and back again</title>
		<link>http://bgstaal.net/blog/?p=339</link>
		<comments>http://bgstaal.net/blog/?p=339#comments</comments>
		<pubDate>Sun, 08 Nov 2009 21:32:00 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[other]]></category>
		<category><![CDATA[anti]]></category>
		<category><![CDATA[bleed]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[employer]]></category>
		<category><![CDATA[interactive designer]]></category>
		<category><![CDATA[Interior]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=339</guid>
		<description><![CDATA[I guess I'm the latest person to announce this, but nothing is better than hearing it directly from the source right? Anyways, the big news is that I'm going back to work at Bleed! (Well, actually I have been working there for about a month already, but things have been so busy that I have [...]]]></description>
			<content:encoded><![CDATA[<p><a title="bleed" href="http://www.bleed.no"><img class="alignnone size-full wp-image-344" title="logo2" src="http://bgstaal.net/blog/wp-content/uploads/2009/11/logo2.jpg" alt="logo2" width="600" height="400" /></a></p>
<p>I guess I'm the latest person to announce this, but nothing is better than hearing it directly from the source right? Anyways, the big news is that I'm going back to work at <a href="http://www.bleed.no">Bleed!</a> (Well, actually I have been working there for about a month already, but things have been so busy that I have had no real time to sit down and think about it, let alone write about it).</p>
<p>For those you who don't know: I used to work there until some of my colleges broke out to start a new company, <a href="http://www.anti.as">Anti</a>, and I was asked to join. I stayed there for about a year before deciding to return to to my former employer a couple of months ago. As much as I like the people at <a href="http://www.anti.as">Anti</a> and the stuff they produce, I started feeling a bit lonely as the only developer/designer with a clear focus on interactive medias.</p>
<p>Looking forward, I am really excited about all the cool stuff happening at <a href="http://www.bleed.no">Bleed</a>: We have just launched a new web &amp; identity, our new offices are nearly finished and a couple of promising interns are joining us over the next couple of months. With several new &amp; exciting clients and plans for an independent exhibition/book release in the pipeline, I'm shure that this is the beginning of the Bleed renaissance!</p>
<p>I'll keep you posted as soon as I have more news. In the meantime, be shure to check out <a href="http://www.bleed.no">our new site</a> and take a look at some photos from our first week in the new offices:</p>
<p><img class="alignnone size-full wp-image-342" title="bleed02" src="http://bgstaal.net/blog/wp-content/uploads/2009/11/bleed02.jpg" alt="bleed02" width="600" height="400" /></p>
<p><img class="alignnone size-full wp-image-341" title="bleed01" src="http://bgstaal.net/blog/wp-content/uploads/2009/11/bleed01.jpg" alt="bleed01" width="600" height="400" /></p>
<p><img class="alignnone size-full wp-image-340" title="bleed00" src="http://bgstaal.net/blog/wp-content/uploads/2009/11/bleed00.jpg" alt="bleed00" width="600" height="400" /></p>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=339</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Format Number as Currency</title>
		<link>http://bgstaal.net/blog/?p=176</link>
		<comments>http://bgstaal.net/blog/?p=176#comments</comments>
		<pubDate>Tue, 15 Sep 2009 15:15:03 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[Actionscript3]]></category>
		<category><![CDATA[cents]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[converter]]></category>
		<category><![CDATA[currency]]></category>
		<category><![CDATA[dollars]]></category>
		<category><![CDATA[euro]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[kroner]]></category>
		<category><![CDATA[money]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=176</guid>
		<description><![CDATA[Just had the need to format some numbers into different currencies the other day so I made a simple, generic function to do the trick. Example: var dollars:String = &#34;$&#34; + currencyFormat&#40;343769.5&#41;; var euro:String = &#34;€ &#34; + currencyFormat&#40;150, 2, &#34;.&#34;, &#34;,&#34;&#41; var nok:String = currencyFormat&#40;10500, 2, &#34;.&#34;, &#34;,&#34;&#41; + &#34;,-&#34; &#160; trace&#40;dollars&#41; // $343,769.50 [...]]]></description>
			<content:encoded><![CDATA[<p>Just had the need to format some numbers into different currencies the other day so I made a simple, generic function to do the trick.</p>
<p>Example:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> dollars:String = <span style="color: #d800ff;">&quot;$&quot;</span> + currencyFormat<span style="color: #000000;">&#40;</span><span style="color: #000000;">343769.5</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> euro:String = <span style="color: #d800ff;">&quot;€ &quot;</span> + currencyFormat<span style="color: #000000;">&#40;</span><span style="color: #000000;">150</span>, <span style="color: #000000;">2</span>, <span style="color: #d800ff;">&quot;.&quot;</span>, <span style="color: #d800ff;">&quot;,&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000; font-weight: bold;">var</span> nok:String = currencyFormat<span style="color: #000000;">&#40;</span><span style="color: #000000;">10500</span>, <span style="color: #000000;">2</span>, <span style="color: #d800ff;">&quot;.&quot;</span>, <span style="color: #d800ff;">&quot;,&quot;</span><span style="color: #000000;">&#41;</span> + <span style="color: #d800ff;">&quot;,-&quot;</span>
&nbsp;
trace<span style="color: #000000;">&#40;</span>dollars<span style="color: #000000;">&#41;</span> <span style="color: #333333; font-style: italic; background-color: #fffde2">// $343,769.50</span>
trace<span style="color: #000000;">&#40;</span>euro<span style="color: #000000;">&#41;</span> <span style="color: #333333; font-style: italic; background-color: #fffde2">// €150,00</span>
trace<span style="color: #000000;">&#40;</span>nok<span style="color: #000000;">&#41;</span> <span style="color: #333333; font-style: italic; background-color: #fffde2">// 10.500 ,-</span></pre>
<p>source:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">function</span> currencyFormat <span style="color: #000000;">&#40;</span>number:Number, numDecimals:int = <span style="color: #000000;">2</span>, separatorSymbol:String = <span style="color: #d800ff;">&quot;,&quot;</span>, decimalSymbol:String = <span style="color: #d800ff;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span>:String
<span style="color: #000000;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> multiplier:int = Math.<span style="color: #000000;">pow</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">10</span>, numDecimals<span style="color: #000000;">&#41;</span>;
	number = Math.<span style="color: #000000;">round</span><span style="color: #000000;">&#40;</span>number*multiplier<span style="color: #000000;">&#41;</span>/multiplier;
	number = round<span style="color: #000000;">&#40;</span>number, numDecimals<span style="color: #000000;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> string:String; = number.<span style="color: #000000;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> split:Array = string.<span style="color: #000000;">split</span><span style="color: #000000;">&#40;</span><span style="color: #d800ff;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> pre:String = split<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> post:String = split<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span> == <span style="color: #000000; font-weight: bold;">null</span> ? <span style="color: #d800ff;">&quot;&quot;</span> : split<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span>;
&nbsp;
	<span style="color: #333333; font-style: italic; background-color: #fffde2">// Format Number</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> _pre:String = pre.<span style="color: #000000;">slice</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	pre = <span style="color: #d800ff;">&quot;&quot;</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> count:int = <span style="color: #000000;">0</span>;
	<span style="color: #7800ff;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:int = _pre.<span style="color: #000000;">length</span>; i &gt;= <span style="color: #000000;">0</span>; i--<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> cypher:String = _pre.<span style="color: #000000;">charAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #7800ff;">if</span> <span style="color: #000000;">&#40;</span>count % <span style="color: #000000;">3</span> == <span style="color: #000000;">0</span> &amp;&amp; count &gt; <span style="color: #000000;">0</span> &amp;&amp; i &gt; <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			cypher = separatorSymbol + cypher;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		pre = cypher + pre;
		count ++;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #333333; font-style: italic; background-color: #fffde2">// Format decimals</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> numMissingDecimals:int = numDecimals - post.<span style="color: #000000;">length</span>;
	<span style="color: #7800ff;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:int = <span style="color: #000000;">0</span>; i &lt; numMissingDecimals; i++<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		post += <span style="color: #d800ff;">&quot;0&quot;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #333333; font-style: italic; background-color: #fffde2">// Join the strings</span>
&nbsp;
	string = pre;
	<span style="color: #7800ff;">if</span> <span style="color: #000000;">&#40;</span>numDecimals &gt; <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		string += decimalSymbol + post;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #7800ff;">return</span> string;
<span style="color: #000000;">&#125;</span></pre>
<p>Do with it as you wish!</p>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=176</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anti Sweden Web</title>
		<link>http://bgstaal.net/blog/?p=189</link>
		<comments>http://bgstaal.net/blog/?p=189#comments</comments>
		<pubDate>Wed, 09 Sep 2009 22:09:39 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Fashion]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Graphic Design]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[My Work]]></category>
		<category><![CDATA[anti]]></category>
		<category><![CDATA[antisweden]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[motion graphics]]></category>
		<category><![CDATA[shop]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=189</guid>
		<description><![CDATA[I have really had a lot of things going on both at work &#38; at home for the last couple of months, which has resulted in no posts at all since June. Pretty lame stuff! Anyways! One of the projects I have been working on is the Anti Sweden website, which was launched just a [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-183" title="01" src="http://bgstaal.net/blog/wp-content/uploads/2009/09/01.jpg" alt="01" width="600" height="382" /></p>
<p><img class="alignnone size-full wp-image-188" title="06" src="http://bgstaal.net/blog/wp-content/uploads/2009/09/06.jpg" alt="06" width="600" height="382" /></p>
<p><img class="alignnone size-full wp-image-184" title="02" src="http://bgstaal.net/blog/wp-content/uploads/2009/09/02.jpg" alt="02" width="600" height="382" /></p>
<p><img class="alignnone size-full wp-image-186" title="04" src="http://bgstaal.net/blog/wp-content/uploads/2009/09/04.jpg" alt="04" width="600" height="382" /></p>
<p><img class="alignnone size-full wp-image-195" title="08" src="http://bgstaal.net/blog/wp-content/uploads/2009/09/08.jpg" alt="08" width="600" height="382" /></p>
<p>I have really had a lot of things going on both at work &amp; at home for the last couple of months, which has resulted in no posts at all since June. Pretty lame stuff! Anyways! One of the projects I have been working on is the <a title="antisweden" href="http://www.antisweden.no" target="_self">Anti Sweden website</a>, which was launched just a few weeks ago. The site is a pretty simple, news driven site, with some very basic shop functionality and one or two nifty graphical details.</p>
<p>About the project:</p>
<blockquote><p>"We at the Norwegian design office <a href="http://www.anti.as" target="_blank">Anti</a> wanted to use our experience and knowledge of design to create our own brand - a brand that reflected our love of fashion, of graphic design, and which reflected the unremitting darkness that is at the heart of the Norwegian identity and is the seat of true Black Metal. Anti Sweden is that unholy creation!"</p></blockquote>
<p><a href="http://www.behance.net/FredrikMelby" target="_self">Fredrik Melby</a> is the main man responsible for the Art Direction &amp; Graphic Design, closely supervised by Creative Director <a href="http://www.anti-ink.com" target="_self">Kjetil Wold</a>. The main illustrations are done by <a href="http://www.vberkvlt.com/" target="_self">Justin Bartlett</a>, photography by <a href="http://www.alexfreund.com/" target="_self">Alex Freund</a> &amp; <a href="http://www.mariust.com/" target="_self">Marius Tharaldsen</a>, motion graphics by <a href="http://www.stormstudios.no/" target="_self">Storm Studios</a>, music by <a href="http://www.myspace.com/sunnofuneraldoom" target="_self">Sunn O)))</a> and motion design + development by <a href="http://www.bgstaal.net" target="_self">yours truly</a>.</p>
<p>Visit the site <a title="antisweden" href="http://antisweden.no" target="_blank">here</a>, and be shure to pick up a pair of true norwegian black jeans!</p>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=189</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Joy Division EQ</title>
		<link>http://bgstaal.net/blog/?p=163</link>
		<comments>http://bgstaal.net/blog/?p=163#comments</comments>
		<pubDate>Wed, 01 Jul 2009 21:23:18 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Graphic Design]]></category>
		<category><![CDATA[Interactive Design]]></category>
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=163</guid>
		<description><![CDATA[I just love the cover art for the Joy Division album Unknown Pleasures and I have had this idea for a while to try to create something interactive based on the main illustration. So here is my first attempt: The "Joy Division Equalizer". For now it is just a rough sketch and the code is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.bgstaal.net/experiments/joydivisioneq/"><img class="alignnone size-full wp-image-164" title="screen" src="http://bgstaal.net/blog/wp-content/uploads/2009/07/screen.jpg" alt="screen" width="600" height="600" /></a></p>
<p>I just love the cover art for the <a href="http://www.myspace.com/joydivision">Joy Division</a> album <a href="http://en.wikipedia.org/wiki/Unknown_Pleasures">Unknown Pleasures</a> and I have had this idea for a while to try to create something interactive based on the main illustration. So here is my first attempt: The <a href="http://www.bgstaal.net/experiments/joydivisioneq/">"Joy Division Equalizer"</a>. For now it is just a rough sketch and the code is very very quick and dirty, but I think it looks kinda' cool. <a href="http://www.bgstaal.net/experiments/joydivisioneq/">Click here</a> to check it out.</p>
<p>Here is the dirrrrrrty source: (Written &amp; Compiled in <a href="http://www.adobe.com/products/flex/">Flex Builder 3</a>)</p>
<pre class="actionscript">&nbsp;
<span style="color: #c000ff;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">display</span>.<span style="color: #000000;">Graphics</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">display</span>.<span style="color: #000000;">Sprite</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">display</span>.<span style="color: #000000;">StageAlign</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">display</span>.<span style="color: #000000;">StageScaleMode</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">events</span>.<span style="color: #000000;">Event</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">geom</span>.<span style="color: #000000;">Rectangle</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">media</span>.<span style="color: #000000;">Sound</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">media</span>.<span style="color: #000000;">SoundMixer</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">net</span>.<span style="color: #000000;">URLRequest</span>;
	<span style="color: #7800ff;">import</span> flash.<span style="color: #000000;">utils</span>.<span style="color: #000000;">ByteArray</span>;
&nbsp;
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span>backgroundColor=<span style="color: #d800ff;">&quot;0x000000&quot;</span>, width=<span style="color: #d800ff;">&quot;1440&quot;</span>, height=<span style="color: #d800ff;">&quot;900&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #7800ff;">public</span> <span style="color: #c000ff;">class</span> JoyDivisionEQ extends Sprite
	<span style="color: #000000;">&#123;</span>
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _numLines:int = <span style="color: #000000;">60</span>;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _numSegments:int = <span style="color: #000000;">40</span>;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _spectrumStartSegment:int = <span style="color: #000000;">10</span>;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _spectrumEndSegment:int = <span style="color: #000000;">30</span>;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _maxSpectrumHeight:Number = <span style="color: #000000;">120</span>;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _rect:Rectangle = <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">400</span>, <span style="color: #000000;">500</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _noiseOffset:Number = <span style="color: #000000;">3</span>;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _sound:Sound;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _stretchFactor:Number = <span style="color: #000000;">2</span>;
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _wrapper:Sprite;
&nbsp;
		<span style="color: #7800ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> JoyDivisionEQ<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			init<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
		<span style="color: #000000;">&#123;</span>
			setStageProps<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			createWrapper<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			playSong<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			addEventListener<span style="color: #000000;">&#40;</span>Event.<span style="color: #000000;">ENTER_FRAME</span>, enterFrameHandler<span style="color: #000000;">&#41;</span>;
			stage.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span>Event.<span style="color: #000000;">RESIZE</span>, stageResizeHandler<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setStageProps <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
		<span style="color: #000000;">&#123;</span>
			stage.<span style="color: #000000;">frameRate</span> = <span style="color: #000000;">30</span>;
			stage.<span style="color: #000000;">scaleMode</span> = StageScaleMode.<span style="color: #000000;">NO_SCALE</span>;
			stage.<span style="color: #000000;">align</span> = StageAlign.<span style="color: #000000;">TOP_LEFT</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> enterFrameHandler <span style="color: #000000;">&#40;</span>e:Event<span style="color: #000000;">&#41;</span>:void
		<span style="color: #000000;">&#123;</span>
			draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> playSong <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
		<span style="color: #000000;">&#123;</span>
			_sound = <span style="color: #000000; font-weight: bold;">new</span> Sound<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #000000;">&#40;</span><span style="color: #d800ff;">&quot;shadowplay.mp3&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			_sound.<span style="color: #000000;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">100</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createWrapper <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
		<span style="color: #000000;">&#123;</span>
			_wrapper = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			_wrapper.<span style="color: #000000;">x</span> = <span style="color: #000000;">&#40;</span>stage.<span style="color: #000000;">stageWidth</span> - _rect.<span style="color: #000000;">width</span><span style="color: #000000;">&#41;</span>/<span style="color: #000000;">2</span>;
			_wrapper.<span style="color: #000000;">y</span> = <span style="color: #000000;">&#40;</span>stage.<span style="color: #000000;">stageHeight</span> - _rect.<span style="color: #000000;">height</span><span style="color: #000000;">&#41;</span>/<span style="color: #000000;">2</span>;
			this.<span style="color: #000000;">addChild</span><span style="color: #000000;">&#40;</span>_wrapper<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> draw <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:void
		<span style="color: #000000;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> xSpacing:Number = _rect.<span style="color: #000000;">width</span>/_numSegments;
			<span style="color: #000000; font-weight: bold;">var</span> ySpacing:Number = _rect.<span style="color: #000000;">height</span>/_numLines;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> ba:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			SoundMixer.<span style="color: #000000;">computeSpectrum</span><span style="color: #000000;">&#40;</span>ba, <span style="color: #000000; font-weight: bold;">true</span>, _stretchFactor<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> g:Graphics = _wrapper.<span style="color: #000000;">graphics</span>;
			g.<span style="color: #000000;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #7800ff;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:int = <span style="color: #000000;">0</span>; i &lt; _numLines; i++<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> y:Number = ySpacing*i;
				g.<span style="color: #000000;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>, y<span style="color: #000000;">&#41;</span>;
				g.<span style="color: #000000;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">1</span>, 0xFFFFFF<span style="color: #000000;">&#41;</span>;
				g.<span style="color: #000000;">beginFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> start:int = _spectrumStartSegment - <span style="color: #000000;">2</span> + <span style="color: #000000;">&#40;</span><span style="color: #000000;">4</span>*Math.<span style="color: #000000;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000; font-weight: bold;">var</span> end:int = _spectrumEndSegment - <span style="color: #000000;">2</span> + <span style="color: #000000;">&#40;</span><span style="color: #000000;">4</span>*Math.<span style="color: #000000;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000; font-weight: bold;">var</span> length:Number = end - start;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> prevY:Number;
&nbsp;
				<span style="color: #7800ff;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> j:int = <span style="color: #000000;">1</span>; j &lt;  _numSegments<span style="color: #000000;">-1</span>; j++<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #7800ff;">if</span> <span style="color: #000000;">&#40;</span>ba.<span style="color: #000000;">position</span> == <span style="color: #000000;">200</span>*_stretchFactor<span style="color: #000000;">&#41;</span>
					<span style="color: #000000;">&#123;</span>
						ba.<span style="color: #000000;">position</span> = <span style="color: #000000;">20</span>*_stretchFactor;
					<span style="color: #000000;">&#125;</span>
&nbsp;
					<span style="color: #000000; font-weight: bold;">var</span> _y:Number = y;
&nbsp;
					<span style="color: #7800ff;">if</span> <span style="color: #000000;">&#40;</span>j &gt;= start &amp;&amp; j&lt;= end<span style="color: #000000;">&#41;</span>
					<span style="color: #000000;">&#123;</span>
						<span style="color: #000000; font-weight: bold;">var</span> k:Number = j - start;
						<span style="color: #000000; font-weight: bold;">var</span> ratio:Number = <span style="color: #000000;">&#40;</span>k/length<span style="color: #000000;">&#41;</span>;
						<span style="color: #7800ff;">if</span> <span style="color: #000000;">&#40;</span>ratio &gt; <span style="color: #000000;">0.5</span><span style="color: #000000;">&#41;</span>
						<span style="color: #000000;">&#123;</span>
							ratio = <span style="color: #000000;">1</span>-ratio;
						<span style="color: #000000;">&#125;</span>
						<span style="color: #000000; font-weight: bold;">var</span> amp:Number = _maxSpectrumHeight*ratio;
&nbsp;
						<span style="color: #7800ff;">if</span> <span style="color: #000000;">&#40;</span>j % <span style="color: #000000;">1</span> == <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span>
						<span style="color: #000000;">&#123;</span>
							<span style="color: #000000; font-weight: bold;">var</span> num:Number;
							_y = y - Math.<span style="color: #000000;">abs</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>ba.<span style="color: #000000;">readFloat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>*amp<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #000000;">&#125;</span>
						<span style="color: #7800ff;">else</span>
						<span style="color: #000000;">&#123;</span>
							_y = prevY + <span style="color: #000000;">10</span> - <span style="color: #000000;">&#40;</span><span style="color: #000000;">10</span>*Math.<span style="color: #000000;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
&nbsp;
					_y = _y - <span style="color: #000000;">&#40;</span>_noiseOffset/<span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span> + <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>_noiseOffset/<span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>*Math.<span style="color: #000000;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
					g.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>xSpacing*j, _y<span style="color: #000000;">&#41;</span>;
					prevY = _y;
				<span style="color: #000000;">&#125;</span>
&nbsp;
				g.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span>xSpacing*<span style="color: #000000;">&#40;</span>j<span style="color: #000000;">+1</span><span style="color: #000000;">&#41;</span>, y<span style="color: #000000;">&#41;</span>;
				g.<span style="color: #000000;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				g.<span style="color: #000000;">lineTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>, y<span style="color: #000000;">&#41;</span>;
				g.<span style="color: #000000;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #7800ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> stageResizeHandler <span style="color: #000000;">&#40;</span>e:Event<span style="color: #000000;">&#41;</span>:void
		<span style="color: #000000;">&#123;</span>
			_wrapper.<span style="color: #000000;">x</span> = <span style="color: #000000;">&#40;</span>stage.<span style="color: #000000;">stageWidth</span> - _rect.<span style="color: #000000;">width</span><span style="color: #000000;">&#41;</span>/<span style="color: #000000;">2</span>;
			_wrapper.<span style="color: #000000;">y</span> = <span style="color: #000000;">&#40;</span>stage.<span style="color: #000000;">stageHeight</span> - _rect.<span style="color: #000000;">height</span><span style="color: #000000;">&#41;</span>/<span style="color: #000000;">2</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=163</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Inspiring Interior / Exterior</title>
		<link>http://bgstaal.net/blog/?p=134</link>
		<comments>http://bgstaal.net/blog/?p=134#comments</comments>
		<pubDate>Thu, 25 Jun 2009 22:09:10 +0000</pubDate>
		<dc:creator>bgstaal</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[Interior Design]]></category>
		<category><![CDATA[Furniture]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[House]]></category>
		<category><![CDATA[Interior]]></category>

		<guid isPermaLink="false">http://bgstaal.net/blog/?p=134</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pitsou.com/"><img class="alignnone size-full wp-image-136" title="pitsou" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/pitsou.jpg" alt="pitsou" width="600" height="399" /></a></p>
<p><a href="http://www.pitsou.com/"><img class="alignnone size-full wp-image-137" title="pitsou" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/pitsou2.jpg" alt="pitsou2" width="600" height="399" /></a></p>
<p><a href="http://www.docmobili.it/"><img class="alignnone size-full wp-image-140" title="docmobili" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/docmobili.jpg" alt="docmobili" width="600" height="399" /></a></p>
<p><a href="http://www.xtenarchitecture.com/"><img class="alignnone size-full wp-image-144" title="xten architecture" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/xten.jpg" alt="xten" width="600" height="399" /></a></p>
<p><a href="http://www.xtenarchitecture.com/"><img class="alignnone size-full wp-image-145" title="xten architecture" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/xten2.jpg" alt="xten2" width="600" height="399" /></a></p>
<p><a href="http://www.mcbridecharlesryan.com.au"><img class="alignnone size-full wp-image-146" title="charles ryan mcbride" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/mcbride.jpg" alt="mcbride" width="600" height="399" /></a></p>
<p><a href="http://www.mcbridecharlesryan.com.au"><img class="alignnone size-full wp-image-147" title="charles ryan mcbride" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/mcbride2.jpg" alt="mcbride2" width="600" height="399" /></a></p>
<p><a href="http://www.marciokogan.com.br/"><img class="alignnone size-full wp-image-153" title="marcio kogan" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/marcio.jpg" alt="marcio" width="600" height="399" /></a></p>
<p><a href="http://www.marciokogan.com.br/"><img class="alignnone size-full wp-image-154" title="marcio kogan" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/marcio2.jpg" alt="marcio2" width="600" height="399" /></a></p>
<p><a href="http://www.marciokogan.com.br/"><img class="alignnone size-full wp-image-155" title="marcio kogan" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/marcio3.jpg" alt="marcio3" width="600" height="399" /></a></p>
<p><a href="http://www.nytimes.com/slideshow/2009/02/12/garden/20090212-dub-slideshow_index.html"><img class="alignnone size-full wp-image-139" title="nyc" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/nytimes.jpg" alt="nyc" width="600" height="399" /></a></p>
<p><a href="http://www.aidlindarlingdesign.com/"><img class="alignnone size-full wp-image-152" title="aidlin darling" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/aidlin2.jpg" alt="aidlin2" width="600" height="399" /></a></p>
<p><a href="http://www.aidlindarlingdesign.com/"><img class="alignnone size-full wp-image-151" title="aidlin darling" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/aidlin.jpg" alt="aidlin" width="600" height="399" /></a></p>
<p><a href="http://www.mathiasklotz.com"><img class="alignnone size-full wp-image-143" title="mathias klotz" src="http://bgstaal.net/blog/wp-content/uploads/2009/06/mathiasklotz.jpg" alt="mathiasklotz" width="600" height="399" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://bgstaal.net/blog/?feed=rss2&#038;p=134</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

