<?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>natewm.com &#187; random</title>
	<atom:link href="http://natewm.com/blog/tag/random/feed/" rel="self" type="application/rss+xml" />
	<link>http://natewm.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 26 Jul 2010 19:43:25 +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>Simple Recursive Maze</title>
		<link>http://natewm.com/blog/2010/07/26/simple-recursive-maze/</link>
		<comments>http://natewm.com/blog/2010/07/26/simple-recursive-maze/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 19:39:51 +0000</pubDate>
		<dc:creator>Nate</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[maze]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[py]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://natewm.com/blog/?p=155</guid>
		<description><![CDATA[Here is a simple recursive maze generator I wrote to help a friend learn a little more about how recursion works. I figured I&#8217;d post it here as well. #! /usr/bin/env python import random # Width and height of maze needs to be an even number because of walls WIDTH = 60 HEIGHT = 20 [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple recursive maze generator I wrote to help a friend learn a little more about how recursion works.  I figured I&#8217;d post it here as well.</p>
<pre class="brush:python">#! /usr/bin/env python

import random

# Width and height of maze needs to be an even number because of walls
WIDTH = 60
HEIGHT = 20

# The change in x and y for all four directions
UP = (0, -1)
DOWN = (0, 1)
LEFT = (-1, 0)
RIGHT = (1, 0)

def recursive_maze(maze, x=0, y=0, dirx=0, diry=0):
	# Check if current position is inside maze boundry
    if 0 &lt;= y &lt; len(maze):
        if 0 &lt;= x &lt; len(maze[0]):
			# Check if this position can have a new hallway going to it
            if maze[y][x] == "#":
				# Make this position into a hallway
                maze[y][x] = " "

                # Connect this position with previous position
                maze[y-diry][x-dirx] = " "

                # Create direction list and randomize it's order
                directions = [UP, DOWN, LEFT, RIGHT]
                random.shuffle(directions)

                # Follows each direction when the callstack returns here
                for dx, dy in directions:
					# Go down this current direction
                    recursive_maze(maze, x + dx*2, y + dy*2, dx, dy)

def draw_maze(maze):
	# Draw top wall
    print "#" * (len(maze[0])+1)
    # Draw each line with left wall added in
    for line in maze:
        print "#" + "".join(line)

# Initialize the maze as am array of arrays filled with wall spaces
maze = [["#" for j in xrange(WIDTH)] for i in xrange(HEIGHT)]

# Start making the maze
recursive_maze(maze)

# Finally, draw it
draw_maze(maze)</pre>
<p>The output of this program will look similar to this:</p>
<pre class="brush:text">#############################################################
# #       #     #           #           #               #   #
# ##### # # ### # ######### ####### ### # ########### # # ###
#   #   # #   # #   #     #   #   # # # # #           # #   #
### # ### ### # ### ### # ### # # # # # ### ########### ### #
#   #   #     #   # #   # #   # #   # #   # #     #   # #   #
# ##### ######### # # ### # ### ##### ### # # ### # # # # ###
# #     # #     #   #   # # #   #     #   #     # # # # #   #
# # ##### # # ######### ### # ### ### # ######### # ### ### #
# # #       #         #   #   #     # #         # # #   #   #
# # ### ########### # ### ######### ########### # # # ### ###
# #   #   #       # #     #         #           # # # #     #
# # # ### # ####### ####### ### ### # ########### # # # ### #
# # # # #   #       #     #   #   # # #           # # # #   #
# # # # # ### ##### # ### ### ### ### ########### # # ### # #
# # # #   #   #     # # #     #   #   #         # #   #   # #
# ### # ### ##### ### # ####### ### ### ####### # # ### ### #
# #   # # # #   # #   #       #     #   #     #   #     #   #
# # ### # # # # ### ####### # ######### # ### ########### ###
#   #     #   #             #           #   #               #
#############################################################</pre>
]]></content:encoded>
			<wfw:commentRss>http://natewm.com/blog/2010/07/26/simple-recursive-maze/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random Neighborhood Generator</title>
		<link>http://natewm.com/blog/2009/01/20/random-neighborhood-generator/</link>
		<comments>http://natewm.com/blog/2009/01/20/random-neighborhood-generator/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 22:18:43 +0000</pubDate>
		<dc:creator>Nate</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[neighborhood]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://natewm.com/blog/?p=86</guid>
		<description><![CDATA[I was wondering how visually interesting a randomly generated neighborhood could be a made by using simple binary subdivision.  Basically the algorithm starts with a square, cuts it in half, cuts those halves in half, and so on to produce streets and plots of land. It is in no way how a real neighborhood would [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_87" class="wp-caption aligncenter" style="width: 610px"><img class="size-full wp-image-87" title="neighborhood" src="http://natewm.com/blog/../media/blog/2009/01/neighborhood.gif" alt="Random Neighborhood Generator" width="600" height="257" /><p class="wp-caption-text">Random Neighborhood Generator</p></div>
<p>I was wondering how visually interesting a randomly generated neighborhood could be a made by using simple binary subdivision.  Basically the algorithm starts with a square, cuts it in half, cuts those halves in half, and so on to produce streets and plots of land.</p>
<p>It is in no way how a real neighborhood would be laid out, but for such simplicity I am rather satisfied with the results.  Such a system could randomly produce results that are visually interesting enough for possibly a small, simple flying or driving based game &#8212; such as having to rush a firetruck to burning homes, for example.</p>
<p>Here is the source code: <a title="Random Neighborhood Generator" href="http://www.natewm.com/media/software/experiments/python/neighborhood.py">neighborhood.py</a></p>
]]></content:encoded>
			<wfw:commentRss>http://natewm.com/blog/2009/01/20/random-neighborhood-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
