## Quick analysis of the first animated Google doodle (“Isaac Newton’s apple”)

You probably noticed the funny animated logo on the Google search page today, January 4, 2010 (Isaac Newton’s birthday). It shows an apple falling from a tree reminding of the story that Isaac Newton was inspired to formulate his theory of gravitation by watching the fall of an apple from a tree. Animation of an apple falling from a tree in Google’s doodle in memory of Isaac Newton’s birthday

As this seems to be the first animated logo on Google’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’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).

Here’s a “reformatted” version of the JavaScript code for better readability, along with some explanations as inline comments (note that this “reformatted” code doesn’t work as-is due to the inserted comments):

```window.lol&&lol();
setTimeout( // execute this code once after a timeout of 2 seconds
function(){ // an anonymous function
var h=0, // initial horizontal offset (=0) of the apple's position
v=1, // initial vertical offset ('delta_height' = b(t+1)-b(t)) of the apple's position
f=document.getElementById('fall'), // get a reference to the apple image
i=setInterval( // execute repeatedly in intervals of 25 msec
function(){ // yet another anonymous function
if(f){ // execute if the apple image exists (a safety net)
var r=parseInt(f.style.right)+h, // add the horizontal offset (will move apple left for h>0)
b=parseInt(f.style.bottom)-v; // subtract the vertical offset (will move apple down for v>0)
f.style.right=r+'px'; // set the apple's new horizontal position
f.style.bottom=b+'px'; // set the apple's new vertical position
if(b>-210){ // the apple is above ground level (i.e. falling down or bouncing up)
v+=2 // increase 'delta_height' by 2 pixels per interval (accelerate the apple's free fall or slow down its rebound)
} else { // the apple hit the 'ground'
h=(v>9)?v*0.1:0; // bounce apple to the left at 10% of the last 'delta_height' if speedy, else don't move it horizontally
v*=(v>9)?-0.3:0 // bounce apple up at 30% of the last 'delta_height' if speedy, else don't move it vertically
}
}
}
,25 // the interval in msec
);
function(){
clearInterval(i); // disable the interval loop
h=0;v=1
}
)
},2000 // the timeout in msec
)
```

The apple’s initial position: position: relative; right: 248px; bottom: 46px;

The apple’s final position (after the rebound): position: relative; right: 286px; bottom: -210px;