<?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>Mindfock &#187; Programming and Development</title>
	<atom:link href="http://blog.mindfock.com/category/programming-and-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mindfock.com</link>
	<description>Flash and ActionScript for the masses. With a little Python thrown in.</description>
	<lastBuildDate>Wed, 31 Mar 2010 10:07:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Photographic mosaics</title>
		<link>http://blog.mindfock.com/photographic-mosaics/</link>
		<comments>http://blog.mindfock.com/photographic-mosaics/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 09:06:00 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[photomosaic]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/photographic-mosaics/</guid>
		<description><![CDATA[I haven’t posted in a long while, mostly because of school. I managed some free time the past few days and wrote a photographic mosaic generator in Python. Why not call it by its more popular name? Because it is trademarked and patented. But I don’t think I’ll get into any trouble by posting this, [...]]]></description>
			<content:encoded><![CDATA[<p>I haven’t posted in a long while, mostly because of school. I managed some free time the past few days and wrote a photographic mosaic generator in Python. Why not call it by its more popular name? Because it is <a href="http://en.wikipedia.org/wiki/Photographic_mosaic#Intellectual_property" target="_blank">trademarked and patented</a>. But I don’t think I’ll get into any trouble by posting this, as this is merely for learning purposes, right?</p>
<p>This is a relatively simple solution. I didn’t use any complex algorithms like edge-detection, dithering or whatever (maybe I could add those later), just plain old RGB matching. I’ll try to explain the process as best and as simply as I can.</p>
<h4>Creating the image pool</h4>
<p>The first step is to create your <em>image pool</em>.&#160; The image pool is a directory of all the tiles that will be used in your mosaic, and every tile must be of the same size. The more tiles you have, the better results you get. </p>
<p>I used <a href="http://www.irfanview.com/" target="_blank">Irfanview</a> to resize, crop, rotate and rename 1,983 photos for my image pool, plus a Python script I wrote to separate the portrait oriented photos from the landscape oriented ones. </p>
<p>Next, I wrote another Python script to create an SQLite database which stores all the data I need to create a photomosaic, instead of calculating each value every time I want to create a mosaic. It holds a reference to an image file, and 9 RGB values.</p>
<p>To calculate the RGB values of a tile, I didn’t just get the average color of the entire tile, instead I divided the tile into a 3&#215;3 grid, then calculated the average RGB value of each cell in the grid (resulting in 9 values). I think this method is called “sub-sampling”. This helps in making more accurate matches. (Pardon the crappy images, I’m making these in Paint.NET)</p>
<p align="center"><a href="http://blog.mindfock.com/wp-content/uploads/2009/10/tilesubave1.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="tile-sub-ave" border="0" alt="tile-sub-ave" src="http://blog.mindfock.com/wp-content/uploads/2009/10/tilesubave_thumb1.jpg" width="204" height="52" /></a> </p>
<p align="center">Subdivided tile –&gt; (Pseudo) Average colors</p>
<h4>Generating the mosaic</h4>
<p align="left">Now that I have my image pool ready, I can start generating the photographic mosaic itself. I won’t go into the too much detail but basically I subdivide the source image with the size of my tiles. I then iterate over the subdivisions and further subdivide each cell into a 3&#215;3 sub-grid to match against the tiles. I calculate and compare the RGB differences between every tile in my image pool, and get the best result (least difference). I then place the best tile into its proper position in the mosaic. </p>
<p align="center"><a href="http://blog.mindfock.com/wp-content/uploads/2009/10/match1.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="match" border="0" alt="match" src="http://blog.mindfock.com/wp-content/uploads/2009/10/match_thumb1.jpg" width="420" height="52" /></a> </p>
<p align="center">Subdivided cell –&gt; Average colors of cell&#160;&#160; =&#160;&#160; Average colors of tile –&gt; Best matching tile</p>
<p>I added an extra method that starts matching from the middle of the source image, going outward. This generates a mosaic where the best matches are in the center, and leftover tiles go to the edges, resulting in a better looking mosaic, especially for portraits. </p>
<p><a href="http://blog.mindfock.com/wp-content/uploads/2009/10/mosaic51.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="mosaic5" border="0" alt="mosaic5" src="http://blog.mindfock.com/wp-content/uploads/2009/10/mosaic5_thumb1.jpg" width="244" height="184" /></a> <a href="http://blog.mindfock.com/wp-content/uploads/2009/10/mosaic71.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="mosaic7" border="0" alt="mosaic7" src="http://blog.mindfock.com/wp-content/uploads/2009/10/mosaic7_thumb1.jpg" width="244" height="184" /></a> </p>
<p align="center">Top-down matching vs. Inside-out matching</p>
<p align="left">In the first one, by the time I got to the center, I ran out of good tiles to use. For the second one, the best tiles are used in the center. </p>
</p>
<h4><strong>Results</strong></h4>
<p><a href="http://blog.mindfock.com/wp-content/uploads/2009/10/monalisamosaic1.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="mona-lisa-mosaic" border="0" alt="mona-lisa-mosaic" src="http://blog.mindfock.com/wp-content/uploads/2009/10/monalisamosaic_thumb1.jpg" width="184" height="244" /></a> <a href="http://blog.mindfock.com/wp-content/uploads/2009/10/eljohn11.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="eljohn1" border="0" alt="eljohn1" src="http://blog.mindfock.com/wp-content/uploads/2009/10/eljohn1_thumb1.jpg" width="244" height="184" /></a> </p>
<p><a href="http://blog.mindfock.com/wp-content/uploads/2009/10/eljohn21.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="eljohn2" border="0" alt="eljohn2" src="http://blog.mindfock.com/wp-content/uploads/2009/10/eljohn2_thumb1.jpg" width="244" height="184" /></a> <a href="http://blog.mindfock.com/wp-content/uploads/2009/10/mosaic81.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="mosaic8" border="0" alt="mosaic8" src="http://blog.mindfock.com/wp-content/uploads/2009/10/mosaic8_thumb1.jpg" width="244" height="184" /></a> </p>
<h4>Try it out</h4>
<p>This is just a bunch of Python scripts, so there is no executable to run. </p>
<p>Just type </p>
<pre>&gt;python photomosaic.py path\to\source.jpg path\to\output.jpg path\to\imagepool\dir [-options]</pre>
<p>on the command line. Type <code>--help</code> to see possible options. </p>
<p>Of course, preparing the image pool is the most difficult part of creating a mosaic. You can use the <code>create_image_pool.py</code> script to do that for you. Just make sure all your tiles are of the same size, and it will automatically create an SQLite file inside your pool directory which the photomosaic generator can use. </p>
<pre>&gt;python create_image_pool.py path\to\imagepool\dir</pre>
<p>If you don’t have 2,000 images lying around, you can go to <a href="http://blog.wolfram.com/2008/05/02/making-photo-mosaics/" target="_blank">this page</a>. At the bottom of his post he has a link to .zip of photos of chemical elements. It’s already resized for you. </p>
<p>Right now, generating a 1,600 tiles mosaic from ~2,000 tiles takes about ~5 minutes on my slow-ish machine. My next goal would have to be speed and better matching algorithms.</p>
<p><a href="http://www.mindfock.com/experiments/photomosaic/photomosaic.zip">Download photomosaic.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/photographic-mosaics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Python + Tetris</title>
		<link>http://blog.mindfock.com/python-tetris/</link>
		<comments>http://blog.mindfock.com/python-tetris/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 06:12:35 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/python-tetris/</guid>
		<description><![CDATA[I’ve always wanted to try out Python, and I’ve been meaning to make a Tetris clone for some time now ( my last attempt in Flash failed ). Since I didn’t have anything to do for the remainder of the summer, I decided to do both. I wanted to post about this last week, during [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve always wanted to try out <a href="http://www.python.org" target="_blank">Python</a>, and I’ve been meaning to make a Tetris clone for some time now ( my last attempt in Flash failed ). Since I didn’t have anything to do for the remainder of the summer, I decided to do both. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>I wanted to post about this last week, during <a href="http://www.gametrailers.com/video/e3-09-tetris/51160" target="_blank">Tetris’ 25th anniversary</a>, but it wasn’t done. This is my first Python app, so the code is filthy. I am quite proud of it though. </p>
<p>Unfortunately, I don’t know how to make an executable from a Python program, and the guys at the #python channel are less than helpful, so I’ll just put up a zip of all the files. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Python is fun and easy to learn, but I think I’ll stick with Flash. I will also be studying <a href="http://www.djangoproject.com" target="_blank">Django</a>.</p>
<p>You need to have <a href="http://python.org" target="_blank">Python</a> and <a href="http://www.pygame.org" target="_blank">Pygame</a> installed to run it though, until I figure out how to make an executable.</p>
<p><a href="http://mindfock.com/images/PythonTetris_93F1/tetrysmenu.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="tetrys-menu" border="0" alt="tetrys-menu" src="http://mindfock.com/images/PythonTetris_93F1/tetrysmenu_thumb.jpg" width="156" height="244" /></a>&#160; <a href="http://mindfock.com/images/PythonTetris_93F1/tetrysgame.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="tetrys-game" border="0" alt="tetrys-game" src="http://mindfock.com/images/PythonTetris_93F1/tetrysgame_thumb.jpg" width="156" height="244" /></a> </p>
<p><a href="http://www.mindfock.com/experiments/Tetris/Tetrys.zip">Download the zip</a>. Extract and run Main.py in ‘src/’ folder using Python. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/python-tetris/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RGB to Hexadecimal to HSV conversion in AS3</title>
		<link>http://blog.mindfock.com/rgb-to-hexadecimal-to-hsv-conversion-in-as3/</link>
		<comments>http://blog.mindfock.com/rgb-to-hexadecimal-to-hsv-conversion-in-as3/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 23:19:07 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=65</guid>
		<description><![CDATA[In my previous post, I needed to do a lot of conversion between different representations of color. I think a post on how to convert color would be useful. private function RGBToHex(r:uint, g:uint, b:uint):uint{ var hex:uint = (r &#60;&#60; 16 &#124; g &#60;&#60; 8 &#124; b); return hex; } private function HexToRGB(hex:uint):Array{ var rgb:Array = [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post, I needed to do a lot of conversion between different representations of color. I think a post on how to convert color would be useful.</p>
<pre class="brush: jscript;">
private function RGBToHex(r:uint, g:uint, b:uint):uint{
    var hex:uint = (r &lt;&lt; 16 | g &lt;&lt; 8 | b);
    return hex;
}

private function HexToRGB(hex:uint):Array{
    var rgb:Array = [];

    var r:uint = hex &gt;&gt; 16 &amp; 0xFF;
    var g:uint = hex &gt;&gt; 8 &amp; 0xFF;
    var b:uint = hex &amp; 0xFF;

    rgb.push(r, g, b);
    return rgb;
}

private function RGBtoHSV(r:uint, g:uint, b:uint):Array{
    var max:uint = Math.max(r, g, b);
    var min:uint = Math.min(r, g, b);

    var hue:Number = 0;
    var saturation:Number = 0;
    var value:Number = 0;

    var hsv:Array = [];

    //get Hue
    if(max == min){
        hue = 0;
    }else if(max == r){
        hue = (60 * (g-b) / (max-min) + 360) % 360;
    }else if(max == g){
        hue = (60 * (b-r) / (max-min) + 120);
    }else if(max == b){
        hue = (60 * (r-g) / (max-min) + 240);
    }

    //get Value
    value = max;

    //get Saturation
    if(max == 0){
        saturation = 0;
    }else{
        saturation = (max - min) / max;
    }

    hsv = [Math.round(hue), Math.round(saturation * 100), Math.round(value / 255 * 100)];
    return hsv;

}

private function HSVtoRGB(h:Number, s:Number, v:Number):Array{
    var r:Number = 0;
    var g:Number = 0;
    var b:Number = 0;
    var rgb:Array = [];

    var tempS:Number = s / 100;
    var tempV:Number = v / 100;

    var hi:int = Math.floor(h/60) % 6;
    var f:Number = h/60 - Math.floor(h/60);
    var p:Number = (tempV * (1 - tempS));
    var q:Number = (tempV * (1 - f * tempS));
    var t:Number = (tempV * (1 - (1 - f) * tempS));

    switch(hi){
        case 0: r = tempV; g = t; b = p; break;
        case 1: r = q; g = tempV; b = p; break;
        case 2: r = p; g = tempV; b = t; break;
        case 3: r = p; g = q; b = tempV; break;
        case 4: r = t; g = p; b = tempV; break;
        case 5: r = tempV; g = p; b = q; break;
    }

    rgb = [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
    return rgb;
}
</pre>
<p>The code above requires and returns:</p>
<ul>
<li>RGB values between 0 to 255</li>
<li>Hexadecimal in RRGGBB format</li>
<li>Hue values between 0 to 360</li>
<li>Saturation and Value between 0 to 100</li>
</ul>
<p>Notice that the &#8220;middleman&#8221; is RGB. </p>
<p>And, just in case you only have the Hexadecimal string to work with, here is the code to convert that string into a usable decimal value.</p>
<pre class="brush: jscript;">
private function HexToDeci(hex:String):uint{
	var deci:uint = 0;
	var power:uint = hex.length - 1;
	for(var i:uint = 0; i &lt; hex.length; i++){
		var char:String = hex.charAt(i);
		if(parseInt(char) &gt;= 0 &amp;&amp;  parseInt(char) &lt;= 9){
			deci += parseInt(char) * Math.pow(16, power);
		}else{
			switch(char){
				case &quot;A&quot;: case &quot;a&quot;:	deci += 10 * Math.pow(16, power); break;
				case &quot;B&quot;: case &quot;b&quot;:	deci += 11 * Math.pow(16, power); break;
				case &quot;C&quot;: case &quot;c&quot;:	deci += 12 * Math.pow(16, power); break;
				case &quot;D&quot;: case &quot;d&quot;:	deci += 13 * Math.pow(16, power); break;
				case &quot;E&quot;: case &quot;e&quot;:	deci += 14 * Math.pow(16, power); break;
				case &quot;F&quot;: case &quot;f&quot;:	deci += 15 * Math.pow(16, power); break;
			}
		}

		power --;
	}
	return deci;
}
</pre>
<p>EDIT: I&#8217;ve just gathered that there is a much much simpler way to convert a Hexadecimal string into a usable number. I feel kind of stupid right now. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  </p>
<pre class="brush: jscript;">
private function HexToDeci(hex:String):uint{
        if (hex.substr(0, 2) != &quot;0x&quot;) {
                hex = &quot;0x&quot; + hex;
        }
        return new uint(hex);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/rgb-to-hexadecimal-to-hsv-conversion-in-as3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Metaballs update</title>
		<link>http://blog.mindfock.com/metaballs-update/</link>
		<comments>http://blog.mindfock.com/metaballs-update/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 01:32:46 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=61</guid>
		<description><![CDATA[Still delving into metaballs. I implemented the suggestions in this page for optimizing, and the results are good. I could even animate it &#8211; just barely though, at ~15 FPS on my browser.  Again, most of this is just copy &#38; paste from the source provided in the tutorial. Metaballs &#8211; move your mouse around. [...]]]></description>
			<content:encoded><![CDATA[<p>Still delving into metaballs. I implemented the suggestions in this <a href="http://www.gamedev.net/reference/programming/features/isometa2d/page4.asp" target="_blank">page</a> for optimizing, and the results are good. I could even animate it &#8211; just barely though, at ~15 FPS on my browser. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Again, most of this is just copy &amp; paste from the <a href="http://www.gamedev.net/reference/programming/features/isometa2d/page5.asp" target="_blank">source</a> provided in the <a href="http://www.gamedev.net/reference/programming/features/isometa2d/" target="_blank">tutorial</a>.</p>
<p><a href="http://www.mindfock.com/experiments/Metaballs/bin/Metaballs-updated.html" target="_self">Metaballs</a> &#8211; move your mouse around.  Click to change the target ball.</p>
<p>Still looking for a more elegant solution for Flash. This is done on a very small stage size, with only 4 balls. I want to do a full screen version, with at least 10 balls moving around. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/metaballs-update/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Metaballs</title>
		<link>http://blog.mindfock.com/simple-metaballs/</link>
		<comments>http://blog.mindfock.com/simple-metaballs/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 06:22:14 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Programming and Development]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=60</guid>
		<description><![CDATA[I stumbled upon Metaballs yesterday, and decided it would be cool to try it out. I&#8217;ve seen some very nice examples done in Flash, but no luck finding their sources. After Googling around, I found this tutorial on Metaballs and computer graphics. I ported the code into AS3, but the result is not very impressive. [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled upon <a href="http://en.wikipedia.org/wiki/Metaball" target="_blank">Metaballs</a> yesterday, and decided it would be cool to try it out. I&#8217;ve seen some very nice examples done in Flash, but no luck finding their sources.</p>
<p>After Googling around, I found this <a href="http://www.gamedev.net/reference/programming/features/isometa2d/page2.asp" target="_blank">tutorial</a> on Metaballs and computer graphics.</p>
<p>I ported the code into AS3, but the <a href="http://www.mindfock.com/experiments/Metaballs/bin/Metaballs.html">result</a> is not very impressive. It is very slow and processor heavy. If you click on the stage, the last Metaball added will be moved, and as you can see, it takes a bit of time to redraw them. I&#8217;m not even thinking about animating this. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><a href="http://www.mindfock.com/experiments/Metaballs/bin/Metaballs-updated.html"><img src="http://www.mindfock.com/experiments/Metaballs/metaball.png" alt="Metaballs" width="320" height="240" /></a></p>
<p>I&#8217;m still looking for a more elegant solution for Flash, hopefully one that uses the Vector-based drawing API of Flash, and not BitmapData.</p>
<p>UPDATE: I have an updated version <a href="http://www.mindfock.com/experiments/Metaballs/bin/Metaballs-updated.html">here</a>. Also, I linked the image above to the updated one. For comparison, the old one is <a href="http://www.mindfock.com/experiments/Metaballs/bin/Metaballs.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/simple-metaballs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nifty FPS/CPU monitor class</title>
		<link>http://blog.mindfock.com/nifty-fpscpu-monitor-class/</link>
		<comments>http://blog.mindfock.com/nifty-fpscpu-monitor-class/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 04:19:37 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Classes]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=51</guid>
		<description><![CDATA[I found this little class that displays the framerate of the current movie and the total memory usage of the Flash Player on your movie. It also shows the version of the player and the operating system you are on. It even has a graph. Very useful for monitoring your experiments or whatever.  Link. If [...]]]></description>
			<content:encoded><![CDATA[<p>I found this little class that displays the framerate of the current movie and the total memory usage of the Flash Player on your movie. It also shows the version of the player and the operating system you are on. It even has a graph. Very useful for monitoring your experiments or whatever. </p>
<p><a title="FPSMonitor class" href="http://www.flashfuck.it/2008/05/27/fpsmonitor-for-as3-and-flex-projects/#comment-68" target="_blank">Link.</a></p>
<p>If anyone knows something better, please let me know. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/nifty-fpscpu-monitor-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Papervision test</title>
		<link>http://blog.mindfock.com/papervision-test/</link>
		<comments>http://blog.mindfock.com/papervision-test/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 04:41:28 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Papervision]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=50</guid>
		<description><![CDATA[It&#8217;s been a while since I&#8217;ve posted here. Got caught up with exams and projects for school, and a lot of DotA with friends. Now sem-break is here, I  can now just sit around and be bored. I&#8217;ve been playing around with Papervsion lately, and have finally understood how to make it work, albeit only [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I&#8217;ve posted here. Got caught up with exams and projects for school, and a lot of <a href="http://www.dota-allstars.com">DotA </a>with friends. Now sem-break is here, I  can now just sit around and be bored.</p>
<p>I&#8217;ve been playing around with Papervsion lately, and have finally understood how to make it work, albeit only lightly. Here is one of my first attempts with Papervision. It&#8217;s just a bunch of spheres, where clicking on one will move the camera to its position, while the camera focuses on the center.</p>
<p>It&#8217;s not much. I&#8217;m still working on it, but I just wanted to post something here. <a href="http://www.mindfock.com/experiments/SphereCamera/floatingparticles.html">Check it out</a>. <a href="http://get.adobe.com/flashplayer/">Flash Player 10 is required.</a></p>
<p><a href="http://www.mindfock.com/experiments/SphereCamera/floatingparticles.html"><img class="aligncenter" title="Particles in 3D" src="http://www.mindfock.com/experiments/SphereCamera/particles.jpg" alt="Floating particles" /></a></p>
<p>Update: I&#8217;ve added a depth of field effect. It&#8217;s not very &#8220;accurate&#8221;, but it&#8217;s a nice touch. I don&#8217;t know how to do it efficiently, so it might be CPU intensive.</p>
<p>Update 2: I&#8217;ve added random movement to the particles.</p>
<p>As always, the <a href="http://www.mindfock.com/experiments/SphereCamera/Main.as">source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/papervision-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Builder, Papervision and GTween &#8211; great way to get the ball rolling again</title>
		<link>http://blog.mindfock.com/flex-builder-papervision-and-gtween-great-way-to-get-the-ball-rolling-again/</link>
		<comments>http://blog.mindfock.com/flex-builder-papervision-and-gtween-great-way-to-get-the-ball-rolling-again/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 15:50:02 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Engines]]></category>
		<category><![CDATA[FlexBuilder]]></category>
		<category><![CDATA[Papervision]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=48</guid>
		<description><![CDATA[Greetings all, still haven&#8217;t fixed the PC, and no plans in buying a new one. But, being forced to use a Macbook with no games installed(damn DotA) and a slow connection, I managed to find some time to get back into Flash and ActionScript. I finally figured out how to setup external class libraries in [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings all, still haven&#8217;t fixed the PC, and no plans in buying a new one. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  But, being forced to use a Macbook with no games installed(damn <a title="Defense of the Ancients" href="http://www.dota-allstars.com/">DotA</a>) and a slow connection, I managed to find some time to get back into Flash and ActionScript. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I finally figured out how to setup external class libraries in FlexBuilder, which took longer than I would have hoped. Now I can use Papervision3D, Away3D and have a central library for all other API&#8217;s and classes.  It&#8217;s not as enjoyable as FlashDevelop, but, it&#8217;s better than nothing.</p>
<p>I also started playing with PV3D, which is just awesome. Very fun to play around with, and I can&#8217;t wait to make something I could use for my eternally work-in-progress site.</p>
<p>And finally, there&#8217;s a new tweening engine on the block. It&#8217;s called <a title="GTween" href="http://www.gskinner.com/blog/archives/2008/08/gtween_a_new_tw.html">gTween</a> and it&#8217;s made by <a title="gSkinner" href="http://www.gskinner.com/blog">Grant Skinner</a>, so you know it&#8217;s great. Like TweenLite, it aims for speed and it&#8217;s also very lightweight. It&#8217;s still in beta, and not as powerful and feature-packed as TweenMax or other tweening engines. I haven&#8217;t tested it enough to choose it over TweenLite yet, but, I like it&#8217;s different approach to creating and managing (yep, you could manage, edit, reuse and even nest) tweens. Check it out <a title="gTween blog post" href="http://www.gskinner.com/blog/archives/2008/08/gtween_a_new_tw.html">here</a>.</p>
<p>And, yeah, I would post my little &#8220;experiment&#8221; with Papervision, but I can&#8217;t seem to extract/find the swf file. I even tried using the .as file as a Document class to a Flash file, but I still can&#8217;t double-click and play the movie. </p>
<p>I am also having trouble with FlexBuilder, whenever I Run/Play button to test a project, it often doesn&#8217;t show anything until several retries or not at all, but using the .as file as a Doc class to a Flash file, it plays fine. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' />  Any help would be very much appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/flex-builder-papervision-and-gtween-great-way-to-get-the-ball-rolling-again/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[Learn] A &#8220;pixelating&#8221; effect on a Bitmap</title>
		<link>http://blog.mindfock.com/learn-a-pixelating-effect-on-a-bitmap/</link>
		<comments>http://blog.mindfock.com/learn-a-pixelating-effect-on-a-bitmap/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 14:19:03 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Learn]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=44</guid>
		<description><![CDATA[I did a little experimenting with the BitmapData class, and came up with this. I found this effect from a gallery somewhere, and thought it would be cool to try my hand at it, for learning purposes. Click on the image below to see the effect. 
<object	type="application/x-shockwave-flash"
			data="http://www.mindfock.com/blog/wp-content/uploads/2008/06/pixelate.swf"
			width="300"
			height="225">
	<param name="movie" value="http://www.mindfock.com/blog/wp-content/uploads/2008/06/pixelate.swf" />
</object> What&#8217;s happening is, I [...]]]></description>
			<content:encoded><![CDATA[<p>I did a little experimenting with the BitmapData class, and came up with this.<br />
I found this effect from a gallery somewhere, and thought it would be cool to try my hand at it, for learning purposes.</p>
<p>Click on the image below to see the effect.</p>

<object	type="application/x-shockwave-flash"
			data="http://www.mindfock.com/blog/wp-content/uploads/2008/06/pixelate.swf"
			width="300"
			height="225">
	<param name="movie" value="http://www.mindfock.com/blog/wp-content/uploads/2008/06/pixelate.swf" />
</object>
<p>What&#8217;s happening is, I get the size of the image, divide it by the size of the &#8220;pixels&#8221; I want, then create an array of Rectangles positioned in a grid over the image.<br />
I then fill each Rectangle with the color of the pixel in it&#8217;s center by using the getPixel() and fillRect() methods of the BitmapData class.<br />
Here is the central function doing the pixelating.</p>
<pre class="brush: jscript;">
private function pixelate(bitmap:Bitmap, strength:Number):void {
var _x:int = 0; // position of the rectangle
var _y:int = 0;
if (strength &gt; 1){
_strength = 1;
}
var _strength:Number = strength; // multiplier for size of &quot;pixels&quot;

var _w:Number = bitmap.bitmapData.width * _strength; //size of &quot;pixels&quot;
var _h:Number = bitmap.bitmapData.height * _strength;

var nH:int = Math.ceil(bitmap.bitmapData.width / _w); // number of rectangles needed horizontally
var nV:int = Math.ceil(bitmap.bitmapData.height / _h);// number of rectangles needed vertically

var rectangles:Array = []; // Rectangles array

//create rectangles
for (var i:int = 0; i &lt; nV; i ++){
var targH:Number = _h;
if (i &gt;= nV - 1){
targH = bitmap.bitmapData.height - _y;
}
for (var j:int = 0; j &lt; nH; j ++){
var targW:Number = _w;
if (j &gt;= nH - 1){
targW = bitmap.bitmapData.width - _x;
}
rectangles.push(new Rectangle(_x, _y, targW, targH));
_x += _w;
}
_x = 0;
_y += _h;

}
//fill in rectangles
for (i = 0; i &lt; rectangles.length; i++){

var rect:Rectangle = rectangles[i];
var pix:uint = _states[0].getPixel((rect.x + rect.width / 2), (rect.y + rect.height / 2));
bitmap.bitmapData.fillRect(rect, pix);
}

saveCurrentState(bitmap.bitmapData);

}
</pre>
<p>Now for the reverting to the original image part, I had to improvise. Since I overwrote the BitmapData with a bunch of filled rectangles, I couldn&#8217;t do much with it.<br />
So I used an array which stores each &#8220;state&#8221; the BitmapData is in. And I could just retrieve the BitmapData in the array and copy it into the original BitmapData.</p>
<pre class="brush: jscript;">
private function saveCurrentState(bitmapData:BitmapData):void {
_states.push(bitmapData.clone());
}
private function revertToState(stage:int):void {
try{
bmData.copyPixels(_states[stage], bmData.rect, new Point(bmData.rect.x, bmData.rect.y));
}catch (e:Error){
throw new Error(&quot;Invalid state. &quot;);
}
}
</pre>
<p>To create the animation, I just called the pixelate() function through a Timer at 300 milliseconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/learn-a-pixelating-effect-on-a-bitmap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A little heads-up about the Flash Player 9 Garbage Collector</title>
		<link>http://blog.mindfock.com/a-little-heads-up-about-the-flash-player-9-garbage-collector/</link>
		<comments>http://blog.mindfock.com/a-little-heads-up-about-the-flash-player-9-garbage-collector/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 13:01:22 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=42</guid>
		<description><![CDATA[I want to give a heads-up to all those just beginning with AS3 about how it handles memory. I had to find out about this the hard way, and now have to redo a lot of stuff. Flash Player 9 introduced a new system management feature called a garbage collector (GC). Basically, what it does [...]]]></description>
			<content:encoded><![CDATA[<p>I want to give a heads-up to all those just beginning with AS3 about how it handles memory. I had to find out about this the hard way, and now have to redo a lot of stuff.</p>
<p>Flash Player 9 introduced a new system management feature called a garbage collector (GC). Basically, what it does is &#8220;sweep&#8221; for objects that can not be used/accessed anymore, and delete them, freeing memory. Until those &#8216;null&#8217; objects are removed by the GC, they will sit in memory until the Player is closed.</p>
<p>So, whenever you want something to be deleted (escpecially with CPU intensive particle systems), you must be aware of what and where you are referencing your objects, so you could easily remove them.  You have to do this by hand. One method is to set all objects you want to delete, and all references to it,  to null. Even then, you have to wait for the GC to do its &#8220;sweeping motion&#8221; for those objects to be deleted.</p>
<p>Another thing to watch out for are event listeners. Make sure you remove any listeners (by calling removeEventListener()) from objects you want to delete, since they also hold a reference to your objects.</p>
<p>Check this <a href="http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html">article series for more details and info about the GC and resource management in Flash Player 9/AS3.</a></p>
<p>And lastly, it is about unloading external swf&#8217;s through Loader. You might think that using unload() from a Loader would remove that swf completely, but that isn&#8217;t the case.  In fact, unload() does a pretty poor job at &#8220;unloading&#8221; swfs. Here is a quote from another <a href="http://www.gskinner.com/blog/archives/2008/04/failure_to_unlo.html">article</a> that explains this in great detail:</p>
<blockquote><p>In AS3, calling Loader.unload() simply removes the reference to the loaded movie. If any other references exist to the loaded content, it will not be unloaded.</p></blockquote>
<p>My site has been delayed by almost a month now, trying to figure out and fix my memory leak problem. I finally have an idea of what&#8217;s wrong, now I have to figure out a solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/a-little-heads-up-about-the-flash-player-9-garbage-collector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
