<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Daily Flash</title>
	<atom:link href="http://www.stdio.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stdio.co.uk/blog</link>
	<description>Examples and tips for making Flash and Actionscript games</description>
	<lastBuildDate>Sat, 22 May 2010 09:39:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A New Game For Cartoon Network</title>
		<link>http://www.stdio.co.uk/blog/flash/a-new-game-for-cartoon-network/</link>
		<comments>http://www.stdio.co.uk/blog/flash/a-new-game-for-cartoon-network/#comments</comments>
		<pubDate>Fri, 21 May 2010 12:10:00 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Ben10]]></category>
		<category><![CDATA[Cartoon Network]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=156</guid>
		<description><![CDATA[My latest game has just gone live! It&#8217;s a fast paced platform puzzler created for Cartoon Network&#8217;s Ben 10 Series. Kerb produced all of the graphics and animations and they got me in to do the programming.

You can play the game here. Enjoy!
]]></description>
			<content:encoded><![CDATA[<p>My latest game has just gone live! It&#8217;s a fast paced platform puzzler created for Cartoon Network&#8217;s Ben 10 Series. <a href="http://www.kerb.co.uk" target="_blank">Kerb</a> produced all of the graphics and animations and they got me in to do the programming.</p>
<p><a href="http://www.cartoonnetwork.co.uk/show/ben%2010%20alien%20force/games/ben%2010%20vilgax%20takedown" target="_blank"><img src="http://www.stdio.co.uk/blog/wp-content/uploads/ben10.jpg" /></a></p>
<p>You can play the game <a href="http://www.cartoonnetwork.co.uk/show/ben%2010%20alien%20force/games/ben%2010%20vilgax%20takedown" target="_blank">here</a>. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/flash/a-new-game-for-cartoon-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free Subversion Repository</title>
		<link>http://www.stdio.co.uk/blog/general/free-subversion-repository/</link>
		<comments>http://www.stdio.co.uk/blog/general/free-subversion-repository/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 22:59:26 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Free]]></category>
		<category><![CDATA[Springloops]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=154</guid>
		<description><![CDATA[I have a library of code that I use across all of the projects that I work on. I also work across several computers so I thought that it would be handy to have my library in a subversion repository so that I can update and synchronise my library from anywhere. After checking out a [...]]]></description>
			<content:encoded><![CDATA[<p>I have a library of code that I use across all of the projects that I work on. I also work across several computers so I thought that it would be handy to have my library in a subversion repository so that I can update and synchronise my library from anywhere. After checking out a few options I signed up with <a href="http://www.springloops.com/" target="_blank">Springloops</a>. They offer a free service with 100MB storage and up to three projects. This is perfect for personal use and so far it&#8217;s been working really well. That&#8217;s a recommendation from me then!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/general/free-subversion-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conway&#8217;s Game of Life Using a Convolution Filter</title>
		<link>http://www.stdio.co.uk/blog/actionscript/conways-game-of-life/</link>
		<comments>http://www.stdio.co.uk/blog/actionscript/conways-game-of-life/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 22:57:03 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Cellular Automata]]></category>
		<category><![CDATA[ConvolutionFilter]]></category>
		<category><![CDATA[Conway]]></category>
		<category><![CDATA[Game of Life]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=123</guid>
		<description><![CDATA[This is a repost from an old blog I used to have. I&#8217;ve cleaned up the code a bit but the idea remains the same.
Conway&#8217;s Game of Life is an example of a cellular automaton. It is based on a square grid of cells who live or die depending on now many live neighbouring cells [...]]]></description>
			<content:encoded><![CDATA[<p>This is a repost from an old blog I used to have. I&#8217;ve cleaned up the code a bit but the idea remains the same.</p>
<p><a href="http://en.wikipedia.org/wiki/Conway%27s_game_of_life">Conway&#8217;s Game of Life</a> is an example of a cellular automaton. It is based on a square grid of cells who live or die depending on now many live neighbouring cells they have. The obvious way to code this would be to have a two-dimensional array storing the state of each cell and then going through each cell to calculate its new state.</p>
<p>Ugh, boring.</p>
<p>It would be much more fun to use a convolution filter to determine if a cell should live or die. Convolution filters take an array of values (called a kernel) which it treats as a two-dimensional grid whose values determine the colour of a pixel based on the pixels around it. All that&#8217;s needed after that is a palette map to set the variously coloured pixels to their correct alive or dead colours.</p>
<p>Certain starting shapes produce very complex outcomes when the rules are repeatedly applied to the grid. When you click on any of the running demos, a shape called &#8220;the Acorn&#8221; will be drawn at the mouse position and the state of the grid will be updated every frame.</p>
<p>The actionscript source code for this first example is at the end of the post. Click on the image to play the demo of Conway&#8217;s Game of Life:</p>
<p><a href="http://www.stdio.co.uk/blog/wp-content/uploads/Conway_Simple.swf" rel="shadowbox;width=400;height=400;options={flashParams:{bgcolor:'#000000'}}"><img src="http://www.stdio.co.uk/blog/wp-content/uploads/conway_simple.gif" alt="Simple Conway's Game of Life" title="Simple Conway's Game of Life" width="400" height="400" /></a></p>
<p>This is a more refined version where dead pixels are cycled through a palette of decay colours:</p>
<p><a href="http://www.stdio.co.uk/blog/wp-content/uploads/Conway_Decay.swf" rel="shadowbox;width=400;height=400;options={flashParams:{bgcolor:'#000000'}}"><img src="http://www.stdio.co.uk/blog/wp-content/uploads/conway_with_decay.gif" alt="Conway's Game of Life with decay" title="Conway's Game of Life with decay" width="400" height="400" /></a></p>
<p>This is a happy accident I ended up with when I was working out the fastest way of applying the palette of decay colours</p>
<p><a href="http://www.stdio.co.uk/blog/wp-content/uploads/Conway_Mistake.swf" rel="shadowbox;width=400;height=400;options={flashParams:{bgcolor:'#000000'}}"><img src="http://www.stdio.co.uk/blog/wp-content/uploads/conway_mistake.gif" alt="Conway's Game of Life gone wrong" title="Conway's Game of Life gone wrong" width="400" height="400" /></a></p>
<p>Actionscript source code for the first example is available below:<br />
<span id="more-123"></span></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="margin-bottom:20px; font-family:consolas, monospace; white-space:pre-wrap;"><span style="color: #009900; font-style:italic;">/*
Conway's Game of Life using a convolution filter and a palette map.
&nbsp;
In the game of life, cells live or die depending on how many live neighbours
they have. In this version, pixels represent cells and the eight pixels around
every pixel are considered to be the cell's neighbours.
&nbsp;
A convolution filter takes the job of adding up each pixel's number of live
neighbours and setting the pixel's colour to a value that represents that
value. After this, the pixels are palette mapped so the correct pixels are
kept alive. The process is repeated to animate the Game of Life.
&nbsp;
The four rules controlling the system are:
1. Fewer than two live neighbours and the cell dies (Loneliness)
2. Greater than three live neighbours and the cell dies (Overcrowding)
3. Exactly three live neighbours and the cell comes to life (Creation)
4. Exactly two live neighbours and the cell stays how it is (Stasis)
&nbsp;
Alistair Macdonald
http://www.stdio.co.uk/blog
*/</span>
&nbsp;
<span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">Bitmap</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">BitmapData</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">Sprite</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.events</span>.<span style="color: #000000;">Event</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.events</span>.<span style="color: #000000;">MouseEvent</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.filters</span>.<span style="color: #000000;">ConvolutionFilter</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.geom</span>.<span style="color: #000000;">Point</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.geom</span>.<span style="color: #000000;">Rectangle</span>;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #000000;">width</span>=<span style="color: #990000; font-weight: bold;">&quot;400&quot;</span>, <span style="color: #000000;">height</span>=<span style="color: #990000; font-weight: bold;">&quot;400&quot;</span>, <span style="color: #000000;">frameRate</span>=<span style="color: #990000; font-weight: bold;">&quot;30&quot;</span>, <span style="color: #000000;">backgroundColor</span>=<span style="color: #990000; font-weight: bold;">&quot;#000000&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SimpleConway extends <span style="color: #000000;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> static const ALIVE_COLOUR<span style="color: #000000;">:</span><span style="color: #000000;">uint</span> = 0xFFFF0000;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> static const DEAD_COLOUR<span style="color: #000000;">:</span><span style="color: #000000;">uint</span> = 0x00000000;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> static const DISPLAY_SCALE<span style="color: #000000;">:</span><span style="color: #000000;">Number</span> = <span style="color: #000000;">2</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// Bitmap that is shown in the display list.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> displayContainer<span style="color: #000000;">:</span><span style="color: #000000;">Bitmap</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// Bitmap that is used to hold the state of the pixels.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> state<span style="color: #000000;">:</span><span style="color: #000000;">BitmapData</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// Filter used to determine how many </span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// alive neighbours a pixel has.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> countNeighbours<span style="color: #000000;">:</span><span style="color: #000000;">ConvolutionFilter</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// Palette map array used to apply the rules of creation, destruction</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// and stasis on the state bitmap after countNeighbours has been applied.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> applyConwayRules<span style="color: #000000;">:</span><span style="color: #000000;">Array</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// Pre-instantated objects do avoid object creation </span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// during the main event loop.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> point<span style="color: #000000;">:</span><span style="color: #000000;">Point</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #000000;">rect</span><span style="color: #000000;">:</span><span style="color: #000000;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SimpleConway<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> w<span style="color: #000000;">:</span><span style="color: #000000;">int</span> = <span style="color: #000000;">stage</span>.<span style="color: #000000;">stageWidth</span> <span style="color: #000000;">/</span> DISPLAY_SCALE;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> h<span style="color: #000000;">:</span><span style="color: #000000;">int</span> = <span style="color: #000000;">stage</span>.<span style="color: #000000;">stageHeight</span> <span style="color: #000000;">/</span> DISPLAY_SCALE;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">rect</span>.<span style="color: #000000;">width</span> = w;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">rect</span>.<span style="color: #000000;">height</span> = h;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">BitmapData</span><span style="color: #000000;">&#40;</span>w, h, <span style="color: #0033ff; font-weight: bold;">true</span>, DEAD_COLOUR<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayContainer = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Bitmap</span><span style="color: #000000;">&#40;</span>state<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayContainer.<span style="color: #000000;">scaleX</span> = DISPLAY_SCALE;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayContainer.<span style="color: #000000;">scaleY</span> = DISPLAY_SCALE;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">addChild</span><span style="color: #000000;">&#40;</span>displayContainer<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">/* Convolution filter which counts the number of alive neighbours a pixel has. Note the value of 0.5 applied to the source pixel. This allows the filter to carry the state of the state of the source pixel through so the stasis rule can be applied. */</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;countNeighbours = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">ConvolutionFilter</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">3</span>, <span style="color: #000000;">3</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">0.5</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span>, <span style="color: #000000;">8</span>, <span style="color: #000000;">0</span>, <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// Palette map, used after applying countNeighbours to convert from </span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// the pixels' values to their alive or dead colours.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applyConwayRules = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">256</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// Set values which must be counted as alive. All other values</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// will be counted as dead.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// source pixel is alive and has 2 alive neighbours (stasis)</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applyConwayRules<span style="color: #000000;">&#91;</span>0x4D<span style="color: #000000;">&#93;</span> = ALIVE_COLOUR;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// source pixel is alive and has 3 alive neighbours (creation)</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applyConwayRules<span style="color: #000000;">&#91;</span>0x6E<span style="color: #000000;">&#93;</span> = ALIVE_COLOUR;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// source pixel is dead and has 3 alive neighbours (creation)</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applyConwayRules<span style="color: #000000;">&#91;</span>0x5E<span style="color: #000000;">&#93;</span> = ALIVE_COLOUR;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">stage</span>.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, onClick<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">stage</span>.<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, onEnterFrame<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onClick<span style="color: #000000;">&#40;</span>e<span style="color: #000000;">:</span><span style="color: #000000;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// Draw the &quot;acorn&quot; shape at the mouse position. When scaled,</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// displayContainer can return sub-pixel mouse positions so</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// the value is rounded.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #000000;">x</span><span style="color: #000000;">:</span><span style="color: #000000;">int</span> = <span style="color: #000000;">Math</span>.<span style="color: #000000;">round</span><span style="color: #000000;">&#40;</span>displayContainer.<span style="color: #000000;">mouseX</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #000000;">y</span><span style="color: #000000;">:</span><span style="color: #000000;">int</span> = <span style="color: #000000;">Math</span>.<span style="color: #000000;">round</span><span style="color: #000000;">&#40;</span>displayContainer.<span style="color: #000000;">mouseY</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">lock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">setPixel32</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">x</span>, <span style="color: #000000;">y</span>, ALIVE_COLOUR<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">setPixel32</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">-</span><span style="color: #000000;">2</span>, y<span style="color: #000000;">-</span><span style="color: #000000;">1</span>, ALIVE_COLOUR<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">setPixel32</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">-</span><span style="color: #000000;">3</span>, <span style="color: #000000;">y</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span>, ALIVE_COLOUR<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">setPixel32</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">-</span><span style="color: #000000;">2</span>, <span style="color: #000000;">y</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span>, ALIVE_COLOUR<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">setPixel32</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">x</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span>, <span style="color: #000000;">y</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span>, ALIVE_COLOUR<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">setPixel32</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">x</span><span style="color: #000000;">+</span><span style="color: #000000;">2</span>, <span style="color: #000000;">y</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span>, ALIVE_COLOUR<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">setPixel32</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">x</span><span style="color: #000000;">+</span><span style="color: #000000;">3</span>, <span style="color: #000000;">y</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span>, ALIVE_COLOUR<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">unlock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onEnterFrame<span style="color: #000000;">&#40;</span>e<span style="color: #000000;">:</span><span style="color: #000000;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">lock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">applyFilter</span><span style="color: #000000;">&#40;</span>state, <span style="color: #000000;">rect</span>, point, countNeighbours<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">paletteMap</span><span style="color: #000000;">&#40;</span>state, <span style="color: #000000;">rect</span>, point, applyConwayRules, applyConwayRules, applyConwayRules, applyConwayRules<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.<span style="color: #000000;">unlock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/actionscript/conways-game-of-life/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Truncating Text</title>
		<link>http://www.stdio.co.uk/blog/actionscript/truncating-text/</link>
		<comments>http://www.stdio.co.uk/blog/actionscript/truncating-text/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 16:25:56 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Ellipsis]]></category>
		<category><![CDATA[Text]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[Truncate]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=119</guid>
		<description><![CDATA[Here&#8217;s a code snippet that takes a textfield and checks to see if its text is too long to fit in the textfield. If it is, it truncates the text and adds an ellipsis (that&#8217;s three dots to you) to indicate that the text has been truncated.

function truncateText&#40;textField:TextField&#41;:void &#123;
&#160;&#160;&#160;&#160;var text:String = textField.text;
&#160;&#160;&#160;&#160;while &#40;textField.maxScrollV &#62; textField.scrollV&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a code snippet that takes a textfield and checks to see if its text is too long to fit in the textfield. If it is, it truncates the text and adds an ellipsis (that&#8217;s three dots to you) to indicate that the text has been truncated.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="margin-bottom:20px; font-family:consolas, monospace; white-space:pre-wrap;"><span style="color: #339966; font-weight: bold;">function</span> truncateText<span style="color: #000000;">&#40;</span>textField<span style="color: #000000;">:</span><span style="color: #000000;">TextField</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #000000;">text</span><span style="color: #000000;">:</span><span style="color: #000000;">String</span> = textField.<span style="color: #000000;">text</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>textField.<span style="color: #000000;">maxScrollV</span> <span style="color: #000000;">&gt;</span> textField.<span style="color: #000000;">scrollV</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">text</span> = <span style="color: #000000;">text</span>.<span style="color: #000000;">substring</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">text</span>.<span style="color: #000000;">length</span> <span style="color: #000000;">-</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textField.<span style="color: #000000;">text</span> = <span style="color: #000000;">text</span> <span style="color: #000000;">+</span> <span style="color: #990000; font-weight: bold;">&quot;...&quot;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/actionscript/truncating-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Metablobs!</title>
		<link>http://www.stdio.co.uk/blog/actionscript/metablobs/</link>
		<comments>http://www.stdio.co.uk/blog/actionscript/metablobs/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 07:26:47 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[BlendMode]]></category>
		<category><![CDATA[Metaballs]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=107</guid>
		<description><![CDATA[Following on from my last post, it occurred to me that there were a couple of problems with plain metaballs using BlendMode.ADD. Firstly circles are boring. What about having energy fields around other shapes? Secondly, although displaying metaballs using BlendMode.ADD doesn&#8217;t actually give you data about the perimeter of the blob.
In this example, I&#8217;m still [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from my last post, it occurred to me that there were a couple of problems with plain metaballs using BlendMode.ADD. Firstly circles are boring. What about having energy fields around other shapes? Secondly, although displaying metaballs using BlendMode.ADD doesn&#8217;t actually give you data about the perimeter of the blob.</p>
<p>In this example, I&#8217;m still using BlendMode.ADD to display the metaballs but this time I&#8217;m drawing the gradient field around a blob that is modelled by a ring of nodes connected by springs. This is similar to the way I created the Flash version of <a href="http://kerbgames.com/Play/?contentId=707" target="_blank">Loco Roco</a>.</p>
<p>The edge of the blob is smoothed by using the node points as control handles in calls to graphics.drawCurve() and the anchor points as determined by calculating the mean between adjacent nodes. The gradient field is drawn by repeating the calls to drawCurve() and changing the line thickness to build up a gradient line.</p>
<p>What I ended up with is a really blobby simulation as each metaball is springing around instead of being a fixed circular shape. I also have access to a set of points which describe the edge of the blob so I could use this for collision detection or even having blobs join together into larger blobs if they get close enough.</p>
<p>This example also has interaction &#8211; you can grab the blobs and throw them around! Of course all this extra functionality comes at a price so the demo is quite processor intensive. The biggest bottleneck comes from having to draw each individual blob to a bitmap before applying a palette map and then drawing it again to a composite bitmap with blendMode.ADD.</p>
<p>Rather than building up the gradient field using the drawing API, it is also possible to use a blur or convolution filter which would have the same effect of decreasing the value of the pixels as they get further away from the edge of the source blob.</p>
<p><a href="http://www.stdio.co.uk/blog/wp-content/uploads/MetaBlobs.swf" rel="shadowbox;width=400;height=400;options={flashParams:{bgcolor:'#000000'}}"><img src="http://www.stdio.co.uk/blog/wp-content/uploads/metablobs.jpg" alt="TITLE" title="TITLE" width="400" height="300" class="alignnone size-full wp-image-87" /></a>
<p class="imageCaption">Click on the image to play with some metablobs</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/actionscript/metablobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Metaballs With BlendMode.ADD</title>
		<link>http://www.stdio.co.uk/blog/flash/metaballs-with-blendmode-add/</link>
		<comments>http://www.stdio.co.uk/blog/flash/metaballs-with-blendmode-add/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 22:49:07 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[BlendMode]]></category>
		<category><![CDATA[Metaballs]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=90</guid>
		<description><![CDATA[Metaballs are organic looking blobs and are often used to model fluid drops as they join together and pull apart. Usually a metaball is described as a source point with a field around it. As the field moves away from the point, the energy of the field diminishes. When you have several metaballs together, the [...]]]></description>
			<content:encoded><![CDATA[<p>Metaballs are organic looking blobs and are often used to model fluid drops as they join together and pull apart. Usually a metaball is described as a source point with a field around it. As the field moves away from the point, the energy of the field diminishes. When you have several metaballs together, the energy at any given point is simply the sum of all the energies of the metaballs in the system at that point.</p>
<p>The edge of a metaball is linking together areas of the same energy, much like the contours on a map. It is these contours that give the metaball its distinctive blobbiness.</p>
<p>Here&#8217;s a quick example of what I&#8217;m talking about. Click on the image to watch the metaballs in action.</p>
<p><a href="http://www.stdio.co.uk/blog/wp-content/uploads/MetaBalls.swf" rel="shadowbox;width=400;height=400;options={flashParams:{bgcolor:'#000000'}}"><img src="http://www.stdio.co.uk/blog/wp-content/uploads/metaballs.jpg" alt="metabals" title="metaballs" width="400" height="300" class="alignnone size-full wp-image-87" /></a>
<p class="imageCaption">Click on the image to watch some metaballs in action</p>
<p>There are lots of methods for modelling metaballs in two dimensions. One of the best I&#8217;ve come across is <a href="http://www.niksula.hut.fi/~hkankaan/Homepages/metaballs.html" target="_blank">this one</a> which uses a very efficient method for determining the edge of the metaball and then tracing around that edge to define the shape.</p>
<p>An even faster method for displaying metaballs can be achieved by using BlendMode.ADD which does all the adding up of the energy fields for us. If you represent the energy field as a circular gradient starting with blue in the centre (0xFF) and going out to black at the perimeter (0&#215;00) any pixel&#8217;s value in that circle will describe the energy of the field at that point. By overlaying these gradient circles with BlendMode.ADD, the blend mode sums the values of each pixel and displays the sum of energies at that point. All that&#8217;s let to do is apply a palette map to convert the blue energy field to something prettier.</p>
<p>The source code for the example is after the click. There are two classes, one controlling the simulation and the other describing each ball.</p>
<p><span id="more-90"></span></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="margin-bottom:20px; font-family:consolas, monospace; white-space:pre-wrap;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">Bitmap</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">BitmapData</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">Sprite</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.events</span>.<span style="color: #000000;">Event</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.geom</span>.<span style="color: #000000;">Point</span>;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main extends <span style="color: #000000;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> balls<span style="color: #000000;">:</span><span style="color: #000000;">Array</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> ballSprite<span style="color: #000000;">:</span><span style="color: #000000;">Sprite</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> display<span style="color: #000000;">:</span><span style="color: #000000;">BitmapData</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> zeroPoint<span style="color: #000000;">:</span><span style="color: #000000;">Point</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> displayMap<span style="color: #000000;">:</span><span style="color: #000000;">Array</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">Event</span>.<span style="color: #004993;">ADDED_TO_STAGE</span>, <span style="color: #000000;">init</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onEnterFrame<span style="color: #000000;">&#40;</span>e<span style="color: #000000;">:</span><span style="color: #000000;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> ball<span style="color: #000000;">:</span>Ball <span style="color: #0033ff; font-weight: bold;">in</span> balls<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ball.update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// copy the balls to the display bitmap, applying a palette map</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// to make them look pretty</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.<span style="color: #000000;">lock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.<span style="color: #000000;">fillRect</span><span style="color: #000000;">&#40;</span>display.<span style="color: #000000;">rect</span>, 0xFF000000<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.<span style="color: #000000;">draw</span><span style="color: #000000;">&#40;</span>ballSprite<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.<span style="color: #000000;">paletteMap</span><span style="color: #000000;">&#40;</span>display, display.<span style="color: #000000;">rect</span>, zeroPoint, <span style="color: #0033ff; font-weight: bold;">null</span>, <span style="color: #0033ff; font-weight: bold;">null</span>, displayMap, <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.<span style="color: #000000;">unlock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">init</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">:</span><span style="color: #000000;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ballSprite = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">BitmapData</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">stage</span>.<span style="color: #000000;">stageWidth</span>, <span style="color: #000000;">stage</span>.<span style="color: #000000;">stageHeight</span>, <span style="color: #0033ff; font-weight: bold;">true</span>, 0xFF000000<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Bitmap</span><span style="color: #000000;">&#40;</span>display<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zeroPoint = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;balls = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayMap = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">256</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000;">:</span><span style="color: #000000;">int</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i=<span style="color: #000000;">0</span>; i<span style="color: #000000;">&lt;</span><span style="color: #000000;">9</span>; i<span style="color: #000000;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #000000;">x</span><span style="color: #000000;">:</span><span style="color: #000000;">Number</span> = <span style="color: #000000;">Math</span>.<span style="color: #000000;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">*</span> <span style="color: #000000;">stage</span>.<span style="color: #000000;">stageWidth</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #000000;">y</span><span style="color: #000000;">:</span><span style="color: #000000;">Number</span> = <span style="color: #000000;">Math</span>.<span style="color: #000000;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">*</span> <span style="color: #000000;">stage</span>.<span style="color: #000000;">stageHeight</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> ball<span style="color: #000000;">:</span>Ball = <span style="color: #0033ff; font-weight: bold;">new</span> Ball<span style="color: #000000;">&#40;</span><span style="color: #000000;">x</span>, <span style="color: #000000;">y</span>, <span style="color: #000000;">stage</span>.<span style="color: #000000;">stageWidth</span>, <span style="color: #000000;">stage</span>.<span style="color: #000000;">stageHeight</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ballSprite.<span style="color: #000000;">addChild</span><span style="color: #000000;">&#40;</span>ball<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;balls.<span style="color: #000000;">push</span><span style="color: #000000;">&#40;</span>ball<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// set up an array to be used in the palette map which will convert</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// the blue-black balls to red and yellow ones</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i=<span style="color: #000000;">0</span>; i<span style="color: #000000;">&lt;</span><span style="color: #000000;">256</span>; i<span style="color: #000000;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>i <span style="color: #000000;">&lt;</span> 0x3F<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// this corresponds to pixels whose energy value is too low</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayMap<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = <span style="color: #000000;">0</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>i <span style="color: #000000;">&lt;</span> 0x4F<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// this corresponds to pixels at the edge of the blob areas</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// and displays the blobs with a yellow-orange-red gradient</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayMap<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = 0xFF000000 <span style="color: #000000;">|</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>i <span style="color: #000000;">-</span> 0x3F<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&lt;&lt;</span> <span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> foo<span style="color: #000000;">:</span><span style="color: #000000;">uint</span> = <span style="color: #000000;">&#40;</span>i <span style="color: #000000;">-</span> 0x3F<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&lt;&lt;</span> <span style="color: #000000;">20</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// this corresponds to pixels whose energy value is high enough</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// to be considered part of a blob and colours them yellow</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayMap<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = 0xFFFF0000 <span style="color: #000000;">|</span> <span style="color: #000000;">&#40;</span>i <span style="color: #000000;">&lt;&lt;</span> <span style="color: #000000;">8</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, onEnterFrame<span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="margin-bottom:20px; font-family:consolas, monospace; white-space:pre-wrap;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">BlendMode</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">GradientType</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.display</span>.<span style="color: #000000;">Sprite</span>;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #000000;">flash.geom</span>.<span style="color: #000000;">Matrix</span>;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Ball extends <span style="color: #000000;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> xMax<span style="color: #000000;">:</span><span style="color: #000000;">Number</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> yMax<span style="color: #000000;">:</span><span style="color: #000000;">Number</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> vx<span style="color: #000000;">:</span><span style="color: #000000;">Number</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> vy<span style="color: #000000;">:</span><span style="color: #000000;">Number</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Ball<span style="color: #000000;">&#40;</span><span style="color: #000000;">x</span><span style="color: #000000;">:</span><span style="color: #000000;">Number</span>, <span style="color: #000000;">y</span><span style="color: #000000;">:</span><span style="color: #000000;">Number</span>, xMax<span style="color: #000000;">:</span><span style="color: #000000;">Number</span>, yMax<span style="color: #000000;">:</span><span style="color: #000000;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #000000;">x</span> = <span style="color: #000000;">x</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #000000;">y</span> = <span style="color: #000000;">y</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">this</span>.xMax = xMax;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">this</span>.yMax = yMax;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// move the ball</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">x</span> <span style="color: #000000;">+</span>= vx;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">y</span> <span style="color: #000000;">+</span>= vy;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// check for the ball hitting the bounds of the display</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">x</span> <span style="color: #000000;">&lt;</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">x</span>=<span style="color: #000000;">0</span>; vx = <span style="color: #000000;">-</span>vx;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">x</span> <span style="color: #000000;">&gt;</span> xMax<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">x</span>=xMax; vx = <span style="color: #000000;">-</span>vx;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">y</span> <span style="color: #000000;">&lt;</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">y</span>=<span style="color: #000000;">0</span>; vy = <span style="color: #000000;">-</span>vy;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">y</span> <span style="color: #000000;">&gt;</span> yMax<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">y</span>=yMax; vy = <span style="color: #000000;">-</span>vy;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// give the ball a random velocity</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vx = <span style="color: #000000;">Math</span>.<span style="color: #000000;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">*</span> <span style="color: #000000;">20</span> <span style="color: #000000;">-</span> <span style="color: #000000;">10</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vy = <span style="color: #000000;">Math</span>.<span style="color: #000000;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">*</span> <span style="color: #000000;">20</span> <span style="color: #000000;">-</span> <span style="color: #000000;">10</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// draw a gradient circle, blue in the middle and black at the edge</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #000000;">matrix</span><span style="color: #000000;">:</span><span style="color: #000000;">Matrix</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">Matrix</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">matrix</span>.<span style="color: #000000;">createGradientBox</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">200</span>, <span style="color: #000000;">200</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">-</span><span style="color: #000000;">100</span>, <span style="color: #000000;">-</span><span style="color: #000000;">100</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">graphics</span>.<span style="color: #000000;">beginGradientFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">GradientType</span>.<span style="color: #004993;">RADIAL</span>, <span style="color: #000000;">&#91;</span>0xFF, 0x00<span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span>, <span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span>0x00, 0xFF<span style="color: #000000;">&#93;</span>, <span style="color: #000000;">matrix</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">graphics</span>.<span style="color: #000000;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">100</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">graphics</span>.<span style="color: #000000;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900; font-style:italic;">// set the blend mode to ADD so the balls are overlaid properly</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">blendMode</span> = <span style="color: #000000;">BlendMode</span>.<span style="color: #004993;">ADD</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/flash/metaballs-with-blendmode-add/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Box2D World Construction Kit</title>
		<link>http://www.stdio.co.uk/blog/actionscript/box2d-world-construction-kit/</link>
		<comments>http://www.stdio.co.uk/blog/actionscript/box2d-world-construction-kit/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 19:55:41 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=53</guid>
		<description><![CDATA[I haven&#8217;t had a look at the WCK project for quite a while so I thought I&#8217;d better check it out again today. I can&#8217;t believe how far it&#8217;s come on since I first came across it!
The World Construction Kit comprises a load of helper classes for working with and extending Box2D and some jsfl [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t had a look at the <a href="http://www.sideroller.com/wck/" target="_blank">WCK</a> project for quite a while so I thought I&#8217;d better check it out again today. I can&#8217;t believe how far it&#8217;s come on since I first came across it!</p>
<p>The World Construction Kit comprises a load of helper classes for working with and extending Box2D and some jsfl scripts for defining complex polygons. There&#8217;s also a copy of the C++ version of Box2D that has been compiled with Alchemy so it can be used with Actionscript. This should be significantly faster than the native Actionscript version which is a bonus.</p>
<p>There are far too many goodies to list them all here but one of the stand-out features to me is the inclusion of elliptical objects and elliptical segments. The maths behind the collision detection of ellipses is pretty hairy stuff so it&#8217;s really impressive to see this running in Flash.</p>
<p>Here&#8217;s the demo that comes with the source. You can download the source code and demo files from <a href="http://github.com/jesses/wck" target="_blank">GitHub</a>.</p>
<p><a href="http://www.stdio.co.uk/blog/wp-content/uploads/wck_demo.swf" rel="shadowbox;width=720;height=480;options={flashParams:{bgcolor:'#3E81E8'}}"><img src="http://www.stdio.co.uk/blog/wp-content/uploads/wck.jpg" alt="WCK Demo" title="WCK Demo" width="420" height="280" class="alignnone size-full wp-image-87" /></a>
<p class="imageCaption">Click on the image to play with the WCK Demo</p>
<p>I can&#8217;t wait to have a play around with this. Hopefully it will integrate nicely with Boris the Brave&#8217;s <a href="http://personal.boristhebrave.com/project/box2dwith/?q=project/box2dwith" target="_blank">Box2DWith</a> library which has an invaluable xml parser for constructing Box2D simulations.</p>
<p>I&#8217;m so glad that there are people way cleverer than me working hard to make my life easier. Hats of to you, Jesses and BoristheBrave!</p>
<p>Edit: How could I forget to mention Erin Catto, the originator of Box2D? Erin, I salute you sir!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/actionscript/box2d-world-construction-kit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gravity in Box2D</title>
		<link>http://www.stdio.co.uk/blog/actionscript/gravity-in-box2d/</link>
		<comments>http://www.stdio.co.uk/blog/actionscript/gravity-in-box2d/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 22:09:07 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Gravity]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=48</guid>
		<description><![CDATA[I&#8217;ve been using Box2DFlash for quite a few years now. One thing I have always done is set the gravity for the world without thinking about it too much. If I need things to fall down in a game then gravity has got to be the answer. When I made games with shooting in them, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://box2dflash.sourceforge.net/" target="_blank">Box2DFlash</a> for quite a few years now. One thing I have always done is set the gravity for the world without thinking about it too much. If I need things to fall down in a game then gravity has got to be the answer. When I made games with shooting in them, I started to have problems. It&#8217;s easy to make a small object in Box2D that acts as a bullet but if gravity is applied to the bullet it stops going in a straight line when you fire it out of a gun and curves down to the ground instead.</p>
<p>Of course this is perfectly accurate and is what happens in the real world but in games you tend to want bullets to go in a straight line. There are two ways round this problem:</p>
<p>The first is to turn gravity off completely. Any objects that do need to have gravity applied to them can have a downward force applied during each step that you update the Box2D model. This is great if you&#8217;ve just got a few objects that need to react to gravity and most of the rest of the game is static. This line of code applies GRAVITY to the body where the constant GRAVITY is a predefined b2Vec2 vector</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="margin-bottom:20px; font-family:consolas, monospace; white-space:pre-wrap;">const GRAVITY = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">9.81</span><span style="color: #000000;">&#41;</span>;
myBody.ApplyForce<span style="color: #000000;">&#40;</span>GRAVITY, myBody.GetPosition<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>The second method is useful when most things need to react to gravity. You can &#8216;turn off&#8217; gravity on certain objects by applying a force in the opposite direction to the objects that shouldn&#8217;t react to gravity. It&#8217;s the same code as above but with the direction of the gravity vector changed:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="margin-bottom:20px; font-family:consolas, monospace; white-space:pre-wrap;">const ANTI_GRAVITY = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">-</span><span style="color: #000000;">9.81</span><span style="color: #000000;">&#41;</span>;
myBody.ApplyForce<span style="color: #000000;">&#40;</span>ANTI_GRAVITY, myBody.GetPosition<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>When I started using Box2D, I tended to take the way it worked as something you didn&#8217;t touch. It just did it&#8217;s simulation and that was what you were stuck with. Nowadays I&#8217;m far more inclined to hack into the way it works with these kind of tricks. I also love controlling the way objects jump up and fall down to give them a more responsive feel by directly altering their velocities according to what state they are in. The true physics model is no longer sacred for me <img src='http://www.stdio.co.uk/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/actionscript/gravity-in-box2d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What&#8217;s The Daily Flash?</title>
		<link>http://www.stdio.co.uk/blog/general/whats-the-daily-flash/</link>
		<comments>http://www.stdio.co.uk/blog/general/whats-the-daily-flash/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 13:51:32 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=24</guid>
		<description><![CDATA[Apart from being an apt description of my life, the title of this blog comes from the classic Nuggets band “The Daily Flash”. I love 60&#8217;s garage and psychedelic bands so the title seemed like a perfect fit. I&#8217;ve only ever heard one track by the Daily Flash &#8211; &#8220;Jack of Diamonds&#8221; but my partner [...]]]></description>
			<content:encoded><![CDATA[<p>Apart from being an apt description of my life, the title of this blog comes from the classic <a href="http://en.wikipedia.org/wiki/Nuggets:_Original_Artyfacts_from_the_First_Psychedelic_Era,_1965%E2%80%931968" target="_blank">Nuggets</a> band “The Daily Flash”. I love 60&#8217;s garage and psychedelic bands so the title seemed like a perfect fit. I&#8217;ve only ever heard one track by the Daily Flash &#8211; &#8220;Jack of Diamonds&#8221; but my partner <a href="http://www.ronainnes.co.uk" target="_blank">Rona</a> used to have their 80s reissue compilation &#8220;I Flash Daily&#8221;.</p>
<p><img src="http://www.stdio.co.uk/blog/wp-content/uploads/i_flash_daily_front.jpg" alt="Front cover of The Daily Flash&#039;s compilation &quot;I Flash Daily&quot;" title="I Flash Daily front cover" width="413" height="413" class="size-full wp-image-26" /></p>
<p><img src="http://www.stdio.co.uk/blog/wp-content/uploads/i_flash_daily_back.jpg" alt="Back cover of The Daily Flash&#039;s compilation &quot;I Flash Daily&quot;" title="I Flash Daily back cover" width="413" height="415" class="alignnone size-full wp-image-27" /></p>
<p>I love the strapline on the back cover: &#8220;Give us this day our daily flash&#8221;!</p>
<p>As a strange twist of fate, Glasgow label <a href="http://luminous-music.com/Daily_Flash_cd.htm" target="_blank">Luminous Music</a> is re-releasing I Flash Daily this year. Small world, eh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/general/whats-the-daily-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>About this blog</title>
		<link>http://www.stdio.co.uk/blog/general/about-this-blog/</link>
		<comments>http://www.stdio.co.uk/blog/general/about-this-blog/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 18:49:52 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.stdio.co.uk/blog/?p=15</guid>
		<description><![CDATA[Like half of the rest of the blogging world, I&#8217;m using Wordpress to power this blog. All Flash content is displayed using the Shadowbox JS plugin which I&#8217;d highly recommend. It&#8217;s an elegant way to avoid having too many swfs running on the same page which can be a real drain on the processor.
One of [...]]]></description>
			<content:encoded><![CDATA[<p>Like half of the rest of the blogging world, I&#8217;m using Wordpress to power this blog. All Flash content is displayed using the <a href="http://wordpress.org/extend/plugins/shadowbox-js/" target="_blank">Shadowbox JS</a> plugin which I&#8217;d highly recommend. It&#8217;s an elegant way to avoid having too many swfs running on the same page which can be a real drain on the processor.</p>
<p>One of the key plugins I needed was one to format and display source code properly. I tested every syntax highlighting plugin that I could get my hands on and quickly came to two conclusions.</p>
<p>Firstly, I preferred the code to be displayed within &lt;pre&gt; tags. This seemed to be the best way to preserve the formatting of my source code. I didn&#8217;t want to spend ages prettifying source code for my blog &#8211; a simple cut &amp; paste from my IDE was all I wanted to do. Putting the source code between &lt;pre&gt; tags also means I don&#8217;t have to worry about special characters getting messed up when rendered as html.</p>
<p>Secondly I needed a syntax highlighter that could handle Actionscript. Like Javascript, Actionscript is based on the ECMA standard so at a push I could have used a syntax highlighter that worked with Javascript. I quickly found out the most syntax highlighter plugins were using GeSHi at their core which not only supports Actionscript but just about every other programming language known to man (OK, no <a href="http://en.wikipedia.org/wiki/Piet_%28programming_language%29">Piet</a>, but when the source code for the canonical &#8220;Hello World&#8221; application looks like this, you can&#8217;t be too suprised!)</p>
<p><img src="http://upload.wikimedia.org/wikipedia/commons/c/c2/Piet_Program_Hello_World%281%29.gif" /></p>
<p class="imageCaption">This is the source code for displaying &#8220;Hello World&#8221; in Piet. Hmmmm.</p>
<p>The syntax highlighter plugin I eventually settled on was <a href="http://wordpress.org/extend/plugins/wp-syntax/" target="_blank">WP-Syntax</a> and with a bit of tweaking I got my source code looking almost identical to my IDE of choice, Flex Builder.</p>
<p>If you have the excellent monospace font &#8220;Consolas&#8221; installed, that&#8217;s what the code will be displayed in. Since discovering Consolas, I can&#8217;t believe I spent years looking at screens of code displayed in Courier New. Ugh.</p>
<p>Finally, I used the free &#8220;Clean Minimal&#8221; theme from <a href="http://www.themelab.com/" target="_blank">Theme Lab</a> which I tweaked a bit but what you see is 90-something percent how it looked out of the box! The only annoyance was that Theme Lab hadn&#8217;t included a call to wp_head() in header.php so the plugins weren&#8217;t being initialised. Adding the line</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="margin-bottom:20px; font-family:consolas, monospace; white-space:pre-wrap;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_head<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>between the &lt;head&gt;&lt;/head&gt; tags solved that problem but it took me a while to work out why the plugins weren&#8217;t working.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stdio.co.uk/blog/general/about-this-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
