<?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>Postpostmodern &#187; Geometry</title>
	<atom:link href="http://postpostmodern.com/tag/geometry/feed/" rel="self" type="application/rss+xml" />
	<link>http://postpostmodern.com</link>
	<description>Speaking of web development.</description>
	<lastBuildDate>Wed, 11 Jan 2012 00:21:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Wheels Keep on Spinning ‘Round</title>
		<link>http://postpostmodern.com/instructional/wheels-keep-on-spinning-round/</link>
		<comments>http://postpostmodern.com/instructional/wheels-keep-on-spinning-round/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 02:37:52 +0000</pubDate>
		<dc:creator>Jason Johnson</dc:creator>
				<category><![CDATA[Instructional]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Geometry]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://postpostmodern.com/?p=133</guid>
		<description><![CDATA[Spinning wheels means fun with geometry and ActionScript.]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I was working on a Flash animation for a client. Part of the animation involved an automobile driving over the client&#8217;s product as a display of structural integrity. That meant spinning wheels. That meant a little fun with geometry and ActionScript.</p>

<p>I threw together some ActionScript 2 to rotate the wheels based on the movement of the vehicle. Not sure if it&#8217;s perfect, but it seemed to work okay.</p>

<p>The ActionScript to calculate the rotation of each wheel depends on two formulae:</p>

<div style="margin: 20px 0;">
<p style="text-align: center;"><a href="/wp-content/media/pythagorean_theorem.png" class="img"><img src="/wp-content/media/pythagorean_theorem.png" alt="Pythagorean Theorem" title="Pythagorean Theorem" width="133" height="23" class="size-full wp-image-152" /></a></p>
<p style="text-align: center;"> -and- </p>
<p style="text-align: center;"><a href="http://en.wikipedia.org/wiki/Circumference" class="img"><img src="/wp-content/media/circumference.png" alt="Circumference" title="Circumference" width="133" height="23" class="size-full wp-image-154" /></a></p>
</div>

<p><em>Thanks, Pythagoras and Pi.</em> <strong><em>Thorasandpi.</em></strong></p>

<p>Here is the resulting ActionScript (attached to the wheel movie clip):</p>

<pre><code lang="javascript">
onEnterFrame = function() {

    // _parent is the vehicle clip. It's what's moving.
    // Figure out its x and y coordinates relative to last time.
    dx = _parent._x - this.lastx;
    dy = _parent._y - this.lasty;

    // The sum of the square of the two sides (horiz. and vert. change)
    sum = Math.pow(dx, 2) + Math.pow(dy, 2)

    // The hypotenuse
    dist = Math.sqrt(Math.abs(sum));

    // The direction is determined by whether dx is positive or negative
    dist = dx &lt; 0 ? -1 * dist : dist;

    _rotation = _rotation + ( (360 / (_width * Math.PI) ) * dist );

    // Store the vehicle's x and y coordinates for next time.
    this.lastx = _parent._x;
    this.lasty = _parent._y;

}
</code></pre>

<p>And here is an example:</p>

<div id="wheel" style="border: solid 2px #CECCC7; width: 490px; margin: 10px auto;">This Flash animation requires Javascript and Flash 9.</div>

<script type="text/javascript" charset="utf-8">
  var so_wheel = new SWFObject("/wp-content/media/wheeltest.swf", "flash-wheel", "490", "250",  "9", "#EFEDE6");
  so_wheel.write('wheel');
</script>

<p>I&#8217;m sure this is basic stuff for most ActionScript people, but I don&#8217;t work with it that often. Sometimes I wish I did. I&#8217;ve always loved geometry, and I know there are all kinds of fun puzzles like this when you combine animation with math. Ah well&#8230; just not enough hours in the day.</p>
]]></content:encoded>
			<wfw:commentRss>http://postpostmodern.com/instructional/wheels-keep-on-spinning-round/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

