<?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>SharonAndAdam.com &#187; Labs</title>
	<atom:link href="http://www.sharonandadam.com/category/labs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sharonandadam.com</link>
	<description>A Domestic Church in Central Texas</description>
	<lastBuildDate>Wed, 04 Jan 2012 16:38:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Realism with Randomness and Math</title>
		<link>http://www.sharonandadam.com/2007/09/01/realism-with-randomness-and-math/</link>
		<comments>http://www.sharonandadam.com/2007/09/01/realism-with-randomness-and-math/#comments</comments>
		<pubDate>Sun, 02 Sep 2007 03:22:23 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Labs]]></category>

		<guid isPermaLink="false">http://www.sharonandadam.com/?p=407</guid>
		<description><![CDATA[One thing I like about game development is the occasional challenge that comes along that requires you to clean out the cob webs in the ol&#8217; noggin and reach back for a few knowledge nuggets that you somehow managed to hold on to from your high school trigonometry class. Take for instance this little problem [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I like about game development is the occasional challenge that comes along that requires you to clean out the cob webs in the ol&#8217; noggin and reach back for a few knowledge nuggets that you somehow managed to hold on to from your high school trigonometry class. Take for instance this little problem in recreating <a href="http://www.sharonandadam.com/?page_id=405">Mancala</a>. While it would be simple to neatly order the stones in each of the bowls it would hardly lend itself to any bit of realism. What we need is randomness to create the effect they were tossed in the bowl. So, how can we do that? Observe.</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// Random radius.</span><br />
<span style="color: #000000; font-weight: bold;">var</span> new_r:<span style="color: #0066CC;">int</span> = <span style="color: #66cc66;">&#40;</span>_bowlShp.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> - s.<span style="color: #0066CC;">width</span>;<br />
new_r = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> new_r;<br />
<br />
<span style="color: #808080; font-style: italic;">// Random angle.</span><br />
<span style="color: #000000; font-weight: bold;">var</span> new_ang:<span style="color: #0066CC;">int</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">// Find the new x and y positions.</span><br />
<span style="color: #000000; font-weight: bold;">var</span> new_x:<span style="color: #0066CC;">int</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>new_ang<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> new_r;<br />
<span style="color: #000000; font-weight: bold;">var</span> new_y:<span style="color: #0066CC;">int</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>new_ang<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> new_r;<br />
<br />
<span style="color: #808080; font-style: italic;">// Move the stone.</span><br />
s.<span style="color: #006600;">x</span> = new_x;<br />
s.<span style="color: #006600;">y</span> = new_y;<br />
<br />
<span style="color: #808080; font-style: italic;">// Random rotation.</span><br />
s.<span style="color: #006600;">rotation</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">360</span>;</div></td></tr></tbody></table></div>
<p>Lines 2 and 3 take the radius of the bowl and subtracts the width of the stone. It then finds a random number between 0 and this shortened radius. Line 6 chooses a random angle. Lines 9 and 10 is where the fun comes in. Using our random values and a bit of <a href="http://en.wikipedia.org/wiki/Trigonometric_function#Right_triangle_definitions">right triangle trig</a>, new x and y coordinates are chosen for the stone. We finish it off by moving the stone to the new location and giving it a little spin.</p>
<p>Essentially you can think of this whole process as first placing the stone in the center of the bowl, move it out a random distance from the center without falling outside of the bowl, and swing it around from the center at a random angle.</p>
<p><img src='http://www.sharonandadam.com/wp-content/uploads/2007/06/mancala_random_stone.gif' alt='Mancala game stones in bowls' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sharonandadam.com/2007/09/01/realism-with-randomness-and-math/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Where are the Apostles?: An Experiment with Google Maps</title>
		<link>http://www.sharonandadam.com/2006/07/20/where-are-the-apostles-an-experiment-with-google-maps/</link>
		<comments>http://www.sharonandadam.com/2006/07/20/where-are-the-apostles-an-experiment-with-google-maps/#comments</comments>
		<pubDate>Thu, 20 Jul 2006 06:01:55 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Labs]]></category>

		<guid isPermaLink="false">http://www.sharonandadam.com/?p=196</guid>
		<description><![CDATA[I&#8217;ve been working on this experiment off and on, but I&#8217;m probably at the point where I could share it. This little test satisfies two of my curiosities: Where are the remains of Christ&#8217;s apostles? How does the Google Maps API work? Well, here are the answers. I was quite impressed with the level of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on this experiment off and on, but I&#8217;m probably at the point where I could share it.  This little test satisfies two of my curiosities:</p>
<ol>
<li>Where are the remains of Christ&#8217;s apostles?</li>
<li>How does the <a href="http://www.google.com/apis/maps/">Google Maps API</a> work?</li>
</ol>
<p>Well, <a href="http://www.sharonandadam.com/labs/google_maps/apostles.htm">here are the answers</a>. I was quite impressed with the level of detail these maps present at an international scale enabling you to locate sites with pinpoint accuracy (check out Peter&#8217;s for example). Click on each individual marker for further information.</p>
<p>You can tell I have a few gaps missing, so if you&#8217;re up to the challenge send me on some coordinates. I find <a href="http://en.wikipedia.org/wiki/Main_Page">Wikipedia</a> to be the most resourceful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sharonandadam.com/2006/07/20/where-are-the-apostles-an-experiment-with-google-maps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

