Archive for the ‘Fun’ Category

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

Monday, January 4th, 2010

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.

Screenshot of Google's doodle in memory of Isaac Newton's birthday

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
    );
    google.rein&&
    google.rein.push(
      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;

Some words about the physics:

The simple algorithm used above reflects the constant acceleration during free fall accurately, supposed we’re neglecting the effect of air drag. IOW: height(t) = height(t=0) – 0.5*g*t^2 = h(t=0) – k*t^2.

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’s difficult to judge where the apple’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’t hurt the realism ;)

Symbolism:

It’s not without irony that Google shows a falling apple on its main page, as one reader points out on Mashable’s article about this animation ;)

Bash script of the day: New .de domains

Monday, October 19th, 2009

The one-liner:

for i in `echo {{a..z},{0..9}};echo {{a..z},{0..9}}{{a..z},{0..9}}`;do dict -d all -C ${i}de>/dev/null 2>&1; if [ "$?" == "0" ];then echo $i.de; fi done

or the equivalent multi-liner:

for i in `echo {{a..z},{0..9}};echo {{a..z},{0..9}}{{a..z},{0..9}}`;
  do
    dict -d all -C ${i}de >/dev/null 2>&1;
    if [ "$?" == "0" ]; then
      echo $i.de;
    fi
  done

No comment (*cough*)

(P.S. That’s for ASCII alphanumeric domains only)

Security through obscurity

Friday, February 15th, 2008

[..] bei Sportgrossveranstaltungen wie der UEFA EURO 2008™ ist es üblich, dass die Eintrittskarten erst wenige Wochen vor Turnierbeginn gedruckt und versandt werden. Dies ist im Sinne der Sicherheit und verkleinert das Risiko, dass die Tickets den Karteninhabern vor den Spielen abhanden kommen.[..]

Isn’t it nice how the “EURO 2008 SA” cares for us? ;)

Some practical advice for startups

Thursday, January 31st, 2008

“The Art of the Start” by Guy Kawasaki. Not the latest, but a courageous and entertaining presentation worthwhile watching.

Windows Vista or The Holy Grail of Usability

Wednesday, December 28th, 2005

Fine. After years (heck, even decades!) of staring into distorting, flickering, radiating and mirrorlike CRT screens we finally managed to banish those darn things from our desks and to use distortion-free, flicker-free, radiation-free, coated TFT screens instead. Time to put glares and reflections back into the GUI (just try to read the labels on the taskbar)! Hallelujah! ;)

(I bet Microsoft will get back to this once the dust has settled. Apple made a similar experience with Aqua’s transparency effect which was significantly reduced in later versions.)