<?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>numlock.ch - a changelog by Daniel Mettler &#187; animated Doodle</title>
	<atom:link href="http://www.numlock.ch/news/tag/animated-doodle/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.numlock.ch/news</link>
	<description>Make a diff!</description>
	<lastBuildDate>Tue, 01 Nov 2011 16:19:05 +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>Quick analysis of the first animated Google doodle (&#8220;Isaac Newton&#8217;s apple&#8221;)</title>
		<link>http://www.numlock.ch/news/it/quick-analysis-of-the-first-animated-google-doodle-isaac-newton-apple/</link>
		<comments>http://www.numlock.ch/news/it/quick-analysis-of-the-first-animated-google-doodle-isaac-newton-apple/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 23:26:50 +0000</pubDate>
		<dc:creator>Daniel Mettler</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[analysis]]></category>
		<category><![CDATA[animated Doodle]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Doodle]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Isaac Newton]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.numlock.ch/news/?p=806</guid>
		<description><![CDATA[You probably noticed the funny animated logo on the Google search page today, January 4, 2010 (Isaac Newton&#8217;s birthday). It shows an apple falling from a tree reminding of the story that Isaac Newton was inspired to formulate his theory &#8230; <a href="http://www.numlock.ch/news/it/quick-analysis-of-the-first-animated-google-doodle-isaac-newton-apple/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You probably noticed the funny animated logo on the <a href="http://www.google.com/" target="_blank">Google search page</a> today, January 4, 2010 (Isaac Newton&#8217;s birthday). It shows an apple falling from a tree reminding of the story that <a href="http://en.wikipedia.org/wiki/Isaac_Newton" target="_blank">Isaac Newton</a> <a href="http://en.wikipedia.org/wiki/Isaac_Newton#Newton.27s_apple" target="_blank">was inspired to formulate his theory of gravitation by watching the fall of an apple from a tree</a>.</p>
<p><a href="http://www.numlock.ch/news/wp-content/uploads/2010/01/google_search_page_apple_isaac_newton.png"><img class="aligncenter size-medium wp-image-809" title="Screenshot of Google's doodle in memory of Isaac Newton's birthday" src="http://www.numlock.ch/news/wp-content/uploads/2010/01/google_search_page_apple_isaac_newton-300x252.png" alt="Screenshot of Google's doodle in memory of Isaac Newton's birthday" width="300" height="252" /></a></p>
<p><a href="http://www.numlock.ch/news/wp-content/uploads/2010/01/2010-01-05_0016.swf">Animation of an apple falling from a tree in Google&#8217;s doodle in memory of Isaac Newton&#8217;s birthday</a></p>
<p>As this seems to be the first animated logo on Google&#8217;s home page ever, I wondered how it was implemented (in particular, how well the code simulates gravity on earth). Short explanation: As expected, it&#8217;s a mix of JavaScript code and CSS formatting. And not surprising either, the algorithm used is an acceptable simulation of gravity on earth (in vacuum).</p>
<p>Here&#8217;s a &#8220;reformatted&#8221; version of the JavaScript code for better readability, along with some explanations as <span style="color: #008000;">inline comments</span> (note that this &#8220;reformatted&#8221; code doesn&#8217;t work as-is due to the inserted comments):</p>
<blockquote>
<pre>window.lol&amp;&amp;lol();
setTimeout( <span style="color: #008000;">// execute this code once after a timeout of 2 seconds</span>
  function(){ <span style="color: #008000;">// an anonymous function</span>
    var h=0, <span style="color: #008000;">// initial horizontal offset (=0) of the apple's position</span>
    v=1, <span style="color: #008000;">// initial vertical offset ('delta_height' = b(t+1)-b(t)) of the apple's position</span>
    f=document.getElementById('fall'), <span style="color: #008000;">// get a reference to the apple image</span>
    i=setInterval( <span style="color: #008000;">// execute repeatedly in intervals of 25 msec</span>
      function(){ <span style="color: #008000;">// yet another anonymous function</span>
        if(f){ <span style="color: #008000;">// execute if the apple image exists</span><span style="color: #008000;"> (a safety net)</span>
          var r=parseInt(f.style.right)+h,<span style="color: #008000;"> // add the horizontal offset (will move apple left for h&gt;0)</span>
          b=parseInt(f.style.bottom)-v;<span style="color: #008000;"> // subtract the vertical offset (will move apple down for v&gt;0)</span>
          f.style.right=r+'px';<span style="color: #008000;"> // set the apple's new horizontal position</span>
          f.style.bottom=b+'px';<span style="color: #008000;"> // set the apple's new vertical position</span>
          if(b&gt;-210){ <span style="color: #008000;">// the apple is above ground level (i.e. falling down or bouncing up)</span>
            v+=2 <span style="color: #008000;">// increase 'delta_height' by 2 pixels per interval (accelerate the apple's free fall or slow down its rebound)</span>
          } else { <span style="color: #008000;">// the apple hit the 'ground'</span>
            h=(v&gt;9)?v*0.1:0; <span style="color: #008000;">// bounce apple to the left at 10% of the last 'delta_height' if speedy, else don't move it horizontally</span>
            v*=(v&gt;9)?-0.3:0 <span style="color: #008000;">// bounce apple up at 30% of the last 'delta_height' if speedy, else don't move it vertically</span>
          }
        }
      }
      ,25 <span style="color: #008000;">// the interval in msec</span>
    );
    google.rein&amp;&amp;
    google.rein.push(
      function(){
        clearInterval(i); <span style="color: #008000;">// disable the interval loop</span>
        h=0;v=1
      }
    )
  },2000 <span style="color: #008000;">// the timeout in msec</span>
)
</pre>
</blockquote>
<p>The apple&#8217;s initial position:<em> position: relative; right: 248px; bottom: 46px;</em></p>
<p>The apple&#8217;s final position (after the rebound):<em> position: relative; right: 286px; bottom: -210px;</em></p>
<p><strong>Some words about the physics:</strong></p>
<p>The simple algorithm used above reflects the constant <a href="http://en.wikipedia.org/wiki/Free_fall" target="_blank">acceleration during free fall</a> accurately, supposed we&#8217;re neglecting the effect of air drag. IOW: height(t) = height(t=0) &#8211; 0.5*g*t^2 = h(t=0) &#8211; k*t^2.</p>
<p>The rebound of the apple is less realistic though. I doubt an apple would rebound that high and the fact that it rebounds to the left seems to be rather arbitrary (given the image it&#8217;s difficult to judge where the apple&#8217;s center of gravity would be compared to the contact area when touching the ground on impact). Further, simulating rotational forces on the apple wouldn&#8217;t hurt the realism ;)</p>
<p><strong>Symbolism:</strong></p>
<p>It&#8217;s not without irony that Google shows a falling <a href="http://www.apple.com/" target="_blank">apple</a> on its main page, as one reader points out on <a href="http://mashable.com/2010/01/04/google-newton-animated-logo/" target="_blank">Mashable&#8217;s article about this animation</a> ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.numlock.ch/news/it/quick-analysis-of-the-first-animated-google-doodle-isaac-newton-apple/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

