<?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>Rabbit Creative &#187; gosu</title>
	<atom:link href="http://www.rabbitcreative.com/category/gosu/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rabbitcreative.com</link>
	<description>ruby, rails, objects and &#60;del&#62;politics&#60;/del&#62; markets</description>
	<lastBuildDate>Tue, 20 Apr 2010 17:15:51 +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>Graphics programming with Math. Programming a graphical clock. Part 1.</title>
		<link>http://www.rabbitcreative.com/2010/02/17/graphics-programming-with-math-programming-a-graphical-clock-part-1/</link>
		<comments>http://www.rabbitcreative.com/2010/02/17/graphics-programming-with-math-programming-a-graphical-clock-part-1/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 19:57:39 +0000</pubDate>
		<dc:creator>Rabbit</dc:creator>
				<category><![CDATA[game programming]]></category>
		<category><![CDATA[gosu]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.rabbitcreative.com/?p=371</guid>
		<description><![CDATA[We’re going to use Ruby, Gosu and some trigonometry to create a graphical clock. Specifically, we will be programming the behavior and graphics for the second, minute and hour hands of an analog clock; the face of the clock will be represented by a simple graphic file (a .png, in our case). Following this exercise [...]]]></description>
			<content:encoded><![CDATA[<p>We’re going to use Ruby, Gosu and some trigonometry to create a graphical clock. Specifically, we will be programming the behavior and graphics for the second, minute and hour hands of an analog clock; the face of the clock will be represented by a simple graphic file (a .png, in our case). Following this exercise from start to finish should grant you a beginner’s understanding of some basic trigonometric concepts.</p>
<p>As we talk and learn about trigonometry, keep one thing in mind: trigonometry is easy. In fact, I&#8217;d argue that the portion of trigonometry that we will cover in this article can be understood intuitively. And soon you shall.</p>
<p>We begin our task by considering the following standard Cartesian coordinate system.</p>
<p><img src="http://www.rabbitcreative.com/wp-content/uploads/2010/02/diagram-1.png" alt="" title="diagram-1" width="620" height="492" class="alignnone size-full wp-image-372" /></p>
<p>Place a circle with radius 1 at the center of the graph, such that the circle’s center is aligned with the origin of the coordinate plane. This circle is called the unit circle.</p>
<p><img src="http://www.rabbitcreative.com/wp-content/uploads/2010/02/diagram-2.png" alt="" title="diagram-2" width="620" height="492" class="alignnone size-full wp-image-375" /></p>
<p>Let&#8217;s see this circle in greater detail by zooming in on it.</p>
<p><img src="http://www.rabbitcreative.com/wp-content/uploads/2010/02/diagram-3.png" alt="" title="diagram-3" width="620" height="492" class="alignnone size-full wp-image-376" /></p>
<p>The line that we draw is called the terminal side of our angle. All angles are measure from their initial side (the x-axis) to their terminal side. The angle created in the diagram below is 45 degrees. The green line below intersects the circumference of our circle at a specific point on the coordinate system.</p>
<p><img src="http://www.rabbitcreative.com/wp-content/uploads/2010/02/diagram-4.png" alt="" title="diagram-4" width="620" height="492" class="alignnone size-full wp-image-377" /></p>
<p>This is true for any line drawn from the origin through any position on the circumference of the circle, as illustrated in the next diagram.</p>
<p><img src="http://www.rabbitcreative.com/wp-content/uploads/2010/02/diagram-4.1.png" alt="" title="diagram-4.1" width="620" height="492" class="alignnone size-full wp-image-378" /></p>
<p>The upshot of all this is that, no matter the angle, given a point along the circumference of a unit circle, we can construct a right triangle, like so.</p>
<p><img src="http://www.rabbitcreative.com/wp-content/uploads/2010/02/diagram-5.png" alt="" title="diagram-5" width="620" height="492" class="alignnone size-full wp-image-379" /></p>
<p>The terminal side of our angle forms the hypotenuse of our right triangle, and is always equal to 1, as mentioned earlier. The point at which our line crosses the circumference of the circle actually gives us the lengths of the remaining two legs. The x-value of our point equals the length of the leg that lies along the x-axis (&#8220;side x&#8221;). The y-value of our point corresponds to the length of the leg that lies parallel to the y-axis (&#8216;&#8221;side y&#8221;).</p>
<p><img src="http://www.rabbitcreative.com/wp-content/uploads/2010/02/diagram-6.png" alt="" title="diagram-6" width="620" height="492" class="alignnone size-full wp-image-380" /></p>
<p>Armed with the lengths of each leg of our triangle, it’s time to learn about two trigonometrical functions, sine and cosine. These functions will allow us to extract the information necessary to draw objects moving at any angle we want. Both functions take as their argument an angle, but in practice this can be any real number.</p>
<p>Side x of the triangle indicates how much horizontal distance is composed within the hypotenuse. This value is given to us by the cosine function, abbreviated in algebra as “cos”. The y side of the triangle indicates how much vertical distance is composed within the hypotenuse. This value is given to us by the sine function, abbreviated in algebra as “sin”. Together, these values tell us the amount of vertical movement needed and the amount of horizontal movement needed to move at the desired angle for 1 unit. “1 unit” in our case is “1 pixel”.</p>
<p><img src="http://www.rabbitcreative.com/wp-content/uploads/2010/02/diagram-7.png" alt="" title="diagram-7" width="620" height="492" class="alignnone size-full wp-image-381" /></p>
<p>The sine and cosine functions return numbers between -1 and 1, inclusive. Because of this, using sine and cosine gives us the core of what matters in all this — the direction of the angle without any significant distance (we can&#8217;t well represent 77% of one pixel!). Once we have our direction, we can multiply the factors given to us by sine and cosine functions to draw lines.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-9576110003123309";
/* 468x60, created 2/17/10 */
google_ad_slot = "5134060023";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rabbitcreative.com/2010/02/17/graphics-programming-with-math-programming-a-graphical-clock-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retris lives. Gosu rocks. Object thinking prevails.</title>
		<link>http://www.rabbitcreative.com/2008/06/01/retris-lives-gosu-rocks-object-thinking-prevails/</link>
		<comments>http://www.rabbitcreative.com/2008/06/01/retris-lives-gosu-rocks-object-thinking-prevails/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 07:40:02 +0000</pubDate>
		<dc:creator>Rabbit</dc:creator>
				<category><![CDATA[game programming]]></category>
		<category><![CDATA[gosu]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.rabbitcreative.com/2008/06/01/retris-lives-gosu-rocks-object-thinking-prevails/</guid>
		<description><![CDATA[I pushed the first version of Retris to github about ten minutes ago. It feels pretty good.


Retris screen cast (large version)
Github repo: http://github.com/angryrabbit/retris/tree/master
gosu library

There are quite a few missing features, but it&#8217;s playable. There are probably a small handful of bugs. I&#8217;m only aware of one or two. Both are documented in the readme.
I want [...]]]></description>
			<content:encoded><![CDATA[<p>I pushed the first version of Retris to github about ten minutes ago. It feels pretty good.</p>
<p><object type="application/x-shockwave-flash" width="398" height="400" data="http://www.flickr.com/apps/video/stewart.swf?v=49235" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&amp;photo_secret=0eee4a0757&amp;photo_id=2540254537"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=49235"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=49235" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&amp;photo_secret=0eee4a0757&amp;photo_id=2540254537" height="400" width="398"></embed></object></p>
<ul>
<li><a href="http://rabbitcreative.com/retris.mov">Retris screen cast (large version)</a></li>
<li>Github repo: <a href="http://github.com/angryrabbit/retris/tree/master">http://github.com/angryrabbit/retris/tree/master</a></li>
<li><a href="http://code.google.com/p/gosu/">gosu library</a></li>
</ul>
<p>There are quite a few missing features, but it&#8217;s playable. There are probably a small handful of bugs. I&#8217;m only aware of one or two. Both are documented in the readme.</p>
<p>I want to thank Julian Raschke and the other gosu contributors. I love Ruby and it&#8217;s awesome to be able to concentrate on my game rather than dick around with low-level details.</p>
<p>As happy as I am that I&#8217;ve &#8220;finally made a game&#8221;, I have to confess, I don&#8217;t care for Tetris. I suck at it, too. I wrote it because I read in an old game programming book that Tetris is a good first game.</p>
<p>So what&#8217;s next? Well, I have a few things I want to finish up. As <a href="http://www.fastgraph.com/makegames/sidescroller/">Diana Gruber</a> says, &#8220;the last 10% of the game takes as long as the first 90%&#8221;. Or something like that.</p>
<p>At the very least I need to instate loss conditions. Currently, overflowing the grid simply causes the game to go on a freak rampage, creating shape after shape in the grid&#8217;s origin. It doesn&#8217;t crash, but you can&#8217;t do anything but exit when you reach that point.</p>
<p>I&#8217;d also like to put in a menu, pause feature, difficulty levels and a menu.</p>
<p>When those things are done I&#8217;ll start to think about another game.</p>
<p>I&#8217;d like to point out that I ditched the idea of using a matrix (nested arrays, actually) to model either the grid or shape objects. I made this move for several reasons:</p>
<ul>
<li>Nested arrays require some math</li>
<li>I can&#8217;t ask a nested array meaningful questions</li>
<li>Previous attempts at using nested arrays fell short for me</li>
<li>It doesn&#8217;t feel very object oriented</li>
</ul>
<p>There&#8217;s no doubt in my mind nested arrays are a viable implementation to Tetris, but personally, I prefer objects.</p>
<p>True, I could have wrapped the nested arrays into an object and queried that, but it&#8217;s just not decomposed enough for my tastes. My landscape (objectscape?) includes Grid, GridLocation, Cursor, Shape, Location and Block objects to orchestrate the interactions required of Tetris. (There are a few more objects, but the ones I listed are my solution to NOT using nested arrays.)</p>
<p>Similar to my <a href="http://www.rabbitcreative.com/2007/05/11/object-oriented-solution-to-the-tower-of-hanoi/">object-oriented solution to the Tower of Hanoi</a>, (portions of) my code read like a story. Stories are easier to grasp than mathematics. At least for now they are. I&#8217;ve decided to go back to school primarily for math.</p>
<p>I imagine though, that even as I become more proficient with math, the &#8220;stage&#8221; my code lives in, and the messages passed back and forth, will remain largely true to my current style.</p>
<p>In fact, if object-oriented programming is really all it&#8217;s cracked up to be, my style will only get tighter and more nuanced; only the implementations will change.</p>
<p>Five years from now I just might use an (actual!) matrix object to handle the implementation for Tetris interactions. But, my guess (indeed, my hope) is that the act of sending messages to create a story will remain in force.</p>
<p>Here&#8217;s to the human mind.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rabbitcreative.com/2008/06/01/retris-lives-gosu-rocks-object-thinking-prevails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://rabbitcreative.com/retris.mov" length="4420351" type="video/quicktime" />
		</item>
	</channel>
</rss>
