<?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>code-spot &#187; Python</title>
	<atom:link href="http://code-spot.co.za/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://code-spot.co.za</link>
	<description>a programming blog</description>
	<lastBuildDate>Wed, 25 Aug 2010 10:59:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Poisson Disk Sampling Example Code</title>
		<link>http://code-spot.co.za/2010/04/07/poisson-disk-sampling-example-code/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=poisson-disk-sampling-example-code</link>
		<comments>http://code-spot.co.za/2010/04/07/poisson-disk-sampling-example-code/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 08:57:27 +0000</pubDate>
		<dc:creator>herman.tulleken</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Downloads]]></category>
		<category><![CDATA[Image Processing]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[poisson disk]]></category>
		<category><![CDATA[procedural texture]]></category>
		<category><![CDATA[sampling]]></category>

		<guid isPermaLink="false">http://code-spot.co.za/?p=806</guid>
		<description><![CDATA[I decided to put the Poisson disk sampling code here for download since the site that hosted it is down. The code accompanies the tutorial on Dev.Mag: Poisson Disk Sampling.
Download



poisson_disk_java.zip (184 KB)
 poisson_disk_python.zip (912 KB)
 poisson_disk_ruby.zip (59 KB)





Related posts:A simple texture algorithm – faster code and more results
A Simple Procedural Texture Algorithm &#8211; More Results [...]


Related posts:<ol><li><a href='http://code-spot.co.za/2008/12/15/a-simple-texture-algorithm-faster-code-and-more-results/' rel='bookmark' title='Permanent Link: A simple texture algorithm – faster code and more results'>A simple texture algorithm – faster code and more results</a></li>
<li><a href='http://code-spot.co.za/2008/11/14/a-simple-procedural-texture-algorithm-more-results-and-code/' rel='bookmark' title='Permanent Link: A Simple Procedural Texture Algorithm &#8211; More Results and Code'>A Simple Procedural Texture Algorithm &#8211; More Results and Code</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-817" title="poisson" src="http://code-spot.co.za/blog/wp-content/uploads/2010/04/poisson3.png" alt="poisson" width="142" height="142" />I decided to put the Poisson disk sampling code here for download since the site that hosted it is down. The code accompanies the tutorial on Dev.Mag: <a href="http://www.devmag.org.za/articles/55-POISSON-DISK-SAMPLING/">Poisson Disk Sampling</a>.</p>
<h2>Download</h2>
<table border="0">
<tbody>
<tr>
<td><a href="http://www.code-spot.co.za/downloads/poisson/poisson_disk_java.zip">poisson_disk_java.zip</a> (184 KB)<br />
<a href="http://www.code-spot.co.za/downloads/poisson/poisson_disk_python.zip"> poisson_disk_python.zip</a> (912 KB)<br />
<a href="http://www.code-spot.co.za/downloads/poisson/poisson_disk_ruby.zip"> poisson_disk_ruby.zip</a> (59 KB)</td>
</tr>
</tbody>
</table>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcode-spot.co.za%2F2010%2F04%2F07%2Fpoisson-disk-sampling-example-code%2F&amp;linkname=Poisson%20Disk%20Sampling%20Example%20Code"><img src="http://code-spot.co.za/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>

<p>Related posts:<ol><li><a href='http://code-spot.co.za/2008/12/15/a-simple-texture-algorithm-faster-code-and-more-results/' rel='bookmark' title='Permanent Link: A simple texture algorithm – faster code and more results'>A simple texture algorithm – faster code and more results</a></li>
<li><a href='http://code-spot.co.za/2008/11/14/a-simple-procedural-texture-algorithm-more-results-and-code/' rel='bookmark' title='Permanent Link: A Simple Procedural Texture Algorithm &#8211; More Results and Code'>A Simple Procedural Texture Algorithm &#8211; More Results and Code</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://code-spot.co.za/2010/04/07/poisson-disk-sampling-example-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting More out of Seamless Tiles</title>
		<link>http://code-spot.co.za/2009/05/28/getting-more-out-of-seamless-tiles/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=getting-more-out-of-seamless-tiles</link>
		<comments>http://code-spot.co.za/2009/05/28/getting-more-out-of-seamless-tiles/#comments</comments>
		<pubDate>Thu, 28 May 2009 08:46:07 +0000</pubDate>
		<dc:creator>herman.tulleken</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Image Processing]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[blending]]></category>
		<category><![CDATA[Dev.Mag]]></category>
		<category><![CDATA[grids]]></category>
		<category><![CDATA[tiles]]></category>

		<guid isPermaLink="false">http://code-spot.co.za/?p=620</guid>
		<description><![CDATA[I wrote an article for Dev.Mag covering some techniques for working with seamless tile sets such as making blend tiles, getting more variety with procedural colour  manipulation, tile placement strategies, and so on. 
Check it out!
The Python Image Code has also been updated with some of the algorithms explained in the article.


Related posts:Quadtrees
Quadtrees
Cellular Automata for Simulation in Games



Related posts:<ol><li><a href='http://code-spot.co.za/2008/10/06/quadtrees/' rel='bookmark' title='Permanent Link: Quadtrees'>Quadtrees</a></li>
<li><a href='http://code-spot.co.za/2008/11/15/quadtrees-2/' rel='bookmark' title='Permanent Link: Quadtrees'>Quadtrees</a></li>
<li><a href='http://code-spot.co.za/2009/04/09/cellular-automata-for-simulation-in-games/' rel='bookmark' title='Permanent Link: Cellular Automata for Simulation in Games'>Cellular Automata for Simulation in Games</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-622" title="tiles_header_small" src="http://code-spot.co.za/blog/wp-content/uploads/2009/05/tiles_header_small.png" alt="tiles_header_small" width="142" height="142" />I wrote an article for Dev.Mag covering <a href="http://www.devmag.org.za/articles/70-GETTING-MORE-OUT-OF-SEAMLESS-TILES/">some techniques for working with seamless tile sets</a> such as making blend tiles, getting more variety with procedural colour  manipulation, tile placement strategies, and so on. </p>
<p>Check it out!</p>
<p>The <a href="http://code-spot.co.za/python-image-code/">Python Image Code</a> has also been updated with some of the algorithms explained in the article.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcode-spot.co.za%2F2009%2F05%2F28%2Fgetting-more-out-of-seamless-tiles%2F&amp;linkname=Getting%20More%20out%20of%20Seamless%20Tiles"><img src="http://code-spot.co.za/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>

<p>Related posts:<ol><li><a href='http://code-spot.co.za/2008/10/06/quadtrees/' rel='bookmark' title='Permanent Link: Quadtrees'>Quadtrees</a></li>
<li><a href='http://code-spot.co.za/2008/11/15/quadtrees-2/' rel='bookmark' title='Permanent Link: Quadtrees'>Quadtrees</a></li>
<li><a href='http://code-spot.co.za/2009/04/09/cellular-automata-for-simulation-in-games/' rel='bookmark' title='Permanent Link: Cellular Automata for Simulation in Games'>Cellular Automata for Simulation in Games</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://code-spot.co.za/2009/05/28/getting-more-out-of-seamless-tiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating Random Integers With Arbitrary Probabilities</title>
		<link>http://code-spot.co.za/2009/04/28/generating-random-integers-with-arbitrary-probabilities/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=generating-random-integers-with-arbitrary-probabilities</link>
		<comments>http://code-spot.co.za/2009/04/28/generating-random-integers-with-arbitrary-probabilities/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 07:12:28 +0000</pubDate>
		<dc:creator>herman.tulleken</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[probability]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[random distribution]]></category>
		<category><![CDATA[random integer]]></category>
		<category><![CDATA[random number generation]]></category>

		<guid isPermaLink="false">http://code-spot.co.za/?p=582</guid>
		<description><![CDATA[
I finally laid my hands on Donald Knuth’s The Art of Computer Programming (what a wonderful set of books!), and found a neat algorithm for generating random integers 0, 1, 2, … , n – 1, with probabilities p_0, p_1, … , p_(n-1).
I have written about generating random numbers (floats) with arbitrary distributions for one [...]


Related posts:<ol><li><a href='http://code-spot.co.za/2009/04/15/generating-random-points-from-arbitrary-distributions-for-2d-and-up/' rel='bookmark' title='Permanent Link: Generating Random Points from Arbitrary Distributions for 2D and Up'>Generating Random Points from Arbitrary Distributions for 2D and Up</a></li>
<li><a href='http://code-spot.co.za/2008/09/21/generating-random-numbers-with-arbitrary-distributions/' rel='bookmark' title='Permanent Link: Generating Random Numbers with Arbitrary Distributions'>Generating Random Numbers with Arbitrary Distributions</a></li>
<li><a href='http://code-spot.co.za/2009/04/15/estimating-a-continuous-distribution-from-a-sample-set/' rel='bookmark' title='Permanent Link: Estimating a Continuous Distribution from a Sample Set'>Estimating a Continuous Distribution from a Sample Set</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img style="display: inline" title="header" src="http://code-spot.co.za/blog/wp-content/uploads/2009/04/header2.png" alt="header" width="500" height="332" /></p>
<p>I finally laid my hands on Donald Knuth’s <em><a href="http://www.amazon.com/Art-Computer-Programming-Volumes-Boxed/dp/0201485419">The Art of Computer Programming</a></em> (what a wonderful set of books!), and found a neat algorithm for generating random integers 0, 1, 2, … , n – 1, with probabilities p_0, p_1, … , p_(n-1).</p>
<p>I have written about generating random numbers (floats) with arbitrary distributions for <a href="http://code-spot.co.za/2008/09/21/generating-random-numbers-with-arbitrary-distributions/">one dimension</a> and <a href="http://code-spot.co.za/2009/04/15/generating-random-points-from-arbitrary-distributions-for-2d-and-up/">higher dimensions</a>, and indeed that method can be adapted for generating integers with specific probabilities. However, the method described below is much more concise, and efficient (I would guess) for this special case. Moreover, it is also easy to adapt it to generate floats for continuous distributions.</p>
<p><span id="more-582"></span></p>
<h2>Description of the Algorithm</h2>
<p>The basic idea of the algorithm is simple. We have two tables of length n that contains integers (K, L), and a third table that contains probabilities (P). The first table merely contains the integers 0 to n-1 (thus, we need not actually store it explicitly). The other two tables are computed before generation (more about that below).</p>
<p>To generate a random number, we generate a random integer (uniformly distributed between 0 and n-1 inclusive), and a random float (uniformly distributed between 0 and 1). The integer tells us which cells in the table to use. First we lookup the probability in P at that index. If the float is smaller than that value, we return the integer in K, otherwise we return the integer in L. (Note, the integer in K is exactly the random integer itself. Therefore, we do not actually have a table K – we simply use the random integer.)</p>
<p>Now this will only give the desired result if the tables have been constructed for this to work. Before looking at how these tables are generated, let us look at a very simple example. Suppose we want to generate 0, 1, 2, with probabilities 3/18, 7/18, 8/18. Can you see why the following tables will work?</p>
<table border="0" cellspacing="0" cellpadding="0" width="500">
<tbody>
<tr>
<td width="125" valign="top"></td>
<td width="125" valign="top">0</td>
<td width="125" valign="top">1</td>
<td width="125" valign="top">2</td>
</tr>
<tr>
<td width="125" valign="top">P</td>
<td width="125" valign="top">1/2</td>
<td width="125" valign="top">1</td>
<td width="125" valign="top">5/6</td>
</tr>
<tr>
<td width="125" valign="top">L</td>
<td width="125" valign="top">2</td>
<td width="125" valign="top">*</td>
<td width="125" valign="top">1</td>
</tr>
</tbody>
</table>
<p>There is only one way to generate 0: if the random integer is 0, and the random float is below 1/2. This will happen with probability 1/3 x 1/2 = 1/6 = 3/18.</p>
<p>There are two ways of generating 1:</p>
<ul>
<li>if the random integer is 1 (probability 1/3 = 6/18); or</li>
<li>if the random integer is 2, and the float is above 5/6 (probability 1/3 x 1/6 = 1/18).</li>
</ul>
<p>Adding these probabilities, we get 6/18 + 1/18 = 7/18.</p>
<p>There are also two ways to generate 2:</p>
<ul>
<li>if the random integer is 0 and the random float is above 1/2 (1/3 x 1/2 = 1/6 = 3/18); or</li>
<li>if the random integer is 2 and the random float is below 5/6 (1/3 x 5/6 = 5/18).</li>
</ul>
<p>Adding these probabilities, we get 3/18 + 5/18 = 8/18.</p>
<h2>Generating the tables</h2>
<p>Consider this problem:</p>
<ul>
<li>We have n<em> </em>squares that we want to paint.</li>
<li>We have five colours of paint, possibly different amounts of paint for each colour.</li>
<li>Each square has a border in one of the colours; no two borders are the same colour.</li>
<li>In total, there is just enough paint to cover the n squares <em>exactly</em>.</li>
<li>We want to paint each square with at most two colours, with one colour matching the border.</li>
</ul>
<p>To do this, we sort the paint buckets in ascending order. We paint the square that matches the first bucket with the first bucket, and whatever remains with the last bucket. The first bucket is empty (why?), and there might be some paint remaining in the last bucket. We now put this bucket back so that the buckets are sorted according to the new quantities of paint. The first square is completely covered (why?). Note that the painted square’s colour corresponds with the depleted colour.</p>
<p>The situation is now: we have n-1 unpainted squares, and n-1 colours of paint. This is the same problem as the initial problem, with one less square and one less colour. Therefore, we proceed as before, and repeat this process until all the squares have been painted and all the paint has been used.</p>
<p>To answer the two <em>why</em>’s above:</p>
<p>The first bucket is always empty, because the smallest bucket cannot cover more than one square. Since it is the smallest bucket, all other buckets must contain at least as much paint. Thus, we have n colours, and enough paint of each colour to paint more than one square. Thus, in total, we must have more paint than is required to paint n squares. But we said that we have <em>exactly</em> the right amount of paint needed, not more. Therefore, the smallest amount of paint cannot cover more than one square.</p>
<p>The first square is always covered completely, since the last bucket always contains enough paint for at least one square. If it did not, since it is the largest bucket, all other buckets will paint less than one square. In total, we would have n colours, each that can cover less than one square. Thus, all our paint will cover less than n squares: we do not have enough paint. But we said that we <em>do</em>, so this cannot be. Therefore, we must have enough paint in the last bucket to cover at least one square.</p>
<p>Below is an illustration of this process for three colours. Here we assume that 1 litre of paint covers 1 square. We have 1/3 = 3/6 litre of red, 7/6 litre of green, and 8/6 litre of cyan.</p>
<h3>Sort Paint</h3>
<p><img style="display: inline" title="step0" src="http://code-spot.co.za/blog/wp-content/uploads/2009/04/step0.png" alt="step0" width="500" height="92" /></p>
<h3>Paint from first bucket</h3>
<p><img style="display: inline" title="step1" src="http://code-spot.co.za/blog/wp-content/uploads/2009/04/step1.png" alt="step1" width="500" height="92" /></p>
<h3>Paint from last bucket</h3>
<p><img style="display: inline" title="step2" src="http://code-spot.co.za/blog/wp-content/uploads/2009/04/step2.png" alt="step2" width="500" height="92" /></p>
<h3>Sort Paint</h3>
<p><img style="display: inline" title="step3" src="http://code-spot.co.za/blog/wp-content/uploads/2009/04/step3.png" alt="step3" width="399" height="92" /></p>
<h3>Paint from first bucket</h3>
<p><img style="display: inline" title="step4" src="http://code-spot.co.za/blog/wp-content/uploads/2009/04/step4.png" alt="step4" width="396" height="92" /></p>
<h3>Paint from last bucket</h3>
<p><img style="display: inline" title="step5" src="http://code-spot.co.za/blog/wp-content/uploads/2009/04/step5.png" alt="step5" width="396" height="110" /></p>
<h3>Sort paint</h3>
<p><img style="display: inline" title="step6" src="http://code-spot.co.za/blog/wp-content/uploads/2009/04/step6.png" alt="step6" width="299" height="110" /></p>
<h3>Paint from first bucket</h3>
<p><img style="display: inline" title="step7" src="http://code-spot.co.za/blog/wp-content/uploads/2009/04/step7.png" alt="step7" width="291" height="110" /></p>
<p>As you can see, the solution above corresponds with the tables given in the example above. Indeed, the algorithm for calculating the tables is exactly the same as the paint algorithm:</p>
<ul>
<li>The n colours correspond to the n integers (from 0 to n-1) that we want to generate.</li>
<li>The initial amounts of paints corresponds with the (relative) probabilities that we want to generate each integer.</li>
<li>The amount of paint used to paint a square of the same border is the entry in table P – the probability of using the number associated with that cell (i.e., “the border”).</li>
<li>The other colour used to paint a square (if any) corresponds to the entry in table K.</li>
</ul>
<h2>A Small Optimisation in the Implementation</h2>
<h3>Generating two uniform random numbers for the price of one</h3>
<p>There is a trick to generate a random integer (0 &lt;= n &lt; k) and a random float (0 &lt;= x &lt; 1) from a single random float (0 &lt;= u &lt; 1) that is used in the implementation of this algorithm (see download below).</p>
<p>The trick is:</p>
<ul>
<li>n = floor (uk)</li>
<li>x = uk – n</li>
</ul>
<p>This assumes things about the random generator and the accuracy required. (I do not want to get into the details here).</p>
<h2>Download</h2>
<p>A python implementation of the above algorithm.</p>
<p><a href="http://www.code-spot.co.za/downloads/python/non_uniform_random_int.py">non_uniform_random_int.py</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcode-spot.co.za%2F2009%2F04%2F28%2Fgenerating-random-integers-with-arbitrary-probabilities%2F&amp;linkname=Generating%20Random%20Integers%20With%20Arbitrary%20Probabilities"><img src="http://code-spot.co.za/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>

<p>Related posts:<ol><li><a href='http://code-spot.co.za/2009/04/15/generating-random-points-from-arbitrary-distributions-for-2d-and-up/' rel='bookmark' title='Permanent Link: Generating Random Points from Arbitrary Distributions for 2D and Up'>Generating Random Points from Arbitrary Distributions for 2D and Up</a></li>
<li><a href='http://code-spot.co.za/2008/09/21/generating-random-numbers-with-arbitrary-distributions/' rel='bookmark' title='Permanent Link: Generating Random Numbers with Arbitrary Distributions'>Generating Random Numbers with Arbitrary Distributions</a></li>
<li><a href='http://code-spot.co.za/2009/04/15/estimating-a-continuous-distribution-from-a-sample-set/' rel='bookmark' title='Permanent Link: Estimating a Continuous Distribution from a Sample Set'>Estimating a Continuous Distribution from a Sample Set</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://code-spot.co.za/2009/04/28/generating-random-integers-with-arbitrary-probabilities/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Turn XSI Mod Tool into a  Level Editor for your XNA Games: Updated for XNA 3.0.</title>
		<link>http://code-spot.co.za/2009/04/08/how-to-turn-xsi-mod-tool-into-a-level-editor-for-your-xna-games-updated-for-xna-30/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=how-to-turn-xsi-mod-tool-into-a-level-editor-for-your-xna-games-updated-for-xna-30</link>
		<comments>http://code-spot.co.za/2009/04/08/how-to-turn-xsi-mod-tool-into-a-level-editor-for-your-xna-games-updated-for-xna-30/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 11:22:00 +0000</pubDate>
		<dc:creator>herman.tulleken</dc:creator>
				<category><![CDATA[Downloads]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[art pipeline]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[game tools]]></category>
		<category><![CDATA[level editor]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[XSI Mod Tool]]></category>

		<guid isPermaLink="false">http://code-spot.co.za/?p=457</guid>
		<description><![CDATA[
Last year I wrote a tutorial explaining how to use XSI Mod Tool as a level editor, specifically for XNA. Below is the same tutorial, updated for XNA 3.0. There are only a few minor changes:

You need not copy compiled assets from the batch file as before.
A section is included that describes how to use [...]


Related posts:<ol><li><a href='http://code-spot.co.za/2009/05/27/how-to-turn-xsi-mod-tool-into-a-level-editor-for-your-xna-games-example-updated-for-xna-30/' rel='bookmark' title='Permanent Link: How to Turn XSI Mod Tool into a Level Editor for your XNA Games: Example Updated for XNA 3.0.'>How to Turn XSI Mod Tool into a Level Editor for your XNA Games: Example Updated for XNA 3.0.</a></li>
<li><a href='http://code-spot.co.za/2008/09/14/google-app-engine-for-games/' rel='bookmark' title='Permanent Link: Google App Engine for Games'>Google App Engine for Games</a></li>
<li><a href='http://code-spot.co.za/2009/10/24/guerrilla-tool-development/' rel='bookmark' title='Permanent Link: Guerrilla Tool Development'>Guerrilla Tool Development</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-643" title="header" src="http://code-spot.co.za/blog/wp-content/uploads/2009/06/header.png" alt="header" width="500" height="371" /></p>
<p>Last year I wrote a <a href="http://www.luma.co.za/labs/2008/05/08/xsi-mod-tool-as-level-editor-for-xna-20/trackback/">tutorial</a> explaining how to use <a href="http://www.softimage.com/products/modtool/">XSI Mod Tool</a> as a level editor, specifically for <a href="http://creators.xna.com/en-GB/">XNA</a>. Below is the same tutorial, updated for XNA 3.0. There are only a few minor changes:</p>
<ul>
<li>You need not copy compiled assets from the batch file as before.</li>
<li>A section is included that describes how to use the content pipeline classes for easy reading of XML files (useful for level files, etc.).</li>
</ul>
<p>I also corrected quite a few typos.<br />
<span id="more-457"></span></p>
<h2>Link</h2>
<p>The article <a href="http://www.gamedev.net/reference/programming/features/XSIinXNA/">Integrating Your XNA Engine With XSI ModTool</a> is very relevant to this tutorial. Among other things, it explains how to make XNA shaders work in XSI.</p>
<h2>Download</h2>
<h3>PDF Tutorial</h3>
<p><a href="http://www.code-spot.co.za/downloads/tutorials/How to Turn XSI Mod Tool into a Level Editor for your XNA Games v3.pdf">How to Turn XSI Mod Tool into a Level Editor for your XNA Games v3.pdf (463 KB)</a></p>
<h3>Example</h3>
<p>(XSI Plug-in and C# code. Includes the tutorial PDF)</p>
<p><a href="http://www.code-spot.co.za/downloads/tutorials/XSIModToolLevelEditor3.zip">XSIModToolLevelEditor3.zip (5.2 MB)</a>.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcode-spot.co.za%2F2009%2F04%2F08%2Fhow-to-turn-xsi-mod-tool-into-a-level-editor-for-your-xna-games-updated-for-xna-30%2F&amp;linkname=How%20to%20Turn%20XSI%20Mod%20Tool%20into%20a%20%20Level%20Editor%20for%20your%20XNA%20Games%3A%20Updated%20for%20XNA%203.0."><img src="http://code-spot.co.za/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>

<p>Related posts:<ol><li><a href='http://code-spot.co.za/2009/05/27/how-to-turn-xsi-mod-tool-into-a-level-editor-for-your-xna-games-example-updated-for-xna-30/' rel='bookmark' title='Permanent Link: How to Turn XSI Mod Tool into a Level Editor for your XNA Games: Example Updated for XNA 3.0.'>How to Turn XSI Mod Tool into a Level Editor for your XNA Games: Example Updated for XNA 3.0.</a></li>
<li><a href='http://code-spot.co.za/2008/09/14/google-app-engine-for-games/' rel='bookmark' title='Permanent Link: Google App Engine for Games'>Google App Engine for Games</a></li>
<li><a href='http://code-spot.co.za/2009/10/24/guerrilla-tool-development/' rel='bookmark' title='Permanent Link: Guerrilla Tool Development'>Guerrilla Tool Development</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://code-spot.co.za/2009/04/08/how-to-turn-xsi-mod-tool-into-a-level-editor-for-your-xna-games-updated-for-xna-30/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Quadtrees</title>
		<link>http://code-spot.co.za/2008/11/15/quadtrees-2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=quadtrees-2</link>
		<comments>http://code-spot.co.za/2008/11/15/quadtrees-2/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 07:28:45 +0000</pubDate>
		<dc:creator>herman.tulleken</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Image Processing]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[computer graphics]]></category>
		<category><![CDATA[Dev.Mag]]></category>
		<category><![CDATA[image partitioning]]></category>
		<category><![CDATA[quadtree]]></category>
		<category><![CDATA[quadtrees]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[spatial partitioning]]></category>

		<guid isPermaLink="false">http://code-spot.co.za/?p=171</guid>
		<description><![CDATA[The code below implements some quadtree extensions, as discussed in another Dev.Mag tutorial about quadtrees (see Issue 27). The tutorial covers the following topics:

what to consider in choosing whether to use a quadtree or not;
tests to help you choose an appropriate threshold;
how to handle discrete data; and
some modifications to the basic algorithm.

Handling Discrete Data
When it [...]


Related posts:<ol><li><a href='http://code-spot.co.za/2008/10/06/quadtrees/' rel='bookmark' title='Permanent Link: Quadtrees'>Quadtrees</a></li>
<li><a href='http://code-spot.co.za/2010/06/15/region-quadtrees-in-c/' rel='bookmark' title='Permanent Link: Region Quadtrees in C++'>Region Quadtrees in C++</a></li>
<li><a href='http://code-spot.co.za/2008/11/07/a-simple-procedural-texture-algorithm/' rel='bookmark' title='Permanent Link: A Simple Procedural Texture Algorithm'>A Simple Procedural Texture Algorithm</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span lang="EN-GB">The code below implements some quadtree extensions, as discussed in another Dev.Mag tutorial about quadtrees (see <a href="http://devmag.org.za/uploads/DevMag_Issue27.zip">Issue 27</a>). The tutorial covers the following topics:</span></p>
<ul>
<li>what to consider in choosing whether to use a quadtree or not;</li>
<li>tests to help you choose an appropriate threshold;</li>
<li>how to handle discrete data; and</li>
<li>some modifications to the basic algorithm.</li>
</ul>
<h2><span lang="EN-GB">Handling Discrete Data</span></h2>
<p>When it comes to discrete data, the &#8220;average&#8221; of a number of pixels doesn&#8217;t make sense. However, we can give it meaning and still use it to get good approximations of the original data, as illustrated in the images below.</p>
<table border="0" cellspacing="0" cellpadding="2" width="451">
<tbody>
<tr>
<td width="135" valign="top"><img class="alignnone size-full wp-image-175" title="discrete_grid" src="http://code-spot.co.za/blog/wp-content/uploads/2008/11/discrete_grid.png" alt="" width="128" height="128" /></td>
<td width="312" valign="top">The original grid of discrete data. The grid contains integers from 0 to 4. Every integer is mapped to a colour in this image. (If this grid represented a tile map, every integer would be mapped to a different tile).</td>
</tr>
<tr>
<td width="135" valign="top"><img class="alignnone size-full wp-image-176" title="discrete_quadtree_normal_rounded" src="http://code-spot.co.za/blog/wp-content/uploads/2008/11/discrete_quadtree_normal_rounded.png" alt="" width="128" height="128" /></td>
<td width="312" valign="top">Here we allowed floating point numbers in the quadtree. Results of queries into the quadtree are rounded before mapping them to colours.</td>
</tr>
<tr>
<td width="135" valign="top"><img class="alignnone size-full wp-image-177" title="discrete_quadtree_normal_randomised" src="http://code-spot.co.za/blog/wp-content/uploads/2008/11/discrete_quadtree_normal_randomised.png" alt="" width="128" height="128" /></td>
<td width="312" valign="top">Here we used the floating point part of queries to bias a randomly selected integer. For example, a result of 1.25 will result in a 75% chance of yielding 2.</td>
</tr>
<tr>
<td width="135" valign="top"><img class="alignnone size-medium wp-image-178" title="discrete_quadtree_interpolated_rounded" src="http://code-spot.co.za/blog/wp-content/uploads/2008/11/discrete_quadtree_interpolated_rounded.png" alt="" width="128" height="128" /></td>
<td width="312" valign="top">Here we use a quadtree with interpolation. The result is rounded before it is mapped.</td>
</tr>
<tr>
<td width="135" valign="top"><img class="alignnone size-full wp-image-179" title="discrete_quadtree_interpolated_randomised" src="http://code-spot.co.za/blog/wp-content/uploads/2008/11/discrete_quadtree_interpolated_randomised.png" alt="" width="128" height="128" /></td>
<td width="312" valign="top">Here we use a quadtree with interpolation, and use the floating point part of the number to bias a randomly selected tile, as above.</td>
</tr>
</tbody>
</table>
<h2>Download</h2>
<h3>Python Implementation</h3>
<p>Download from: <a href="http://code-spot.co.za/python-image-code/">http://code-spot.co.za/python-image-code/</a> (See quadtree.py, quadtree_image.py, and quadtree_demo.py).</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcode-spot.co.za%2F2008%2F11%2F15%2Fquadtrees-2%2F&amp;linkname=Quadtrees"><img src="http://code-spot.co.za/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>

<p>Related posts:<ol><li><a href='http://code-spot.co.za/2008/10/06/quadtrees/' rel='bookmark' title='Permanent Link: Quadtrees'>Quadtrees</a></li>
<li><a href='http://code-spot.co.za/2010/06/15/region-quadtrees-in-c/' rel='bookmark' title='Permanent Link: Region Quadtrees in C++'>Region Quadtrees in C++</a></li>
<li><a href='http://code-spot.co.za/2008/11/07/a-simple-procedural-texture-algorithm/' rel='bookmark' title='Permanent Link: A Simple Procedural Texture Algorithm'>A Simple Procedural Texture Algorithm</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://code-spot.co.za/2008/11/15/quadtrees-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quadtrees</title>
		<link>http://code-spot.co.za/2008/10/06/quadtrees/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=quadtrees</link>
		<comments>http://code-spot.co.za/2008/10/06/quadtrees/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 22:52:02 +0000</pubDate>
		<dc:creator>herman.tulleken</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[computer graphics]]></category>
		<category><![CDATA[Dev.Mag]]></category>
		<category><![CDATA[image partitioning]]></category>
		<category><![CDATA[Image Processing]]></category>
		<category><![CDATA[quadtree]]></category>
		<category><![CDATA[quadtrees]]></category>
		<category><![CDATA[spatial partitioning]]></category>

		<guid isPermaLink="false">http://code-spot.co.za/?p=146</guid>
		<description><![CDATA[The quadtree is an important 2D data structure and forms the core of many spatial algorithms, including compression, collision detection, and stitching algorithms. Below you can download general purpose quadtree implementations in Java and Python.
The code accompanies the Quadtrees article in Dev.Mag Issue 26. The tutorial explains how the implement a quadtree that can be [...]


Related posts:<ol><li><a href='http://code-spot.co.za/2008/11/15/quadtrees-2/' rel='bookmark' title='Permanent Link: Quadtrees'>Quadtrees</a></li>
<li><a href='http://code-spot.co.za/2010/06/15/region-quadtrees-in-c/' rel='bookmark' title='Permanent Link: Region Quadtrees in C++'>Region Quadtrees in C++</a></li>
<li><a href='http://code-spot.co.za/2008/10/29/force-field-editor-v10/' rel='bookmark' title='Permanent Link: Force Field Editor v1.0'>Force Field Editor v1.0</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Quadtree">quadtree</a> is an important 2D data structure and forms the core of many spatial algorithms, including compression, collision detection, and stitching algorithms. Below you can download general purpose quadtree implementations in Java and Python.</p>
<p>The code accompanies the Quadtrees article in <a href="http://devmag.org.za/uploads/DevMag_Issue26.zip">Dev.Mag Issue 26</a>. The tutorial explains how the implement a quadtree that can be use to store 2D data efficiently, lists what considerations there are in real-world applications, and gives some debugging tips.</p>
<h3>Channels Compressed Simultaneously</h3>
<table border="0" cellspacing="0" cellpadding="2" width="478">
<tbody>
<tr>
<td width="295" valign="top"><img src="http://code-spot.co.za/blog/wp-content/uploads/2008/10/bar.png" alt="bar" width="240" height="240" /></td>
<td width="181" valign="top"><img src="http://code-spot.co.za/blog/wp-content/uploads/2008/10/bar-c.png" alt="bar_c" width="240" height="240" /></td>
</tr>
<tr>
<td width="307" valign="top">The original image (by <a href="http://www.flickr.com/photos/smcgee/">smcgee</a>).</td>
<td width="186" valign="top">The image after being loaded into a quadtree.</td>
</tr>
</tbody>
</table>
<p><span id="more-146"></span></p>
<h3>Channels Compressed Separately</h3>
<table border="0" cellspacing="0" cellpadding="2" width="491">
<tbody>
<tr>
<td width="249" valign="top"><img src="http://code-spot.co.za/blog/wp-content/uploads/2008/10/bar-c-0.png" alt="bar_c_0" width="240" height="240" /></td>
<td width="240" valign="top"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://code-spot.co.za/blog/wp-content/uploads/2008/10/bar-c-1.png" border="0" alt="bar_c_1" width="240" height="240" /></td>
</tr>
<tr>
<td width="249" valign="top">Red channel compressed.</td>
<td width="240" valign="top">Green channel compressed.</td>
</tr>
<tr>
<td width="249" valign="top"><img src="http://code-spot.co.za/blog/wp-content/uploads/2008/10/bar-c-2.png" alt="bar_c_2" width="240" height="240" /></td>
<td width="240" valign="top"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://code-spot.co.za/blog/wp-content/uploads/2008/10/bar-d.png" border="0" alt="bar_d" width="240" height="240" /></td>
</tr>
<tr>
<td width="249" valign="top">Blue channel compressed.</td>
<td width="240" valign="top">Compressed channels combined.</td>
</tr>
</tbody>
</table>
<h2></h2>
<h2>Downloads</h2>
<h3>Java Implementation</h3>
<p><a href="http://code-spot.co.za/downloads/quadtrees/quadtree_java_src.zip">quadtree_java_src.zip (25 KB)</a></p>
<h3>Python Implementation</h3>
<p><span>Download from: <a href="http://code-spot.co.za/python-image-code/">http://code-spot.co.za/python-image-code/</a>.<br />
</span></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcode-spot.co.za%2F2008%2F10%2F06%2Fquadtrees%2F&amp;linkname=Quadtrees"><img src="http://code-spot.co.za/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>

<p>Related posts:<ol><li><a href='http://code-spot.co.za/2008/11/15/quadtrees-2/' rel='bookmark' title='Permanent Link: Quadtrees'>Quadtrees</a></li>
<li><a href='http://code-spot.co.za/2010/06/15/region-quadtrees-in-c/' rel='bookmark' title='Permanent Link: Region Quadtrees in C++'>Region Quadtrees in C++</a></li>
<li><a href='http://code-spot.co.za/2008/10/29/force-field-editor-v10/' rel='bookmark' title='Permanent Link: Force Field Editor v1.0'>Force Field Editor v1.0</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://code-spot.co.za/2008/10/06/quadtrees/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
