<?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>Oaxoa Blog</title>
	<atom:link href="http://blog.oaxoa.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.oaxoa.com</link>
	<description>weblog about actionscript 3 experiments, flex, php and web development stuff</description>
	<lastBuildDate>Fri, 14 Sep 2012 08:11:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>3D Christmas tree (aka the &#8220;Merry Christmas&#8221; post)</title>
		<link>http://blog.oaxoa.com/2009/12/24/3d-christmas-tree-aka-the-merry-christmas-post/</link>
		<comments>http://blog.oaxoa.com/2009/12/24/3d-christmas-tree-aka-the-merry-christmas-post/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 09:07:22 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Particles]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=211</guid>
		<description><![CDATA[Hi there, lot of time without posting some code. I have been working three months on a Disney project, which will be on-line soon and makes me very proud, but almost drained all of my energies. Here is my Christmas card/gift for my readers, in less than 80 lines of code. Obviously with source code. [...]]]></description>
			<content:encoded><![CDATA[<p>Hi there,</p>
<p>lot of time without posting some code. I have been working three months on a Disney project, which will be on-line soon and makes me very proud, but almost drained all of my energies.</p>
<p>Here is my Christmas card/gift for my readers, in less than 80 lines of code. Obviously with source code. The lights are vector graphics in the attached FLA&#8217;s library to make it easy to customize or animate.</p>
<p>Nothing too fancy here about the code, just some trigonometric math. You can have a look at the correctOrientations function which can be interesting to avoid lights deformations due to the FP10 native 3D.<br />
<a href='http://blog.oaxoa.com/wp-content/classes/oaxoa_Xmas2009.zip'>Download source code</a>.</p>
<p><strong>I wish you all great winter holidays, and an awesome beginning of 2010!</strong><br />
And make me smile by leaving a greetings comment <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Watch the running example:<br />
<a href="http://blog.oaxoa.com/wp-content/examples/showExample.php?f=Xmas2009.swf&#038;w=400&#038;h=600">Click to start (mouseX affects rotation)<br /><img src="http://blog.oaxoa.com/wp-content/xmas2009.gif" alt="xmas2009" title="xmas2009" width="400" height="600" class="alignnone size-full wp-image-212" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/12/24/3d-christmas-tree-aka-the-merry-christmas-post/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Google Translate database is&#8230; Windows Font Viewer</title>
		<link>http://blog.oaxoa.com/2009/11/17/google-translate-database-is-windows-font-viewer/</link>
		<comments>http://blog.oaxoa.com/2009/11/17/google-translate-database-is-windows-font-viewer/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 01:10:29 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[bugs]]></category>
		<category><![CDATA[fun]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=198</guid>
		<description><![CDATA[Google Translate goes realtime&#8230; -_- Just a quick (non-technical) post, but I cannot resist&#8230; Ok, Google translate introduces a realtime translation feature as highlighted as every new Google feature by billions of blogs (I saw it here: http://mashable.com/2009/11/16/google-translate-update/), but where is the GTranslate database taken from? Does Anyone know? I do&#8230; The Google Translate source [...]]]></description>
			<content:encoded><![CDATA[<p>Google Translate goes realtime&#8230; -_-</p>
<p>Just a quick (non-technical) post, but I cannot resist&#8230; Ok, Google translate introduces a realtime translation feature as highlighted as every new Google feature by billions of blogs (I saw it here: <a href='http://mashable.com/2009/11/16/google-translate-update/'>http://mashable.com/2009/11/16/google-translate-update/</a>), but where is the GTranslate database taken from? </p>
<p>Does Anyone know? I do&#8230;<br />
The Google Translate source database is&#8230; Windows Font Viewer!</p>
<p>Any other way to explain how is it possible that writing:<br />
&#8220;a quick brown fox&#8221; </p>
<p>is translated in </p>
<p>&#8220;<em>uno Cantami o Diva</em>&#8221; (literally: &#8220;one Sing, O goddess&#8221;)</p>
<p>(<a href='http://translate.google.com/#en|it|a%20quick%20brown%20fox'>Try it yourself</a>)</p>
<p>For those not into Greek epic poems translated in Italian, this is the beginning of the <a href='http://en.wikipedia.org/wiki/Iliad'>Homer&#8217;s Iliad</a> which in my language reads:</p>
<blockquote><p>
<em>Cantami, o Diva, del Pelìde Achille<br />
l&#8217;ira funesta che infiniti addusse<br />
lutti agli Achei, molte anzi tempo all&#8217;Orco<br />
generose travolse alme d&#8217;eroi,<br />
e di cani e d&#8217;augelli orrido pasto<br />
lor salme abbandonò (così di Giove<br />
l&#8217;alto consiglio s&#8217;adempìa), da quando<br />
primamente disgiunse aspra contesa<br />
il re de&#8217; prodi Atride e il divo Achille.<br />
E qual de&#8217; numi inimicolli?</em>
</p></blockquote>
<p>So how is it possible that a brown fox becomes a singing Goddess? I couldn&#8217;t remember but then I realized that the beginning of that poem is used by the Italian version of Windows in the font viewer to preview fonts!</p>
<p><img src="http://blog.oaxoa.com/wp-content/fontviewer.gif" alt="" title="" width="500" height="216" /></p>
<p>So &#8220;A quick brown fox jumped over a lazy dog&#8221; (which is used in the English version since it contains every letter of the alphabet &#8211;a <a href='http://en.wikipedia.org/wiki/Pangram'>pangram</a>) according to GTranslate in Italian should be translated with the beginning of a classical piece of literature&#8230; just because it&#8217;s another common pangram (almost)).</p>
<p>Obviously the magic doesn&#8217;t end here: just change &#8220;a quick brown fox&#8221; in &#8220;A quick brown fox&#8221; (with capital A) and the result is &#8220;Una volpe veloce&#8221; (correct)&#8230;</p>
<p>or remove the article: &#8220;quick brown fox&#8221; and the result is &#8220;quick brown fox&#8221; (not translated at all)! </p>
<p>I can understand translating from english to japanese (which are structurally completely different languages) back and forth can produce funny idiosyncrasies as seen on <a href='http://translationparty.com/'>Translation Party</a> but Italian is more similar and &#8220;quick&#8221;, &#8220;brown&#8221; and &#8220;fox&#8221; are common words learned at the first grade during the English lessons.</p>
<p>So I never wrote a dictionary db or algorithm and I am not so sure I could do better, but Google surely can, and <abbr title='a decent translation system'>first things</abbr> should come first.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/11/17/google-translate-database-is-windows-font-viewer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>NihongoUp by divita &#8211; Learn japanese the fun way</title>
		<link>http://blog.oaxoa.com/2009/10/18/nihongoup-by-divita-learn-japanese-the-fun-way/</link>
		<comments>http://blog.oaxoa.com/2009/10/18/nihongoup-by-divita-learn-japanese-the-fun-way/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 14:05:24 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[fun]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[japanese]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=186</guid>
		<description><![CDATA[This is the first time I publish a review, but since I am learning japanese and this game is so much fun and so much useful I think it deserves visibility. NihongoUp is a japanese learning game developed in Adobe AIR by Philip Seyfi. It is structured in four main categories: Kana (Hiragana, Katakana, All [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first time I publish a review, but since I am learning japanese and this game is so much fun and so much useful I think it deserves visibility.</p>
<p><a href='http://nihongoup.com/'>NihongoUp</a> is a japanese learning game developed in Adobe AIR by <a href='http://www.divita.eu'>Philip Seyfi</a>.<br />
It is structured in four main categories:</p>
<ul>
<li>Kana (Hiragana, Katakana, All kana)</li>
<li>Kanji (JLPT  3, JLPT 2)</li>
<li>Vocabulary (JLPT 4, JLPT 3, JLPT 2, JLPT 1)</li>
<li>Grammar (particles, counters)</li>
</ul>
<p><img src="http://blog.oaxoa.com/wp-content/nihongoup1.jpg" width="500" height="375" alt="nihongoup" /></p>
<p>There are mainly two kinds of games, a typing one, used in the &#8220;Kana&#8221; section where lots of balloon comes down the screen with a japanese symbol attached. You have to type the translitterated kana before the balloon disappears to gain score points and raise the level number. It&#8217;s simply funny and perfect for someone at the beginning of the studying process.</p>
<p><img src="http://blog.oaxoa.com/wp-content/nihongoup3.jpg" width="500" height="370" alt="nihongoup" /></p>
<p>The other kind of game reuses the concept of the falling balloons but you simply have to choose between four possible answers to the question located at the bottom of the screen. This game concept is used in the other sections, where you can train your Kanji knowledge, grammar skills or the richness of your japanese vocabulary.</p>
<p><img src="http://blog.oaxoa.com/wp-content/nihongoup2.jpg" width="500" height="376" alt="nihongoup" /></p>
<p>What else to say? It is well coded and the database is huge with <del datetime="2009-10-20T06:52:47+00:00">8000</del> <ins datetime="2009-10-20T06:52:47+00:00">10000</ins> (!) records filled all the <a href='http://en.wikipedia.org/wiki/JLPT'>JLPT</a> Kanjis and training sentences, so this game could really help the willing student to become a japanese language master, with fun.</p>
<p>So if you are studying japanese and you are a flash developer (likely as you are reading this&#8230;), support this valuable work. A license serial number costs only $4.99 and before buying you can trying a free trial to test it out.</p>
<p><a href='http://nihongoup.com/'>http://nihongoup.com/</a></p>
<p>I&#8217;ll soon be back posting lots of new actionscript stuff. Have a nice sushi day <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/10/18/nihongoup-by-divita-learn-japanese-the-fun-way/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 &#8211; as3 &#124; Rorschach mask (realtime animated inkblots)</title>
		<link>http://blog.oaxoa.com/2009/09/11/actionscript-3-as3-rorschach-mask-realtime-animated-inkblots/</link>
		<comments>http://blog.oaxoa.com/2009/09/11/actionscript-3-as3-rorschach-mask-realtime-animated-inkblots/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 07:19:13 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[fluids]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[morphing]]></category>
		<category><![CDATA[perlinNoise]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[threshold]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=165</guid>
		<description><![CDATA[Everybody knows about Rorschach inkblot tests, and they always charmed me&#8230; It&#8217;s like looking clouds and recognizing different shapes. However I must admit the real turn on came after watching Watchmen the movie. Seeing those animated inkblots on the face of the character symbolically named Rorschach is something really fascinating. So here we are, after [...]]]></description>
			<content:encoded><![CDATA[<p>Everybody knows about Rorschach inkblot tests, and they always charmed me&#8230; It&#8217;s like looking clouds and recognizing different shapes.</p>
<p>However I must admit the real turn on came after watching <a href='http://www.imdb.com/title/tt0409459/'>Watchmen</a> the movie. Seeing those animated inkblots on the face of the character symbolically named Rorschach is something really fascinating. So here we are, after about an hour of coding fun this is what I came up with.</p>
<p><a href="http://blog.oaxoa.com/wp-content/examples/showExample.php?f=rorschach_test1.swf&#038;w=400&#038;h=400"><img src="http://blog.oaxoa.com/wp-content/rorschach1.gif" width="300" height="300" alt="" /><br />Click to start</a></p>
<p>Here after adding a cool persistence of the ink (call it motion blur if you like), and the face oval:</p>
<p><a href="http://blog.oaxoa.com/wp-content/examples/showExample.php?f=rorschach_test2.swf&#038;w=300&#038;h=400"><img src="http://blog.oaxoa.com/wp-content/rorschach_test2.jpg" width="300" height="400" alt="" /><br />Click to start</a></p>
<p>How it&#8217;s made is quite simple:</p>
<p>- perlinNoise a bitmapData<br />
- draw a circular gradient mask (I used a beginGradientFill on a Shape/Sprite)<br />
- BitmapData.draw() the mask onto the perlinNoise bitmapData<br />
- threshold<br />
- (optional) a little blur to simulate antialias</p>
<p>Since a picture is worth a thousand words:</p>
<p><a href="http://blog.oaxoa.com/wp-content/examples/showExample.php?f=rorschach_steps.swf&#038;w=600&#038;h=340"><img src="http://blog.oaxoa.com/wp-content/rorschach_steps.jpg" width="500" height="283" alt="" /><br />Click to see it moving</a></p>
<p>I&#8217;ve built a class to do this easily. Six parameters are optional to instance it:</p>
<pre lang='actionscript'>
public function Rorschach(w:uint=400, h:uint=400, mirror:Boolean=true, seed:uint=0, ovalClass:Class=null, ovalScale:Number=1, ovalYOffset:Number=0)
</pre>
<p>ovalClass is the (optional) reference to the class containing the face background.</p>
<p>So the usage is very simple, here an example:</p>
<pre lang='actionscript'>
import com.oaxoa.fx.Rorschach;
addChild(new Rorschach(300,300));
//addChild(new Rorschach(300,300,true,0,blankMaskImage, 1.2, -20));
</pre>
<p><a href='http://blog.oaxoa.com/wp-content/classes/Rorschach.zip'>Download Rorschach class</a> for your experimentation pleasure.</p>
<p>All nice, but the aim of this simple experiment is seeing Rorschach animated face in action so here we go&#8230; we will be using this class in a practical example.</p>
<p>To simulate 3D volume and perspective we need flash CS4 (or any 3D engine):<br />
we create a MovieClip which has the Rorschach class instanced and a rectangular solid background for composition reference in it. Then we set layer visibility to wireframe and add another instance to the stage, which is flipped horizontally.<br />
Just position the two instances using 3D rotations and we are ready.</p>
<p><img src="http://blog.oaxoa.com/wp-content/rorschach2_wf.jpg" width="350" height="297" alt="" /></p>
<p>Just build et voilà!</p>
<p><a href="http://blog.oaxoa.com/wp-content/examples/showExample.php?f=rorschach2.swf&#038;w=731&#038;h=548"><img src="http://blog.oaxoa.com/wp-content/rorschach2.jpg" width="500" height="375" alt="" /><br />Click to start</a></p>
<blockquote><p>Rorschach&#8217;s Journal. October 12th, 1985. Dog Carcass in alley this morning, tire tread on burst stomach. This city is afraid of me. I have seen its true face. The streets are extended gutters and the gutters are full of blood and when the drains finally scab over, all the vermin will drown. The accumulated filth of all their sex and murder will foam up about their waists and all the whores and politicians will look up and shout &#8216;Save us!&#8217; And I&#8217;ll look down, and whisper &#8216;no.&#8217;</p></blockquote>
<p>The last (and D-E-F-I-N-I-T-I-V-E! <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  ) usage for this is apply it to a realtime webcam face detection algorithm. I used this originally created by <a href='http://maaash.jp/as3/as3marilena-object-detection-in-as3/'>Ohtsuka Masakazu</a> and optimized by <a href='http://www.quasimondo.com/archives/000687.php'>Mario Klingemann</a>. The result is totally weird (don&#8217;t expect photoreal hollywood effect LOL) but it&#8217;s funny, even if the face detection algorithm is not perfectly smooth.</p>
<p>Have fun being the definitive comics anti-hero:</p>
<p><a href="http://blog.oaxoa.com/wp-content/examples/showExample.php?f=FaceDetector_Camera.swf&#038;w=320&#038;h=240"><img src="http://blog.oaxoa.com/wp-content/rorschach_facedetection.jpg" width="320" height="239" alt="" /><br />Click to start</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/09/11/actionscript-3-as3-rorschach-mask-realtime-animated-inkblots/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 &#8211; as3 Lightning / Thunderbolt / Electric discharge Class</title>
		<link>http://blog.oaxoa.com/2009/07/27/actionscript-3-as3-lightning-thunderbolt-electric-discharge-class/</link>
		<comments>http://blog.oaxoa.com/2009/07/27/actionscript-3-as3-lightning-thunderbolt-electric-discharge-class/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 21:34:28 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[morphing]]></category>
		<category><![CDATA[perlinNoise]]></category>
		<category><![CDATA[simulation]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=131</guid>
		<description><![CDATA[Finally here we come! Yup, sry for the delay, I&#8217;ve had a lot of work recently. I have prepared three demos and a publishable (but far from perfect and not yet documented) class. The demos are FLA based&#8230; you can find the timeline code to assemble the demos at the bottom of the post. I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>Finally here we come!</p>
<p>Yup, sry for the delay, I&#8217;ve had a lot of work recently.</p>
<p>I have prepared three demos and a publishable (but far from perfect and not yet documented) class. The demos are FLA based&#8230; you can find the timeline code to assemble the demos at the bottom of the post. I&#8217;ll publish some documentation in the next days, so until then just look at the demos&#8217; code to unserstand the basic of the class usage.</p>
<p>Download <a href="http://blog.oaxoa.com/wp-content/classes/Lightning.zip">Lightning classes</a></p>
<p><strong>Demo N°1:</strong><br />
This demo shows the two different behaviours the class can mimic: Electric discharge/beam or lightning. Drag the ball near or far to the coil to see different behaviors.</p>
<p><a href="http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test_coil.swf&#038;w=727&#038;h=566"><img src="http://blog.oaxoa.com/wp-content/lightning_test_coil.jpg" width="500" height="352" alt="" /><br />Click to start</a></p>
<p><strong>Demo N°2:</strong><br />
This demos show the maxLength and maxLengthVary properties in action.<br />
Bring the fingers near to the plug to have continuos electricity. Bringing the hand far from the plug lowers the discharge probability. Reaching the max distance simply disables it.</p>
<p><a href="http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test_plug.swf&#038;w=413&#038;h=564"><img src="http://blog.oaxoa.com/wp-content/lightning_test_plug.jpg" width="300" height="418" alt="" /><br />Click to start</a></p>
<p><strong>Demo N°3:</strong><br />
This demo is a good reason for the publishing delay <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>A nice sandbox to play with (some of) the properties.<br />
The class is recursive to create children so many properties have also a decay twin property which rule how the property is passed to children.<br />
As instance if you set a childrenMaxCount = 6 to the main Lightning instance it will have a maximum of 6 direct children. Its children will have a childrenMaxCount value which depends on the main instance childrenMaxCount and childrenMaxCountDecay.<br />
So if you set childrenMaxCount = 6 and childrenMaxCountDecay = .5 the children of the main instance will have childrenMaxCount = 3.<br />
If you set childrenMaxCount = 6 and childrenMaxCountDecay = 0 the children of the main instance will have childrenMaxCount = 6 (no decay).</p>
<p>This value can be very useful to optimize the speed of execution cause smaller branches don&#8217;t need many children or many steps of detail.</p>
<p><a href="http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test5.swf&#038;w=730&#038;h=680"><img src="http://blog.oaxoa.com/wp-content/lightning_test5.jpg" width="500" height="465" alt="" /><br />Click to start</a></p>
<p>Ok, I&#8217;m too tired to write more. I&#8217;ll publish some documentation in the next days.<br />
Feel free to ask everything question you can have in the comments, and as usual if you like this stuff scream it in the comments!</p>
<p>Demos&#8217; code after the break. Waiting for your comments I will surf through the website of <a href="http://www.webhostingsearch.com/review/fatcow.php" title="fatcow">fatcow</a> and see if they have any good hosting plans.<br />
<span id="more-131"></span><br />
Demos code is just timeline code to instance and pilot the lightning class&#8230; and very untidy! Please don&#8217;t blame it <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>Demo N°1:</strong></p>
<pre lang='actionscript'>
import com.oaxoa.fx.Lightning;
import com.oaxoa.fx.LightningFadeType;

const cx:uint=360;
const cy:uint=320;

var color:uint=0xffffff;
var ll:Lightning=new Lightning(color, 2);
ll.blendMode=BlendMode.ADD;
ll.childrenDetachedEnd=true;
ll.childrenLifeSpanMin=.1;
ll.childrenLifeSpanMax=2;
ll.childrenMaxCount=4;
ll.childrenMaxCountDecay=.5;
ll.steps=150;
ll.alphaFadeType=LightningFadeType.TIP_TO_END;

ball.useHandCursor=ball.buttonMode=true;
dot1.mouseEnabled=dot2.mouseEnabled=false;
dot1.alpha=.75;

var glow:GlowFilter=new GlowFilter();
glow.color=color;
glow.strength=3.5;
glow.quality=3;
glow.blurX=glow.blurY=10;
ll.filters=dot1.filters=dot2.filters=[glow];
addChild(ll);

ll.childrenProbability=.3;

var p:Point=new Point();
randomizePoint();
function randomizePoint():void {
	var angle:Number=-Math.random()*Math.PI;
	var dist:Number=160+Math.random()*180;
	p.x=cx+Math.cos(angle)*dist;
	p.y=cy+Math.sin(angle)*dist;
}

addEventListener(Event.ENTER_FRAME, onframe);
function onframe(event:Event):void {
	
	var rnd:Number=Math.random();
	if(rnd<.05) randomizePoint();
	var dx:Number=cx-ball.x;
	var dy:Number=cy-ball.y;
	var d:Number=Math.sqrt(dx*dx+dy*dy);
	if(d<310) {
		dot2.visible=true;
		if(ll.childrenDetachedEnd) {
			ll.childrenDetachedEnd=false;
			ll.alphaFadeType=LightningFadeType.GENERATION;
			ll.killAllChildren();
		}
		
		ll.endX=dot2.x=ball.x;
		ll.endY=dot2.y=ball.y;
	} else {
		dot2.visible=false;
		if(!ll.childrenDetachedEnd) {
			ll.childrenDetachedEnd=true;
			ll.alphaFadeType=LightningFadeType.TIP_TO_END;
			ll.killAllChildren();
		}
		ll.endX=p.x;
		ll.endY=p.y;
	}
	var ddx:Number=cx-ll.endX;
	var ddy:Number=cy-ll.endY;
	var aangle:Number=Math.atan2(ddy, ddx);
	ll.startX=cx-Math.cos(aangle)*80;
	dot1.scaleX=Math.sin(aangle);
	ll.startY=cy;
	dot1.x=ll.startX;
	dot1.y=ll.startY;
	ll.update();
}

ball.addEventListener(MouseEvent.MOUSE_DOWN, onmdown);
function onmdown(event:MouseEvent):void {
	ball.startDrag();
}
ball.addEventListener(MouseEvent.MOUSE_UP, onmup);
function onmup(event:MouseEvent):void {
	ball.stopDrag();
}
</pre>
<p><strong>Demo N°2:</strong></p>
<pre lang='actionscript'>
import com.oaxoa.fx.Lightning;
import com.oaxoa.fx.LightningFadeType;

setChildIndex(fingers, 2);

var iy:Number=fingers.y;
addEventListener(MouseEvent.MOUSE_MOVE, onmove);

fingers.x=fingers.y/2.5-10;

function updatePositions():void {
	ll.endX=fingers.x+fingers.dot1.x;
	ll.endY=fingers.y+fingers.dot1.y;
	ll2.endX=fingers.x+fingers.dot2.x;
	ll2.endY=fingers.y+fingers.dot2.y;
}

function onmove(event:MouseEvent):void {
	fingers.y=mouseY-150;
	if(fingers.y<iy) fingers.y=iy;
	if(fingers.y>320) fingers.y=320;
	fingers.x=fingers.y/2.5-10;
	updatePositions();
	event.updateAfterEvent();
}
addEventListener(Event.ENTER_FRAME, onframe);
function onframe(event:Event):void {
	ll.update();
	ll2.update();
}

var color:uint=0xddeeff;
var ll:Lightning=new Lightning(color, 2);
var ll2:Lightning=new Lightning(color, 2);
ll.blendMode=ll2.blendMode=BlendMode.ADD;
ll.childrenProbability=ll2.childrenProbability=.5;
ll.childrenLifeSpanMin=ll2.childrenLifeSpanMin=.1;
ll.childrenLifeSpanMax=ll2.childrenLifeSpanMax=2;
ll.maxLength=ll2.maxLength=50;
ll.maxLengthVary=ll2.maxLengthVary=200;

ll.startX=dot3.x;
ll.startY=dot3.y;
ll2.startX=dot4.x;
ll2.startY=dot4.y;

var glow:GlowFilter=new GlowFilter();
glow.color=color;
glow.strength=3.5;
glow.quality=3;
glow.blurX=glow.blurY=10;
ll.filters=ll2.filters=[glow];
addChild(ll);
addChild(ll2);

updatePositions();

</pre>
<p><strong>Demo N°3:</strong><br />
(The ugliest bunch of random code lines ever written <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> )</p>
<pre lang='actionscript'>
import com.oaxoa.fx.Lightning;
import com.oaxoa.fx.LightningFadeType;
import com.oaxoa.components.ToolTip;
import fl.controls.Button;
import fl.data.DataProvider;

import fl.events.SliderEvent;
var color:uint=0xffffff;
var ll:Lightning=new Lightning(color, 2);
ll.blendMode=BlendMode.ADD;

var glow:GlowFilter=new GlowFilter();
glow.color=color;
glow.strength=4;
glow.quality=3;
glow.blurX=glow.blurY=10;
ll.filters=[glow];
addChild(ll);
ll.startX=cross1.x;
ll.startY=cross1.y;

ll.endX=cross2.x;
ll.endY=cross2.y;

setChildIndex(ll,0);

ll.childrenMaxGenerations=3;
ll.childrenMaxCountDecay=.5;

addEventListener(Event.ENTER_FRAME, onframe);
function onframe(event:Event):void {
	ll.startX=cross1.x;
	ll.startY=cross1.y;
	
	ll.endX=cross2.x;
	ll.endY=cross2.y;
	ll.update();
	updateCircles();
}

import com.oaxoa.components.FrameRater;
var fr:FrameRater=new FrameRater(0xffffff, true);
addChild(fr);

var ttip:ToolTip=new ToolTip();
addChild(ttip);

var tfmt:TextFormat=new TextFormat("_sans", 11, 0xffffff);

cb0.addItem({label:"Choose a preset", value:0});
cb0.addItem({label:"Fast discharge", value:1});
cb0.addItem({label:"Fast discharge (Max length + max length variation)", value:2});
cb0.addItem({label:"Fast discharge (slow-motion)", value:3});
cb0.addItem({label:"Moving Thunderbolt", value:4});
cb0.addItem({label:"Moving Thunderbolt (Max length + max length variation)", value:5});
cb0.selectedIndex=0;
cb0.addEventListener(Event.CHANGE, oncb);
cb0.textField.setStyle("textFormat", tfmt);
cb0.dropdown.setRendererStyle("textFormat", tfmt);

cb1.addItem({label:"Discharge", value:false});
cb1.addItem({label:"Lightning (detached end)", value:true});
cb1.selectedIndex=1;
cb1.addEventListener(Event.CHANGE, oncb);
cb1.textField.setStyle("textFormat", tfmt);
cb1.dropdown.setRendererStyle("textFormat", tfmt);

cb2.addItem({label:"None", value:LightningFadeType.NONE});
cb2.addItem({label:"Generation", value:LightningFadeType.GENERATION});
cb2.addItem({label:"Tip to end", value:LightningFadeType.TIP_TO_END});
cb2.selectedIndex=2;
cb2.addEventListener(Event.CHANGE, oncb);
cb2.textField.setStyle("textFormat", tfmt);
cb2.dropdown.setRendererStyle("textFormat", tfmt);

cb3.addItem({label:"None", value:LightningFadeType.NONE});
cb3.addItem({label:"Generation", value:LightningFadeType.GENERATION});
cb3.addItem({label:"Tip to end", value:LightningFadeType.TIP_TO_END});
cb3.selectedIndex=2;
cb3.addEventListener(Event.CHANGE, oncb);
cb3.textField.setStyle("textFormat", tfmt);
cb3.dropdown.setRendererStyle("textFormat", tfmt);

function oncb(event:Event):void {
	var t:ComboBox=event.currentTarget as ComboBox;
	switch(t) {
		case cb0:
			setPreset(t.selectedItem.value);
			break;
		case cb1:
			ll.childrenDetachedEnd=t.selectedItem.value;
			ll.killAllChildren();
			break;
		case cb2:
			ll.alphaFadeType=t.selectedItem.value;
			ll.killAllChildren();
			break;
		case cb3:
			ll.thicknessFadeType=t.selectedItem.value;
			ll.killAllChildren();
			break;
	}
}


slider.addEventListener(SliderEvent.CHANGE, onslider);
slider2.addEventListener(SliderEvent.CHANGE, onslider);
slider3.addEventListener(SliderEvent.CHANGE, onslider);
slider4.addEventListener(SliderEvent.CHANGE, onslider);
slider5.addEventListener(SliderEvent.CHANGE, onslider);
slider6.addEventListener(SliderEvent.CHANGE, onslider);
slider7.addEventListener(SliderEvent.CHANGE, onslider);
slider8.addEventListener(SliderEvent.CHANGE, onslider);
slider9.addEventListener(SliderEvent.CHANGE, onslider);
slider10.addEventListener(SliderEvent.CHANGE, onslider);
slider11.addEventListener(SliderEvent.CHANGE, onslider);
slider12.addEventListener(SliderEvent.CHANGE, onslider);
slider13.addEventListener(SliderEvent.CHANGE, onslider);
function onslider(event:SliderEvent):void {
	var t:Slider=event.currentTarget as Slider;
	ttip.show(t.value.toString());
	ttip.y=t.y-30;
	switch(t) {
		case slider:
			ll.smoothPercentage=t.value;
			break;
		case slider2:
			ll.childrenAngleVariation=t.value;
			break;
		case slider3:
			ll.childrenMaxCount=t.value;
			break;
		case slider4:
			ll.wavelength=t.value;
			break;
		case slider5:
			ll.amplitude=t.value;
			break;
		case slider6:
			ll.speed=t.value;
			break;
		case slider7:
			ll.thickness=t.value;
			ll.killAllChildren();
			break;
		case slider8:
			ll.maxLength=t.value;
			break;
		case slider9:
			ll.maxLengthVary=t.value;
			break;
		case slider10:
			ll.childrenProbability=t.value;
			ll.killAllChildren();
			break;
		case slider11:
			ll.childrenLifeSpanMin=t.value;
			ll.killAllChildren();
			if(t.value>slider12.value) slider12.value=t.value;
			break;
		case slider12:
			ll.childrenLifeSpanMax=t.value;
			ll.killAllChildren();
			slider11.visible=t.value!=0;
			break;
		case slider13:
			ll.steps=t.value;
			ll.killAllChildren();
			break;
	}
	ll.render();
}

function setPreset(n:uint):void {
	switch(n) {
		// fast discharge
		case 1:
			ll.childrenLifeSpanMin=1;
			ll.childrenLifeSpanMax=3;
			ll.childrenProbability=1;
			ll.childrenMaxGenerations=3;
			ll.childrenMaxCount=4;
			ll.childrenAngleVariation=110;
			ll.thickness=2;
			ll.steps=100;
			
			ll.smoothPercentage=50;
			ll.wavelength=.3;
			ll.amplitude=.5;
			ll.speed=.7;
			ll.maxLength=0;
			ll.maxLengthVary=0;
			
			ll.childrenDetachedEnd=false;
			cb1.selectedIndex=0;
			ll.alphaFadeType=LightningFadeType.GENERATION;
			cb2.selectedIndex=1;
			ll.thicknessFadeType=LightningFadeType.NONE;
			cb3.selectedIndex=0;
			
			break;
		// fast discharge (with max length+variation)
		case 2:
			ll.childrenLifeSpanMin=1;
			ll.childrenLifeSpanMax=3;
			ll.childrenProbability=1;
			ll.childrenMaxGenerations=3;
			ll.childrenMaxCount=4;
			ll.childrenAngleVariation=110;
			ll.thickness=2;
			ll.steps=100;
			
			ll.smoothPercentage=50;
			ll.wavelength=.3;
			ll.amplitude=.5;
			ll.speed=.7;
			ll.maxLength=440;
			ll.maxLengthVary=75;
			
			ll.childrenDetachedEnd=false;
			cb1.selectedIndex=0;
			ll.alphaFadeType=LightningFadeType.GENERATION;
			cb2.selectedIndex=1;
			ll.thicknessFadeType=LightningFadeType.NONE;
			cb3.selectedIndex=0;
			
			break;
		// fast discharge slowmo
		case 3:
			ll.childrenLifeSpanMin=1;
			ll.childrenLifeSpanMax=3;
			ll.childrenProbability=1;
			ll.childrenMaxGenerations=3;
			ll.childrenMaxCount=4;
			ll.childrenAngleVariation=110;
			ll.thickness=2;
			ll.steps=100;
			
			ll.smoothPercentage=50;
			ll.wavelength=.3;
			ll.amplitude=.5;
			ll.speed=.1;
			ll.maxLength=0;
			ll.maxLengthVary=0;
			
			ll.childrenDetachedEnd=false;
			cb1.selectedIndex=0;
			ll.alphaFadeType=LightningFadeType.GENERATION;
			cb2.selectedIndex=1;
			ll.thicknessFadeType=LightningFadeType.NONE;
			cb3.selectedIndex=0;
			
			break;
		// moving thumnder
		case 4:
			ll.childrenLifeSpanMin=.1;
			ll.childrenLifeSpanMax=2;
			ll.childrenProbability=1;
			ll.childrenMaxGenerations=3;
			ll.childrenMaxCount=4;
			ll.childrenAngleVariation=130;
			ll.thickness=3;
			ll.steps=100;
			
			ll.smoothPercentage=50;
			ll.wavelength=.3;
			ll.amplitude=.5;
			ll.speed=1;
			ll.maxLength=0;
			ll.maxLengthVary=0;
			
			ll.childrenDetachedEnd=true;
			cb1.selectedIndex=1;
			ll.alphaFadeType=LightningFadeType.TIP_TO_END;
			cb2.selectedIndex=2;
			ll.thicknessFadeType=LightningFadeType.GENERATION;
			cb3.selectedIndex=1;
			
			break;
		case 5:
			ll.childrenLifeSpanMin=.1;
			ll.childrenLifeSpanMax=2;
			ll.childrenProbability=1;
			ll.childrenMaxGenerations=3;
			ll.childrenMaxCount=4;
			ll.childrenAngleVariation=130;
			ll.thickness=3;
			ll.steps=100;
			
			ll.smoothPercentage=50;
			ll.wavelength=.3;
			ll.amplitude=.5;
			ll.speed=1;
			ll.maxLength=440;
			ll.maxLengthVary=75;
			
			ll.childrenDetachedEnd=true;
			cb1.selectedIndex=1;
			ll.alphaFadeType=LightningFadeType.TIP_TO_END;
			cb2.selectedIndex=2;
			ll.thicknessFadeType=LightningFadeType.GENERATION;
			cb3.selectedIndex=1;
			
			break;
	}
	ll.killAllChildren();
	updateSliders();
}
function updateSliders():void {
	slider.value=ll.smoothPercentage;
	slider2.value=ll.childrenAngleVariation;
	slider3.value=ll.childrenMaxCount;
	slider4.value=ll.wavelength;
	slider5.value=ll.amplitude;
	slider6.value=ll.speed;
	slider7.value=ll.thickness;
	slider8.value=ll.maxLength;
	slider9.value=ll.maxLengthVary;
	slider10.value=ll.childrenProbability;
	slider11.value=ll.childrenLifeSpanMin;
	slider12.value=ll.childrenLifeSpanMax;
	slider13.value=ll.steps;
}
///////////////////

var tf:TextFormat=new TextFormat();
tf.color=0xffffff;

cross1.addEventListener(MouseEvent.MOUSE_UP, onup);
cross1.addEventListener(MouseEvent.MOUSE_DOWN, ondown);
cross2.addEventListener(MouseEvent.MOUSE_UP, onup);
cross2.addEventListener(MouseEvent.MOUSE_DOWN, ondown);
cross1.buttonMode=cross2.buttonMode=cross1.useHandCursor=cross2.useHandCursor=true;

function ondown(event:MouseEvent):void {
	event.currentTarget.alpha=.2;
	event.currentTarget.startDrag();
}
function onup(event:MouseEvent):void {
	event.currentTarget.alpha=1;
	event.currentTarget.stopDrag();
}
var circles:Shape=new Shape();
addChildAt(circles, 0);

function updateCircles():void {
	circles.graphics.clear();
	if(ll.maxLength>0) {
		circles.graphics.lineStyle(6, 0xffffff, .3);
		circles.graphics.drawCircle(cross1.x, cross1.y, ll.maxLength);
		circles.graphics.lineStyle(2, 0xffffff, .4);
		circles.graphics.drawCircle(cross1.x, cross1.y, ll.maxLength+ll.maxLengthVary);
		var steps:uint=5;
		for(var i:uint=1; i<steps; i++) {
			circles.graphics.lineStyle(1, 0xffffff, .2);
			circles.graphics.beginFill(0xffffff, .025);
			circles.graphics.drawCircle(cross1.x, cross1.y, ll.maxLength+(ll.maxLengthVary/steps)*i);
			circles.graphics.endFill();
		}
	}
}


setPreset(1);


</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/07/27/actionscript-3-as3-lightning-thunderbolt-electric-discharge-class/feed/</wfw:commentRss>
		<slash:comments>87</slash:comments>
		</item>
		<item>
		<title>Back from Prague</title>
		<link>http://blog.oaxoa.com/2009/06/03/back-from-prague/</link>
		<comments>http://blog.oaxoa.com/2009/06/03/back-from-prague/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 13:44:03 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[general]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=121</guid>
		<description><![CDATA[I am back from a week in Prague. My 6th time there (my wife is czech) but the first time just for tourism. Prague is awesome but prepare to walk a lot. A picture to let you enjoy my best side Got to get back to work now. And complete my lightning class.. which is [...]]]></description>
			<content:encoded><![CDATA[<p>I am back from a week in Prague.<br />
My 6th time there (my wife is czech) but the first time just for tourism.<br />
Prague is awesome but prepare to walk a lot.</p>
<p>A picture to let you enjoy my best side <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /><br />
<img src="http://blog.oaxoa.com/wp-content/praha.jpg" alt="praha" title="praha" width="550" height="413" class="alignnone size-full wp-image-122" /></p>
<p>Got to get back to work now. And complete my lightning class.. which is almost done.<br />
Posting soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/06/03/back-from-prague/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 &#124; Speedcoding video &#8211; session #1: Black Branches</title>
		<link>http://blog.oaxoa.com/2009/05/05/actionscript-3-speedcoding-video-session-1-black-branches/</link>
		<comments>http://blog.oaxoa.com/2009/05/05/actionscript-3-speedcoding-video-session-1-black-branches/#comments</comments>
		<pubDate>Tue, 05 May 2009 13:22:39 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[perlinNoise]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=106</guid>
		<description><![CDATA[Yesterday night I wanted to have some &#8220;no-purpose coding session&#8221; and thought it was a nice idea to record the session and do a speedcoding video. The original video has been collapsed from 45 minutes to 3 minutes circa. The main concept is once again based on perlinNoise which (I am sure you already guessed) [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday night I wanted to have some &#8220;no-purpose coding session&#8221; and thought it was a nice idea to record the session and do a speedcoding video. The original video has been collapsed from 45 minutes to 3 minutes circa.</p>
<p>The main concept is once again based on perlinNoise which (I am sure you already guessed) is something I do like very much. So please start call me &#8220;The PerlinNoise Guy&#8221; or &#8220;Perlinator&#8221;. <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  </p>
<p>So this is my first speedcoding video (be sure to look at it in high quality):</p>
<p><object width="500" height="405"><param name="movie" value="http://www.youtube.com/v/MD7fN4I8cB8&#038;hl=it&#038;fs=1&#038;rel=0&#038;border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/MD7fN4I8cB8&#038;hl=it&#038;fs=1&#038;rel=0&#038;border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="405"></embed></object></p>
<p>Here&#8217;s the interactive demo:</p>
<p><a href='http://blog.oaxoa.com/wp-content/examples/showExample.php?f=black_branches.swf&#038;w=800&#038;h=600'><img src='http://blog.oaxoa.com/wp-content/black_branches.jpg' width='550' height='' alt='400' /><br />
Click to launch. Move mouse (x position) to change smoothness (my favourite values are around 100)</a></p>
<p>The code consist on a <a href='http://blog.oaxoa.com/wp-content/classes/Branch_class.zip'>Branch.as class file (click to download)</a> and some timeline code to assemble the demo:</p>
<pre lang='actionscript'>
import com.oaxoa.fx.Branch;

const w:uint=stage.stageWidth;
const h:uint=stage.stageHeight;

var ct:ColorTransform=new ColorTransform(1,1,1,1,1,1,1);
var renderView:BitmapData=new BitmapData(w, h, true);
var bmp:Bitmap=new Bitmap(renderView);
addChild(bmp);

var tf:TextFormat=new TextFormat("_sans", 16, 0, true);
var label:TextField=new TextField();
label.width=400;
label.defaultTextFormat=tf;
addChild(label);

var timer:Timer=new Timer(10);
timer.addEventListener(TimerEvent.TIMER, ontimer);
timer.start();

function ontimer(event:TimerEvent):void {
	addNew();
}
function addNew():void {
	label.text="Smoothness: "+String(mouseX-w/2);
	var tt:Branch=new Branch(mouseX-w/2);
	tt.x=stage.stageWidth/2;
	tt.y=stage.stageHeight/2;
	tt.addEventListener(Event.COMPLETE, oncomplete);
	addChild(tt);
	renderView.colorTransform(renderView.rect, ct);
}
function oncomplete(event:Event):void {
	var t:Branch=event.currentTarget as Branch;
	var matrix:Matrix=new Matrix();
	matrix.translate(t.x, t.y);
	renderView.draw(t, matrix);
	removeChild(t);
	t.removeEventListener(Event.COMPLETE, oncomplete);
	t=null;
}

</pre>
<p>I didn&#8217;t forget about the lightning class part 3 that I will publish soon <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>As usual if you liked this drop a line in the comments.<br />
Ciao</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/05/05/actionscript-3-speedcoding-video-session-1-black-branches/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 Lightning class &#8211; step 2</title>
		<link>http://blog.oaxoa.com/2009/04/26/actionscript-3-lightning-class-step-2/</link>
		<comments>http://blog.oaxoa.com/2009/04/26/actionscript-3-lightning-class-step-2/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 22:57:47 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[fluids]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[perlinNoise]]></category>
		<category><![CDATA[simulation]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=78</guid>
		<description><![CDATA[The first rule for the good blogger I read 18 months ago (when I started this blog) was: &#8220;Never, ever post on Sunday&#8230; people coming back to the office on monday morning will find tons of weekend rss notifications and miss your post among them&#8221;. But&#8230; since I am not a good blogger and since [...]]]></description>
			<content:encoded><![CDATA[<p>The first rule for the good blogger I read 18 months ago (when I started this blog) was: &#8220;Never, ever post on Sunday&#8230; people coming back to the office on monday morning will find tons of weekend rss notifications and miss your post among them&#8221;.</p>
<p>But&#8230; since I am not a good blogger and since this blog is mine&#8230; I do post whenever I want <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
<p>Here we are with the second post dedicated to the lightning class I&#8217;m working on. It had to force myself to sit down here and write again about this, I am working on other 3 nice experiments and the fun part of this class for me has already gone, now starts the boring part: optimize/parametrize/explainize. But I think it could be interesting for someone, so here we are.</p>
<p>Still no code, I still have to optimize/parametrize but I can start to &#8220;explain-ize&#8221;. In the first post we just saw a couple of samples running. Some people asked me for the raw logic behind this. </p>
<p>The key here are two perlinNoise, one for simulate the macro behaviour and one for the micro variations. As often a monodimensional (1px height) perlinNoise is perfect to simulate bidimensional effects, since perlinNoise images contain an additional dimension defined by luminosity variations.</p>
<p>So, if from a 2D perlinNoise image you can easily get a <a href='http://blog.oaxoa.com/category/voxels/'>3D voxelTerrain</a> (X+Y+Height), from a 1D image you can easily get for instance 2D mountains (X+Height).<br />
1px height perlinNoise images are very fast to render so they do not kill your cpu even if many of them are used.</p>
<p>I have prepared two &#8220;debug&#8221; sample movies. The first is to show how the two perlinNoise bitmapDatas affect the movement of the final shape (children are disabled for clarity purpose).</p>
<p><a href='http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test3.swf&#038;w=500&#038;h=400'><img src='http://blog.oaxoa.com/wp-content/lightning_test3.jpg' width='500' height='400' alt='' /><br />Debug sample #1</a></p>
<p>As you can see there are 3 different grey bars under the lightning:</p>
<ul>
<li>The first one is the perlinNoise used to displace the discharge on a micro scale</li>
<li>the second one for the macro movements (this is really what makes it feel as real)</li>
<li>the third one is the image merged onto the second one to smooth the edges.</li>
</ul>
<p>Obviously the 3 bitmaps are 1 pixel height, I just stretched them here to 30px to make &#8216;em visible.</p>
<p>Speaking about perlinNoise edges smoothing this is the fact: without any smoothing the extremities of the perlinNoise have a random value between 0&#215;000000 and 0xffffff which stand for black and white. Black value will displace the beam in a negative direction, white value will displace it in a positive direction. To be sure the edges are sticked to the x/y coords of the graphic that simulates the origin of the discharge, we need no displacement at the beginning and at the end.<br />
No displacement=grey value (0&#215;808080).</p>
<p>The easiest way to do this is to create a vector shape, fill it with a gradient (alphas=[1,0,0,1]), adjust ration accordingly to the smooth percentage and draw it onto the macro variations bitmap (Bitmap.draw(&#8230;)). Is off course possible to to this directly using bitmap methods. But I found this being the most natural for me. I like the idea to mix vector and bitmaps using the easiest way for what I need.</p>
<p>Naturally you cannot set the last pixels to medium gray without some smooth transition, and so we use the gradient. Check this sample with code snippet:</p>
<p><a href='http://blog.oaxoa.com/wp-content/examples/showExample.php?f=perlinSmoothed.swf&#038;w=500&#038;h=101'><img src='http://blog.oaxoa.com/wp-content/perlinSmoothed.jpg' width='500' height='101' alt='' /><br />perlinNoise edges smoothing</a></p>
<pre lang='actionscript'>
const grey:uint=0x808080;
var smooth:Sprite=new Sprite();
var ratioOffset:uint=smoothPercentage/100*128;
smooth.graphics.beginGradientFill(GradientType.LINEAR, [grey, grey, grey, grey], [1, 0, 0, 1], [0, ratioOffset, 255-ratioOffset, 255], matrix);
smooth.graphics.drawRect(0, 0, w, 1);
</pre>
<p>I used the smoothing only on the macro bitmap, not one the micro too save some cpu cycle on a barely visible detail and because I like the micro variations on the edges too. </p>
<p>The second one shows the same concept applied also to children with a slider to vary the children birth probability:</p>
<blockquote><p>[demo removed cause I overwrote the files LOL. Don't ask to get them from backups please, simply refer to part 3 post <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ]</p></blockquote>
<p>The main beam can create bridges of electricity, or &#8220;children&#8221;. A child is simply another instance of the class with a &#8220;generationNumber&#8221; parameter to manage descendant probability and avoid infite recursion. All the rules described until now  applies to children too. Children need to be sticked to the parent beam so they always have a non-variable smoothing of 50%.</p>
<p>Coming soon with part 3 and the full class.<br />
As always leave a comment if you find something interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/04/26/actionscript-3-lightning-class-step-2/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 Lightning class &#8211; First tests</title>
		<link>http://blog.oaxoa.com/2009/04/23/actionscript-3-lightning-class-first-tests/</link>
		<comments>http://blog.oaxoa.com/2009/04/23/actionscript-3-lightning-class-first-tests/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 23:04:49 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[advanced image editing]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[perlinNoise]]></category>
		<category><![CDATA[Physics]]></category>
		<category><![CDATA[simulation]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=72</guid>
		<description><![CDATA[Here again with the first test of a Fx class. The class can render lightnings with these specs: - different shapes and aspect - variable edge-smoothness to keep the extremities sticked to the origin - runtime children generation (every trunk can generate children) Sample #1 Sample #2 Perhaps not that useful but could be nice [...]]]></description>
			<content:encoded><![CDATA[<p>Here again with the first test of a Fx class.</p>
<p>The class can render lightnings with these specs:</p>
<p>- different shapes and aspect<br />
- variable edge-smoothness to keep the extremities sticked to the origin<br />
- runtime children generation (every trunk can generate children)</p>
<p><a href='http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test2.swf&#038;w=550&#038;h=400'><img src='http://blog.oaxoa.com/wp-content/lightning_test2.jpg' width='500' height='137' alt='' /><br />Sample #1</a></p>
<p><a href='http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test1.swf&#038;w=550&#038;h=400'><img src='http://blog.oaxoa.com/wp-content/lightning_test1.jpg' width='550' height='400' alt='' /><br />Sample #2</a></p>
<p>Perhaps not that useful but could be nice to implement in some game or demo.<br />
Code soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/04/23/actionscript-3-lightning-class-first-tests/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>(Useless) Nightly delirium</title>
		<link>http://blog.oaxoa.com/2009/04/21/useless-nightly-delirium/</link>
		<comments>http://blog.oaxoa.com/2009/04/21/useless-nightly-delirium/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 23:28:10 +0000</pubDate>
		<dc:creator>Pierluigi Pesenti</dc:creator>
				<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[fun]]></category>

		<guid isPermaLink="false">http://blog.oaxoa.com/?p=67</guid>
		<description><![CDATA[Just some hypno-fun with drawing APIs: Click to self-hypnotize p.s.: this zoom back infinitely (more and more drawing API usage) so do not leave it run wildly or your cpu will burn Code: var w:Number=stage.stageWidth; var h:Number=stage.stageHeight; var steps:uint=5; var stepAngle:Number=720/steps; var div:Number=2; var inita:Number=0; var acc:Number=0; function render(event:Event):void { acc+=1; div+=.02; inita+=.2; this.graphics.clear(); this.graphics.beginFill(0); [...]]]></description>
			<content:encoded><![CDATA[<p>Just some hypno-fun with drawing APIs:</p>
<p><a href='http://blog.oaxoa.com/wp-content/examples/showExample.php?f=delirium.swf&#038;w=550&#038;h=400'><img src='http://blog.oaxoa.com/wp-content/delirium.jpg' width='550' height='400' alt='' /><br />Click to self-hypnotize</a></p>
<p>p.s.: this zoom back infinitely (more and more drawing API usage) so do not leave it run wildly or your cpu will burn <img src='http://blog.oaxoa.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Code:</p>
<pre lang='actionscript'>
var w:Number=stage.stageWidth;
var h:Number=stage.stageHeight;
var steps:uint=5;
var stepAngle:Number=720/steps;
var div:Number=2;
var inita:Number=0;
var acc:Number=0;

function render(event:Event):void {
	acc+=1;
	div+=.02;
	inita+=.2;
	this.graphics.clear();
	this.graphics.beginFill(0);
	this.graphics.moveTo(w/2, h/2);
	var r:Number=1;
	var a:Number;
	var arad:Number;
	var i:int=0;
	while (r<1000) {
		if (div!=0) r+=r/div;
		a=inita;
		for (i=0; i<steps; i++) {
			a+=stepAngle;
			arad=a/180*Math.PI;
			this.graphics.lineTo(w/2+Math.cos(arad)*r, h/2+Math.sin(arad)*r);
		}
	}
}
addEventListener(Event.ENTER_FRAME, render);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.oaxoa.com/2009/04/21/useless-nightly-delirium/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
