Activate your free membership today | Log-in

Wednesday, September 17th, 2008

iPhone Web App: Spin the Bottle

Category: Mobile, iPhone

Tomi Mickelsson has created a fun iPhone Web App called Spin the Bottle. You know, a Web app, not one that has to get into the Apple store.

You can check it out on the iPhone/Touch/emulator and you will see how Tomi uses the iPhone specific APIs, such as:

JAVASCRIPT:
  1.  
  2. function startTouch() {
  3.     setTimeout(hideURLbar, 100);
  4.  
  5.     document.body.ontouchstart = function(e) {
  6.         oldangle1 = 0; oldangle2 = 0; oldangle3 = 0;
  7.         //spinout();
  8.         cancelspin();
  9.     }
  10.  
  11.     document.body.ontouchmove = function(e) {
  12.         // prevent window scrolling!
  13.         e.preventDefault();
  14.  
  15.         if (timer_rot != 0)
  16.             return;
  17.  
  18.         var touch = e.touches[0]; // finger 1
  19.         var dx = centerx - touch.pageX;
  20.         var dy = centery - touch.pageY;
  21.         var angle = Math.atan2(dy, dx);
  22.  
  23.         oldangle3 = angle;
  24.         oldangle1 = oldangle2;
  25.         oldangle2 = oldangle3;
  26.  
  27.         var val = "rotateZ(" + angle + "rad)";
  28.         bottle.style.webkitTransform = val;
  29.         shadow.style.webkitTransform = val;
  30.         rot = angle;
  31.         //cancelspin();
  32.     }
  33.     document.body.ontouchend = function(e){
  34.         if (timer_rot == 0) {
  35.             var val = ((oldangle2 - oldangle1) + (oldangle3 - oldangle2)) / 2;
  36.             val /= 3;
  37.             if (val == 0.0)
  38.                 val = rand(0.3)+0.2;
  39.             else if (Math.abs(val) <0.3)
  40.                 val *= 3;
  41.  
  42.             //cancelspin();
  43.             startanim(val);
  44.         }
  45.     }
  46. }
  47. // remove our touch handlers
  48. function stopTouch() {
  49.     document.body.ontouchstart = null;
  50.     document.body.ontouchmove = null;
  51.     document.body.ontouchend = null;
  52. }
  53.  

Posted by Dion Almaer at 8:24 am

++---
2.9 rating from 16 votes

3 Comments »

Comments feed TrackBack URI

I’m using rss from feedburner to read Ajaxian and in feed, the second link is changed to: http://feeds.feedburner.com/www.idean.com/iphone/spin that point to a different website, http://feeds.feedburner.com/www Please fix the problem (or maybe is a bug from feedburner).

Thanks

Comment by dt — September 17, 2008

It appears that the problem is in the article itself.

Comment by epascarello — September 17, 2008

Maybe this site is interesting for iPhone WebApp Developers too:

http://www.big5apps.com

Comment by perenzo — September 18, 2008

Leave a comment

You must be logged in to post a comment.