<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/templates/rss.xsl"?><!--
	how to skin an rss feed by nathan@webr3.org
-->
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
	<rdf:Description rdf:about="http://webr3.org/blog/"
    	dc:identifier="http://webr3.org/blog/"
    	dc:title="WebR3"
    	trackback:ping="http://webr3.org/blog/" />
</rdf:RDF>
-->
<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>webr3.org &#187; experiments</title>
	<atom:link href="http://webr3.org/blog/category/experiments/feed/" rel="self" type="application/rss+xml" />
	<link>http://webr3.org/blog</link>
	<description>the personal blog of nathan :)</description>
	<lastBuildDate>Fri, 12 Mar 2010 02:24:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Forced Coding</title>
		<link>http://webr3.org/blog/general/forced-coding/</link>
		<comments>http://webr3.org/blog/general/forced-coding/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 20:30:40 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[experiments]]></category>
		<category><![CDATA[general]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=150</guid>
		<description><![CDATA[
update:
I've been off for a week after finishing a project and moving house, in that time this domain dropped and just prior to that appeared to get 20k+ reads which is a bit omg. Anyways many comments all over the net, and certainly on reddit (comments here) - and thus just to clarify, the entire [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://webr3.org/blog/wp-content/uploads/2009/09/forced-coding.jpg" alt="forced-coding" title="forced-coding" width="600" height="250" class="alignnone size-full wp-image-151" /></p>
<p>update:<br />
I've been off for a week after finishing a project and moving house, in that time this domain dropped and just prior to that appeared to get 20k+ reads which is a bit omg. Anyways many comments all over the net, and certainly on reddit (<a href="http://www.reddit.com/r/programming/comments/9s1n8/forced_coding/">comments here</a>) - and thus just to clarify, the entire content of this post is purely a note to myself, and to help me in those times when you can't get going in the morning or such like.. in no way am I suggesting you don't plan or do things properly whenever you can - this is literally just some ways of getting through the day. Thought I'd made that clear and most people got it ;)<br />
end update:</p>
<p>This one is more for my own reference, but sharing anyways as it may help others. In numerous scenarios it is really hard to "get going" when you're trying to code, particularly under the following circumstances:</p>
<p> * You haven't started coding till late(r) in the day<br />
 * Emails, Blogs, Social networking have taken up more time than expected and/or distracted more than anticipated<br />
 * You've just completed a deliverable, milestone or task.<br />
 * You're tired!</p>
<p>All of these are virtually daily occurances in the coding world, and here are the methods I've used to get going again.. no particular order, just a list.</p>
<p><strong>Under all circumstance, avoid planning!</strong><br />
Planning is one of those things you can't do unless you are all ready in the flow, whether this is because you've just had a client meeting, a long discussion, or read a full spec - it's not the thing to do to get your flow going, all you'll do is plan nothing, plan badly, or stare blankly at the screen / paper.</p>
<p><strong>Don't read related material to get you in the flow.</strong><br />
This will purely serve to distract you, make you think about doing things differently, doublt what you've done or worse throw you in to planning mode - fact is you won't be planning "your" app though, you'll be planning "some" ideal app or scenario.</p>
<p><strong>Pick the smallest task, whether complex or not, and just do it!</strong><br />
Doesn't matter what it is, so long as it's coding a little part of the app, or modifying part of it, then it'll do. It could be adding an extra field to an object or table, popping in some validation, anything small and simple. It really doesn't matter if you do it right or wrong; you're not doing it to sign off a task, you're doing it to re-aquaint yourself with your system, by the time you've been through X lines of code you'll be back in work mode and firing on all cylinders, well on your way to getting zoned.</p>
<p><strong>Music, Headphones, Repeat.</strong><br />
You'll know the genre that suits you, personally I find repeating an album or even song fades me in to the zone and keeps me there. The repetitiveness of the tune keeps you there, because just as a phone call can distract you, so can a change in tune to something at a different tempo or worse a completely different genre.</p>
<p><strong>Don't cram!</strong><br />
If you've only got 15 minutes before the next sizable interuption, forget it, don't do anything just chill - make a coffee, smoke, whatever. You're not wasting time you're saving your zone, you can only get zoned a couple of times a day, so don't get zoned for only 15 minutes - save it and get zoned for longer later on.</p>
<p><strong>Speedcode</strong><br />
Why not? as nike say "just do it", if the code has 10 bugs but is finished in half the time then you've done good, that gives you loads of time to fix the bugs, and more importantly you get to those moments where you realise x,y&#038;z need to be changed much quicker. Not only that, but would you rather have a week to go and have a list of 80 bugs, or a week to go and 2 major deliverables a week overdue..</p>
<p><strong>Communicate for no reason.</strong><br />
Often a major focus is simply talking to somebody else on the same project as you, whether its the client or a workmate, and the more stressed they are the better, they'll not only blast you with things but their urgency / stress will often convey straight over to you and focus / zone you instantly.</p>
<p><strong>Do the thing you know, not the thing you don't.</strong><br />
Inline with "don't plan" and "pick the smallest task", always pick something you can already do (if possible), as with everything else, the things you don't know are much easier when you're already zoned, not only that but you'll be more focussed when doing the thing you don't know so less likely to over spec / over code it.</p>
<p><strong>Don't code other things!</strong><br />
nothing on earth will kill your project like working on something else, every minute you spend on another script or app is like an hour lost on what you should be doing, and with every minute that passes you're getting closer and closer to utter project failure - and hence why most open source projects are dead.</p>
<p>Remember, the key to forced coding is just to get you in the zone, and ultimately boils down to just getting stuck in there with some lines of code on your project.</p>
<p>Works for me anyways [most of the time] - if anybody has anything to add (constructive) then please do!</p>
<p>Regards - nathan</p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/general/forced-coding/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>PHP Events - Actionscript 3 style events in PHP 5</title>
		<link>http://webr3.org/blog/experiments/php-events-actionscript-3-style-events-in-php-5/</link>
		<comments>http://webr3.org/blog/experiments/php-events-actionscript-3-style-events-in-php-5/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 17:33:12 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Event Listener]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[multi site systems]]></category>
		<category><![CDATA[Negation]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Serialization]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=111</guid>
		<description><![CDATA[Here are a set of classes which aim to provide basic actionscript style events in php5;
The Point - Events are useful everywhere even when you don't have a UI, the main reason for building this was to create a kind of "hook" system for php. Often we create multi site systems where each implementation of [...]]]></description>
			<content:encoded><![CDATA[<p>Here are a set of classes which aim to provide basic actionscript style events in php5;</p>
<p><strong>The Point </strong>- Events are useful everywhere even when you don't have a UI, the main reason for building this was to create a kind of "hook" system for php. Often we create multi site systems where each implementation of that system has different client specific considerations; consider a system where one client wants all of there images to go to amazon s3 instead of being saved on the host like your other clients. With this system you can simply:</p>
<ol>
<li>throw an "storeUpload" event which is cancelable</li>
<li>register a default event listener which listens for "storeUpload" events and provides default functionality, saving the upload and setting the location (ur) on the event.target</li>
<li>on one site register a custom event listener which listens for the "storeUpload" event, uploads to amazon s3, then cancels the event and set the event.target to the s3 url instead</li>
</ol>
<p>as you can see, with this you can keep the codebase of your multisite application the same and simply hook in to events whereever you want.</p>
<p>the system consists of 2 public classes:</p>
<h3>Event</h3>
<p>The base class for all events, provides event type and cancelable; with typical usage you create a new event, then dispatch it when ready.</p>
<ul>
<li><strong>__construct</strong>( $type , $cancelable=FALSE )<br />
create a new event listener - if you extend the Event class you must call this with parent::__construct( $type , $cancelable );</p>
<p><strong>$type</strong> - string, event type eg "debugEvent"<br />
<strong>$cancelable</strong> - boolean, provides cancelation functionality, so you can prevent further event listeners from firing thus in effect overriding them.</p>
<p>throws InvalidArgumentException if $type is not a string</li>
<li><strong>cancel</strong>() : void<br />
cancels an event, only if it is cancelable</li>
<li><strong>isCancelable</strong>() : Boolean</li>
<li><strong>isCanceled</strong>() : Boolean</li>
<li><strong>getType</strong>() : string</li>
<li><strong>getTarget</strong>() : obj<br />
target always contains the instance which dispatched the event.</li>
</ul>
<h3>EventDispatcher</h3>
<p>All classes which wish to dispatch events must inherit from EventDispatcher (like in most languages), this class provides:</p>
<ul>
<li><strong>addEventListener</strong>( $type , $callable , $owner ) : void<br />
adds an event listener, this may be a function, a class method or a static class method.<br />
note: a current limitation is that event listener methods must be public</p>
<p><strong>$type</strong> - string, event type eg "debugEvent"<br />
<strong>$callable</strong> - string, the function or method which is to be called when event $type is dispatched<br />
<strong>$owner</strong> - mixed, used when $callable is a method, can be either an object instance, or the string name of a class for static methods.</p>
<p><strong>throws:</strong><br />
InvalidArgumentException when type or callable isn't a string<br />
Exception('unknown method / function')</li>
<li><strong>removeEventListener</strong>( $type , $callable , $owner ) : void<br />
removes an event listener that has been added with addEventListener, this only removes a single event listener each call, so if you have 3 identical event listeners you will need to call this method 3 times to remove them all.</p>
<p>arguments are the same as addEventListener - throws no exceptions, always returns void</li>
<li><strong>hasEventListener</strong>( $type ) : Boolean<br />
checks if any event listeners are registered for event $type; always returns boolean true or false.</li>
<li><strong>dispatchEvent</strong>( Event $event ) : void<br />
the obvious one, dispatches an event and notifies all listeners.</li>
</ul>
<h3>Notes:</h3>
<p>The event dispatcher implements a function which hides all instance properties starting with __ from the serialize process, thus hiding the events and meaning your current serialization process will still work, additionally you can utilize it to hide any properties you don't want to be serialized.</p>
<p>I've tried to make the classes as simple, small and practical as possible, they execute rather quickly and shouldn't make any speed difference to your application - do however be aware that loosely coupling and entire system could allow coding errors to creep in, so maybe don't use it everywhere - but then PHP isn't strict anyways so..!</p>
<h2>Download</h2>
<p>You can download the <a href="http://webr3.org/experiments/php/PHPEvents.zip">PHP Event system</a> here (3 classes + example, 4.2k) - hope somebody finds it useful!</p>
<p><img class="alignnone size-full wp-image-112" title="events" src="http://webr3.org/blog/wp-content/uploads/2009/07/events.jpg" alt="events" width="600" height="250" /></p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/experiments/php-events-actionscript-3-style-events-in-php-5/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using Sound.extract to create visualizations.</title>
		<link>http://webr3.org/blog/haxe/using-sound-extract-to-create-visualizations/</link>
		<comments>http://webr3.org/blog/haxe/using-sound-extract-to-create-visualizations/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 20:19:35 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[3D computer graphics]]></category>
		<category><![CDATA[Computer memory]]></category>
		<category><![CDATA[Data buffer]]></category>
		<category><![CDATA[Frame rate]]></category>
		<category><![CDATA[Sampling]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=101</guid>
		<description><![CDATA[
Technically, this is a really stupid thing to do, and move over it isn't the cleverest thing to do, regardless though I've done it just for the hell of it.
The aim of this post is to prevent anybody else from making the same stupid mistakes! end product isn't too bad though.
To give a quick over [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://webr3.org/experiments/sound/sound-extract-visualize/"><img class="alignnone size-full wp-image-102" title="sound" src="http://webr3.org/blog/wp-content/uploads/2009/07/sound.jpg" alt="sound" width="600" height="250" /></a></p>
<p>Technically, this is a really stupid thing to do, and move over it isn't the cleverest thing to do, regardless though I've done it just for the hell of it.</p>
<p>The aim of this post is to prevent anybody else from making the same stupid mistakes! end product isn't too bad though.</p>
<p>To give a quick over view, Sound.extract() gives access to raw sound data, as a ByteArray of floats; typically you setup two sound objects, the first loads the sound data from source, the second requests sound data from the first at regular intervals, extracting 2048-8192 samples per request and then playing it - idea is that in the method that requests the samples you can quickly pre-process it before its played and make some nice effects.</p>
<p>So my illogical train of thought was to visualize the raw sound data in real time as it plays to create some nice effects.</p>
<h3>The Numbers Game</h3>
<p>Music in flash is sampled at 44100 Hz Stereo - 44100 samples per second,  per channel - we're getting it at intervals of either 2048, 4096 or 8192 samples - meaning our visualization can run at either 21.53fps,  10.76fps or 5.45fps - which lets be honest is hardly going to make a nice smooth effect is it.</p>
<p>So our only option is to somehow synchronize the "timeline" (the screen updating) with the raw sound being played.</p>
<h3>The Approach</h3>
<p>I decided the only real way to do this was to make a continual buffer of sound that could be read independently by both the SampleDataEvent and by my own code to do the visualizations - after some playing around with numbers I finally gathered that if one was to run at a framerate of 63fps and render the 700 samples per channel at a time then I'd be consuming (63*700 = 41000 Hz / samples per second) = the data in realtime.</p>
<p>To make this possible I needed some kind of fast buffer to store the data in, obvious choice was fast memory which is a ByteArray and can be read and written to directly.</p>
<p>More number came in to play when the size of the buffer needed calculated, had to be a multiple of both the render speed (700) and the data feed rate (2048); which is a buffer of 358400 samples, or sample requests. (358400/175 = 2048).</p>
<p>To get the data in to the buffer I was finding the next offset at which i should write the data to my buffer, sound.extract'ing the data in to the buffer and using a modulo to create wrap around so after 175 samples data was written back at the start.</p>
<p>This covers getting the sound in to a fast memory buffer without consuming too many resources, next up to get it out and render it!</p>
<h3>The Rendering</h3>
<p>Rendering uses the same idea of requesting samples from the buffer, however this time the magic number is (358400/700 =) 512.</p>
<p>I implemented a simple framecounter that increments each frame and resets to 0 every 512 frames (giving the loop on the buffer), then quickly read 700 pairs of samples from the buffer each frame.</p>
<p>The left channel float value is then scaled by 300 used as an X position, whilst the right channel creates the Y position - both x and y are then fed to setPixel() on BitmapData whilst a simple calculation of 0xFFFFFF*leftChannel / 2 sets the color value.</p>
<p>Each frame the 700 dual channel samples are rendered creating 700 realtime 2D particles (hopefully) in time with the sound, and a simple blur filter is used to clear the previous frame in a nicer way.</p>
<h3>The Point</h3>
<p>It's all stupid, pointless and just stick to computeSpectrum - you only get 256 samples rather than 700 but it's perfectly in time and allows you do something other than exactly 63 fps; further it'll always be in time with the music.</p>
<h3>The Result</h3>
<p>Well, it's here - I've got it tuned in to my other halfs <a href="http://citybeatradio.org/" target="_blank">radio station citybeat radio</a> at the minute (which i wholeheartedly recommend for any electronic / trance music fans) and well.. <a href="http://webr3.org/experiments/sound/sound-extract-visualize/">here it is with source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/using-sound-extract-to-create-visualizations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Massive amount of 3D Particles Take Two</title>
		<link>http://webr3.org/blog/haxe/massive-amount-of-3d-particles-take-two/</link>
		<comments>http://webr3.org/blog/haxe/massive-amount-of-3d-particles-take-two/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 15:45:16 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=71</guid>
		<description><![CDATA[
Ralph Hauwert created a great demo of the power of Flash 10 / PixelBender / Alchemy  that you're probably familiar with, then Joa Ebert made a fantastic Flash 9 pure AS3 version that's very impressive, then I gave it a go with haXe and flash.Memory which turned out rather well too.
It's been bugging me [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-72" title="take2" src="http://webr3.org/blog/wp-content/uploads/2009/06/take2.jpg" alt="take2" width="600" height="250" /></p>
<p>Ralph Hauwert created a great <a href="http://www.unitzeroone.com/blog/2009/03/18/flash-10-massive-amounts-of-3d-particles-with-alchemy-source-included/" target="_blank">demo of the power of Flash 10 / PixelBender / Alchemy </a> that you're probably familiar with, then Joa Ebert made a fantastic <a href="http://blog.joa-ebert.com/2009/04/03/massive-amounts-of-3d-particles-without-alchemy-and-pixelbender/">Flash 9 pure AS3 version</a> that's very impressive, then I gave it <a href="http://webr3.org/blog/haxe/flash-10-massive-amounts-of-3d-particles-with-haxe/">a go with haXe and flash.Memory</a> which turned out rather well too.</p>
<p>It's been bugging me for some time that the code just wasn't real world enough though - so I thought I'd give it a go using AS3 and flash 10, using only native methods and no fancy 3D calculations that us commoners don't quite get. In short I've stripped it down and turned it into a simple class which uses flash 10 Vectors and Matrix3D.</p>
<p>I've taken a different approach with these demo's, rather than all in realtime, you simply click and it runs the enterFrame code once and displays the time in ms that it took. There is however a <a href="http://webr3.org/experiments/particle-pusher-take2/realtime/">final realtime version</a> using this code at the end.</p>
<p>Four examples are provided, Pure AS3, then the same code converted to haxe, then the haxe "inline" keyword added and finally the whole thing working in realtime.</p>
<h2>AS3 Flash 10 Version with Vector / Matrix3D</h2>
<p>Here's the main source used:</p>
<pre class="brush: as3;">private function enterFrameHandler( event : Event ): void {
 var d : Date = new Date();
 var t : Number = d.getTime();

 updateMatrix( mouseX , mouseY );
 _matrix.transformVectors( particleVector , realVector );

 var pxs : Vector.&amp;lt;uint&amp;gt; = new Vector.&amp;lt;uint&amp;gt;( PIXELS , true );
 var po : int = 0;
 var a : int = 0;

 while( a &amp;lt; PARTICLES ) {
   po = pointToOffset( int(realVector[a*3]) , int(realVector[(a*3)+1]) , WIDTH );
   if( 0 &amp;lt; po &amp;amp;&amp;amp; po &amp;lt; PIXELS) {
     pxs[po] = increaseColor( pxs[po] );
   }
   a++;
 }
 // update display
 this.bitmapData.lock();
 this.bitmapData.setVector( this.bitmapData.rect , pxs );
 this.bitmapData.unlock( this.bitmapData.rect );

 d = new Date();
 textField.text = &quot;single frame time: &quot; + ( d.getTime() - t );
}

private function updateMatrix( mx : Number , my : Number ) : void {
 tx = tx + ((mx - tx)/10);
 ty = ty + ((my - ty)/10);
 _matrix.identity();
 _matrix.appendRotation( tx , Vector3D.Y_AXIS );
 _matrix.appendRotation( ty , Vector3D.X_AXIS );
 _matrix.appendTranslation( CX, CY, 10 );
}

private static function increaseColor( c : uint ) : uint {
 return c &amp;lt; MAXCOLOR ? c + SHADE : 0xFFFFFF;
}

private static function pointToOffset( vx : int , vy : int , vw : int ) : uint {
 return vx + ( vy * vw );
}
</pre>
<p><a href="http://webr3.org/experiments/particle-pusher-take2/pure-as3/" target="_blank">And here's the AS3 result (with full source)</a></p>
<h2>The same code in haXe</h2>
<p>next up I spent literally 2 minutes converting this to haXe syntax, changed no functionality - just slight syntax changes between the languages.</p>
<pre class="brush: plain;">private function enterFrameHandler( event : Event ) : Void {
 var d : Date = Date.now();
 var t : Float = d.getTime();

 updateMatrix( mouseX , mouseY );
 _matrix.transformVectors( particleVector , realVector );

 var pxs : Vector&amp;lt;UInt&amp;gt; = new Vector&amp;lt;UInt&amp;gt;( PIXELS , true );
 var po : Int = 0;
 var a : Int = 0;

 while( a &amp;lt; PARTICLES ) {
   po = pointToOffset( Std.int(realVector[a*3]) , Std.int(realVector[(a*3)+1]) , WIDTH );
   if( 0 &amp;lt; po &amp;amp;&amp;amp; po &amp;lt; PIXELS) {
     pxs[po] = increaseColor( pxs[po] );
   }
   a++;
 }
 // update display
 this.bitmapData.lock();
 this.bitmapData.setVector( this.bitmapData.rect , pxs );
 this.bitmapData.unlock( this.bitmapData.rect );

 d = Date.now();
 textField.text = &quot;single frame time: &quot; + ( d.getTime() - t );
}

private function updateMatrix( mx : Float , my : Float ) : Void {
 tx = tx + ((mx - tx)/10);
 ty = ty + ((my - ty)/10);
 _matrix.identity();
 _matrix.appendRotation( tx , Vector3D.Y_AXIS );
 _matrix.appendRotation( ty , Vector3D.X_AXIS );
 _matrix.appendTranslation( CX, CY, 10 );
}

private static function increaseColor( c : UInt ) : UInt {
 return c &amp;lt; MAXCOLOR ? c + SHADE : 0xFFFFFF;
}

private static function pointToOffset( vx : Int , vy : Int , vw : Int ) : UInt {
 return vx + ( vy * vw );
}</pre>
<p><a href="http://webr3.org/experiments/particle-pusher-take2/identical/" target="_blank">And here's the identical haXe result (with full source)</a></p>
<h2>Optimized haXe Version</h2>
<p>Next up I spent another minute optimizing (literally, one minute) - haXe supports inlining of variables and methods, so I added the inline keyword to the static vars and two of the static methods (increaseColor and pointToOffset)</p>
<pre class="brush: plain;">private function enterFrameHandler( event : Event ) : Void {
 var d : Date = Date.now();
 var t : Float = d.getTime();

 updateMatrix( mouseX , mouseY );
 _matrix.transformVectors( particleVector , realVector );

 var pxs : Vector&amp;lt;UInt&amp;gt; = new Vector&amp;lt;UInt&amp;gt;( PIXELS , true );
 var po : Int = 0;
 var a : Int = 0;

 while( a &amp;lt; PARTICLES ) {
   po = pointToOffset( Std.int(realVector[a*3]) , Std.int(realVector[(a*3)+1]) , WIDTH );
   if( 0 &amp;lt; po &amp;amp;&amp;amp; po &amp;lt; PIXELS) {
     pxs[po] = increaseColor( pxs[po] );
   }
   a++;
 }
 // update display
 this.bitmapData.lock();
 this.bitmapData.setVector( this.bitmapData.rect , pxs );
 this.bitmapData.unlock( this.bitmapData.rect );

 d = Date.now();
 textField.text = &quot;single frame time: &quot; + ( d.getTime() - t );
}

private function updateMatrix( mx : Float , my : Float ) : Void {
  tx = tx + ((mx - tx)/10);
  ty = ty + ((my - ty)/10);
  _matrix.identity();
  _matrix.appendRotation( tx , Vector3D.Y_AXIS );
  _matrix.appendRotation( ty , Vector3D.X_AXIS );
  _matrix.appendTranslation( CX, CY, 10 );
}

static inline function increaseColor( c : UInt ) : UInt {
  return c &amp;lt; MAXCOLOR ? c + SHADE : 0xFFFFFF;
}

static inline function pointToOffset( vx : Int , vy : Int , vw : Int ) : UInt {
 return vx + ( vy * vw );
}
</pre>
<p><a href="http://webr3.org/experiments/particle-pusher-take2/optimized/" target="_blank">And here's the inlined haXe result (with full source)</a></p>
<h2>Summary</h2>
<p>In under five minutes and with tiny code changes we've gained well over 100% speed increase; using nothing fancy and the speed rivals all the heavily optimized versions using every trick in the book.</p>
<p>The final result (simply with the event listener changed to Event.ENTER_FRAME and fps added) <a href="http://webr3.org/experiments/particle-pusher-take2/realtime/">is available here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/massive-amount-of-3d-particles-take-two/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>3D Perlin Particle Light Cloud (and source) - haXe / Flash 10</title>
		<link>http://webr3.org/blog/haxe/3d-perlin-particle-light-cloud-and-source-haxe-flash-10/</link>
		<comments>http://webr3.org/blog/haxe/3d-perlin-particle-light-cloud-and-source-haxe-flash-10/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 17:19:47 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Perlin Noise]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[3D computer graphics]]></category>
		<category><![CDATA[Environment]]></category>
		<category><![CDATA[Fractals]]></category>
		<category><![CDATA[Noise]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=47</guid>
		<description><![CDATA[
Been doing some more playing with Perlin Particles, this time going for more natural, and indeed more useful!
Full source and comments included with this one: 3D Perlin Particle Light Cloud
]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-51" title="perlincloud" src="http://webr3.org/blog/wp-content/uploads/2009/06/perlincloud1.jpg" alt="perlincloud" width="600" height="250" /></p>
<p>Been doing some more playing with Perlin Particles, this time going for more natural, and indeed more useful!</p>
<p>Full source and comments included with this one: <a href="http://webr3.org/experiments/perlin-particles/light-cloud/">3D Perlin Particle Light Cloud</a></p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/3d-perlin-particle-light-cloud-and-source-haxe-flash-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3D Perlin Noise Particles in Realtime</title>
		<link>http://webr3.org/blog/haxe/3d-perlin-noise-particles-in-realtime/</link>
		<comments>http://webr3.org/blog/haxe/3d-perlin-noise-particles-in-realtime/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 15:55:06 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Perlin Noise]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[Computer graphics]]></category>
		<category><![CDATA[Fractals]]></category>
		<category><![CDATA[Joa Ebert]]></category>
		<category><![CDATA[Noise]]></category>
		<category><![CDATA[Perlin]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=42</guid>
		<description><![CDATA[
I was flicking through Joa Eberts site the other day and came across a post he did, speed coding 2; the product of which was a load of 2D perlin noise particles that looked.. well great! Kindly Joa gave me permission to dissect, modify and port it to haxe. Ultimately though I ended up recoding [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-43" title="perlincube" src="http://webr3.org/blog/wp-content/uploads/2009/06/perlincube.jpg" alt="perlincube" width="600" height="250" /></p>
<p>I was flicking through Joa Eberts site the other day and came across a post he did, <a href="http://blog.joa-ebert.com/2008/01/20/speedcoding-2/">speed coding 2</a>; the product of which was a load of 2D perlin noise particles that looked.. well great! Kindly Joa gave me permission to dissect, modify and port it to haxe. Ultimately though I ended up recoding it all from scratch, I did however borrow the nice color transform code from the original though, they're damn nice.</p>
<p>Typically you'd call BitmapData.perlinNoise() to generate a 2 color, 2 octave fractal perlin noise image - you then take the 0-255 color values for both of the channels, scale them and use them as your x &amp; y coordinates.</p>
<p>I decided to twist it a bit and try 3D, so in the experiments I'm generating a 3 color, 4 octave fractal perlin noise image then using the   scaling the values to provide x,y,z coordinates. Then mapping each particle into a 3d space, calculating it's color by merging values of particles which land on the same display pixel together.</p>
<p>Enough of the going on anyways, I'll post the full code for the examples once I've cleaned and commented it - all done in haXe of course.</p>
<p>First off, we have a 3D version of <a href="http://blog.joa-ebert.com/2008/01/20/speedcoding-2/">Joa's original</a>; in this one the particles are all mapped into an imaginary cube and some nice effects added : <a href="http://webr3.org/experiments/perlin-particles/cube-tracing-light-particles/">3D perlin noise particles tracing a cube.</a></p>
<p>Next up I thought I'd try some variations:</p>
<ul>
<li><a href="http://webr3.org/experiments/perlin-particles/lazer-tracing-cube/">Lazer tracing a cube</a> (runs v fast)</li>
<li><a href="http://webr3.org/experiments/perlin-particles/noise-in-a-box/">Perlin Noise, In a Box!</a></li>
</ul>
<p>Quite impressed with the base performance here from haxe, I get 100fps on the lazer tracing example, and circa 45-50 fps on the versions with effects or more complex algo's.</p>
<p>liking perlin noise (and haXe).</p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/3d-perlin-noise-particles-in-realtime/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>More Mashed Up Spheres</title>
		<link>http://webr3.org/blog/haxe/more-mashed-up-spheres/</link>
		<comments>http://webr3.org/blog/haxe/more-mashed-up-spheres/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 15:28:57 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[3D computer graphics]]></category>
		<category><![CDATA[Adobe Flash]]></category>
		<category><![CDATA[Particles]]></category>
		<category><![CDATA[Sphere]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=38</guid>
		<description><![CDATA[
Doesn't need much of an introduction, after my previous post "Amazing what happens when you modify a Sphere"; I realised that I'd missed a few combinations, and as such thought it'd be a good idea to finish off the obvious combinations.. you know, to see what they looked like.
One of the best, and the one [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-39" title="morespheres" src="http://webr3.org/blog/wp-content/uploads/2009/06/morespheres.jpg" alt="morespheres" width="600" height="250" /></p>
<p>Doesn't need much of an introduction, after my previous post "Amazing what happens when you modify a Sphere"; I realised that I'd missed a few combinations, and as such thought it'd be a good idea to finish off the obvious combinations.. you know, to see what they looked like.</p>
<p>One of the best, and the one that makes the most sense formula wise is M16.. here's the formula for it</p>
<pre>x = Math.cos(a) * Math.cos(r);
y = Math.cos(a) * Math.sin(r);
z = Math.sin(a) * Math.sin(r);</pre>
<p>makes sense to me! anyway, on with the show - here are the rest:</p>
<ul>
<li><a href="/experiments/basic-3d-particles/mashed-up-8/">M8</a></li>
<li><a href="/experiments/basic-3d-particles/mashed-up-9/">M9</a></li>
<li><a href="/experiments/basic-3d-particles/mashed-up-10/">M10</a></li>
<li><a href="/experiments/basic-3d-particles/mashed-up-11/">M11</a></li>
<li><a href="/experiments/basic-3d-particles/mashed-up-12/">M12</a></li>
<li><a href="/experiments/basic-3d-particles/mashed-up-13/">M13</a></li>
<li><a href="/experiments/basic-3d-particles/mashed-up-14/">M14</a></li>
<li><a href="/experiments/basic-3d-particles/mashed-up-15/">M15</a></li>
<li><a href="/experiments/basic-3d-particles/mashed-up-16/">M16</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/more-mashed-up-spheres/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amazing what happens when you modify a Sphere..</title>
		<link>http://webr3.org/blog/haxe/amazing-what-happens-when-you-modify-a-sphere/</link>
		<comments>http://webr3.org/blog/haxe/amazing-what-happens-when-you-modify-a-sphere/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 16:59:35 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[3D computer graphics]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=35</guid>
		<description><![CDATA[
Taking the 3d particle primatives a bit further (and adding color) I've found that some very nice and rather interesting models can be made when you simply change a sphere a little bit.
Normally I'd do these in order, but in this case I'd recommend you checkout M4 first to get a taste (it's certainly my [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-36" title="eyecandyspheres" src="http://webr3.org/blog/wp-content/uploads/2009/06/eyecandyspheres.jpg" alt="eyecandyspheres" width="600" height="250" /></p>
<p>Taking the 3d particle primatives a bit further (and adding color) I've found that some very nice and rather interesting models can be made when you simply change a sphere a little bit.</p>
<p>Normally I'd do these in order, but in this case I'd recommend you checkout <a href="http://webr3.org/experiments/basic-3d-particles/mashed-up-4/">M4</a> first to get a taste (it's certainly my fav).</p>
<p>Before the list, a very brief description; here we have the code to generate a sphere:</p>
<p><code><br />
for( i in 0...PARTICLES ) {<br />
a = (PARTICLES/360)*i;<br />
r = (i/PARTICLES) * Math.PI;<br />
x = Math.cos(a) * Math.cos(r);<br />
y = Math.cos(a) * Math.sin(r);<br />
z = Math.sin(a);<br />
}<br />
</code></p>
<p>now all we are going to be doing is adding in some steps, or changing the odd cos/sin with cos/sin/tan - nothing complex.</p>
<ul>
<li><a href="http://webr3.org/experiments/basic-3d-particles/mashed-up-1/">M1 Variation</a></li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/mashed-up-2/">M2 Variation</a></li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/mashed-up-3/">M3 Variation</a></li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/mashed-up-4/">M4 Variation</a> (my fav)</li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/mashed-up-5/">M5 Variation</a></li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/mashed-up-6/">M6 Variation</a></li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/mashed-up-7/">M7 Variation<br />
</a></li>
</ul>
<p>Now.. M7 is a rather interesting one.. because it has two very interesting variations (imho) primarily the eye which produces a flat, yet 3d shaded circle..?</p>
<ul>
<li><a href="http://webr3.org/experiments/basic-3d-particles/m7-strange-variation-the-eye/">M7 Strange Variation - The Eye</a></li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/m7-strange-variation-the-feather/">M7 Strange Variation - The Feather</a></li>
</ul>
<p>In addition there are a few more which are created by simply stepping colors or values:</p>
<ul>
<li><a href="http://webr3.org/experiments/basic-3d-particles/3d-abstract-rainbow/">3D Abstract Rainbow</a></li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/one-three-twentyfour/">One, Three, TwentyFour</a></li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/three-six-twelve/">Three, Six, Twelve</a></li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/six-six-twelve/">Six, Six, Twelve</a></li>
</ul>
<p>again, thanks to <a href="http://haxe.org/">haXe</a> for allowing this - remember it's all just particles rendered in realtime.</p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/amazing-what-happens-when-you-modify-a-sphere/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Particle Cubes and Spheres</title>
		<link>http://webr3.org/blog/haxe/particle-cubes-and-spheres/</link>
		<comments>http://webr3.org/blog/haxe/particle-cubes-and-spheres/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 16:11:44 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[3D computer graphics]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Particles]]></category>
		<category><![CDATA[Rendering]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=30</guid>
		<description><![CDATA[
Following earlier unpublished work, and my version of 300k particles in flash, I found that I've created a nice little setup for rendering the results of mathematical functions in flash; specifically rendering the results as 300k/500k particles - I'm kind of fascinated with particles and plotting functions, as are many others - my preference is [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-31" title="primatives" src="http://webr3.org/blog/wp-content/uploads/2009/06/primatives.jpg" alt="primatives" width="600" height="250" /></p>
<p>Following earlier unpublished work, and <a href="http://webr3.org/blog/haxe/flash-10-massive-amounts-of-3d-particles-with-haxe/">my version of 300k particles</a> in flash, I found that I've created a nice little setup for rendering the results of mathematical functions in flash; specifically rendering the results as 300k/500k particles - I'm kind of fascinated with particles and plotting functions, as are many others - my preference is to work with strange attractors; however I thought I'd shoot right back to basics and see what can be made with primatives and modifications of.</p>
<p><strong>pre-warning, if you're looking for eye candy, forget it </strong>- these are simple practical examples and a bit boring, but useful if you need to know how</p>
<p>Starting with the simplest we have the <strong><a href="http://webr3.org/experiments/basic-3d-particles/random-particle-cube/">Particle Cube</a></strong> - 500k random particles plotted in 3d space within an invisible cube. Then I modified it a bit..</p>
<ul>
<li><a href="http://webr3.org/experiments/basic-3d-particles/sine-modified-x-particle-cube/">Sine Modified Particle Cube</a> (it's all skewed)</li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/particle-cube-sine-variation/">Sine and Time Modified Particle Cube</a> (double cube with a flow of particles between)</li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/particle-cube-sin-cos-tan/">Sine, Tan and Cos Modified Particle Cube</a> (one function applied to each axis)</li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/particle-cube-sin-cos-tan-v1/">Alternative Flattened Sine, Tan, Cos Modified Particle Cube</a> (patchwork circular flattened cube!)</li>
</ul>
<p>Next up the <strong><a href="http://webr3.org/experiments/basic-3d-particles/3d-particle-sphere/">Particle Sphere</a></strong> - another 500k particles in 3d space, all random, and then some modified versions..</p>
<ul>
<li><a href="http://webr3.org/experiments/basic-3d-particles/3d-particle-spherical-circles/">Spherical Circles</a> (evenly distributed particles, creates a single line wrapped around a sphere)</li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/3d-emphasized-particle-sphere/">Emphasized Particle Sphere</a> (double spaced to create a messy particle sphere - but more like particles)</li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/3d-particle-half-sphere/">Half a Sphere</a> (go on, guess)</li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/3d-white-bubble/">White Particle Bubble</a> (evenly distributed to create a kind of bubble effect)</li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/the-binlid-3d-particles/">Split Sections of a Sphere</a> (two opposing but differing chunks of sphere, again all particles, like a swing bin lid)</li>
</ul>
<p>And finally a couple of simple experiments..</p>
<ul>
<li><a href="http://webr3.org/experiments/basic-3d-particles/atan2-warped-random-plane/">Random Warped Particle Plane</a> (random x, random y, atan2(x,y) for z)</li>
<li><a href="http://webr3.org/experiments/basic-3d-particles/3d-beach-bubble/">Beach Bubble</a> (the white bubble with some colour, like a beach ball but translucent)</li>
</ul>
<p>In summary, it's good to see how easily different effects and primatives can be build, and even better to see how easily they can be modified with basic mathematical functions. (and how good <a href="http://haxe.org/">haXe</a> is :p)</p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/particle-cubes-and-spheres/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Experiments Upgraded</title>
		<link>http://webr3.org/blog/general/experiments-upgraded/</link>
		<comments>http://webr3.org/blog/general/experiments-upgraded/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 13:58:05 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[experiments]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[Extensible Stylesheet Language]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Markup languages]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL Transformations]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=20</guid>
		<description><![CDATA[
It's a bit premature, seeing as I haven't even blogged about what the existing experiments are yet, however I'm glad to say that the section is finished and ready for veiwing.
Seeing as most of the audience of this blog will be using more recent browsers, I've opted for XSLT templates and small XML descriptors for [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-22" title="xslt-labs" src="http://webr3.org/blog/wp-content/uploads/2009/06/xslt-labs.jpg" alt="xslt-labs" width="600" height="250" /><br />
It's a bit premature, seeing as I haven't even blogged about what the existing experiments are yet, however I'm glad to say that the section is finished and ready for veiwing.</p>
<p>Seeing as most of the audience of this blog will be using more recent browsers, I've opted for XSLT templates and small XML descriptors for each item - this saves me writing tonnes of html, saves the server some weight, saves you some bandwidth and let's me palm off all rendering on to the client.</p>
<p>Inkeeping with the spirit of experiments, one of the main reasons I've done this is to see how the xml documents get listed in google (if at all); and to check if analytics works with XSLT.</p>
<p>On this note, I had to do a little bit of fiddling with the recommended embed code from google to get it to work; if anybody else hits this problem here's a modified version.</p>
<p><code><br />
&lt;script src="http://www.google-analytics.com/ga.js" type="text/javascript"&gt;&lt;/script&gt;<br />
&lt;script type="text/javascript"&gt;<br />
try {<br />
var pageTracker = _gat._getTracker("UA-3391780-6");<br />
pageTracker._trackPageview();<br />
} catch(err) {}<br />
&lt;/script&gt;<br />
</code></p>
<p>And as for the listings, well thats just a quick and dirty PHP 5 class which iterates the directories, loads them in to a dom document and spits out the xml - ultra simples.</p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/general/experiments-upgraded/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
