Sunday, May 03, 2009

Randomness, Throbbers and the <canvas> tag

[caveat - if you're reading this in a feedreader, I have no idea how the iframes below will work. If they do, then great. If not, then maybe click through to the site...]

As I've been on holiday for the last week, I thought I'd take the opportunity to learn a little bit about some of the new funky stuff that's in HTML 5. The Google mobile team just released an awesome new version of gmail for iPhone and Android that relies heavily on HTML 5 and it seems that there are some pretty cool things you can do with it.

In an amusing twist, the fact that iPhone and Android browsers are based on WebKit means that for once, (smart-phone) mobile developers can build on top of the new standard with more confidence before their desktop cousins (assuming of course they don't need their sites to work on a Blackberry). On the desktop, Safari and Chrome are built on WebKit, so they are fine, and Firefox is gradually introducing all of the features through each new build to Gekko. As the standard is still evoling, no browser has comprehensive support, but as far as I can tell, WebKit is most in tune (get the nightly build for the latest bells and whistles), with Firefox and Opera not far behind and Internet Explorer (as ever) a distant fourth (IE 7 and before have none of these features, IE 8 may have some but I'm on a Mac and so haven't tested it...)

The three areas of HTML 5 that I am most interested in exploring are the <canvas> tag, the Application Cache and the Web Storage API (mainly because these are the ones that my colleagues blogged about and I caught the bug). So far I've spent a couple of days playing with <canvas> and have to say I've enjoyed it immensely. Posts on the App Cache and Storage capabilities will follow just as soon as I'm finished drawing (I promise...)

So, what is <canvas>? Well the wikipedia article has some good history, but in essence <canvas> lets you define an area of the DOM that you can subsequently use for scripted vector graphics. There is a detailed tutorial over on Mozilla Developer Center that I used to get started, which I don't intend to reproduce here. That said, here are a few useful pointers:

  • <canvas> takes two explicit parameters height and width to specify the size of the area on which you can draw. Apparently setting these in CSS is not a good idea.
  • You draw inside your canvas using Javascript. Get hold of your canvas object from the DOM and you'll find it is imbued with all the helpful vector drawing methods you need
  • You can animate your canvas by using the Javascript setInterval() function to redraw it at regular intervals.
Armed with the Mozilla tutorial and the latest nightly build of WebKit  I set off to try my hand at a bit of canvas scripting.

First order of the day was to try to recreate a fun test that I saw recently on In The Dark (a great physics blog if you're on the look out for one). The test works on the basis that humans are really good at identifying patterns (even where there are none), and that this can lead us down the wrong path sometimes. We are shown two images of seemingly randomly scattered dots and asked to identify the one that is truly random. In lab tests, humans consistently pick the wrong image. We pick the one where the dots are scattered more smoothly, because we identify 'patterns' in the clumping caused by truly random behavior that throws us off the scent. And now, by the miracle of HTML 5, here are the two images:

No prizes for which one folks normally choose as the random image. Interesting huh?

There is a really simple piece of Javascript running these simulations (and because it's Javascript you can add interactivity just like the customisation I added to the right hand box). If you want to see the code, just view the source of the frame above. The whole thing took next to no time to put together (especially given that I was learning about <canvas> at the same time). Onto my next exercise.

In their blog post the gmail team said that they had decided to build a throbber for gmail mobile using <canvas> and Javascript so that they could reduce server round trips and page weight. I thought this sounded pretty amazing (after all a throbber gif is never more than a few kB right) so I set out to see if I could recreate their efforts. After a bit of gnashing of teeth and a lot of fun tweaking my design I came up with the following 49 lines of code (1668 Bytes or just 702 when gzipped) :

function Throbber(containerId) {
  this.options = {
    speedMS: 100,
    center: 4,
    thickness: 3,
    spokes:8,
    color: [0,0,0],
    style: "line" //set to "balls" for a different style of throbber
  };
  this.t = document.getElementById(containerId);
  this.c = document.createElement('canvas');
  this.c.width = this.t.offsetWidth;
  this.c.height = this.t.offsetHeight;
  this.t.appendChild(this.c);
  this.throb = function() {
    var ctx = this.c.getContext("2d");
    ctx.translate(this.c.width/2, this.c.height/2);
    var w = Math.floor(Math.min(this.c.width,this.c.height)/2);
    var self = this;
    var o = self.options;
    var draw = function() {
      ctx.clearRect(-self.c.width/2,-self.c.height/2,self.c.width,self.c.height)
      ctx.restore();
      ctx.shadowOffsetX = ctx.shadowOffsetY = 1;
        ctx.shadowBlur = 2;
        ctx.shadowColor = "rgba(220, 220, 220, 0.5)";
        for (var i = 0; i < o.spokes; i++) {
        r = 255-Math.floor((255-o.color[0]) / o.spokes * i);
        g = 255-Math.floor((255-o.color[1]) / o.spokes * i);
        b = 255-Math.floor((255-o.color[2]) / o.spokes * i);
          ctx.fillStyle = "rgb(" + r + "," + g + "," + b + ")";
        if(o.style == "balls") {
          ctx.beginPath();
          ctx.moveTo(w,0)
          ctx.arc(w-Math.floor(Math.PI*2*w/o.spokes/3),0,Math.floor(Math.PI*2*w/o.spokes/3),0,Math.PI*2,true);
          ctx.fill();
        } else { ctx.fillRect(o.center, -Math.floor(o.thickness/2), w-o.center, o.thickness); }
        ctx.rotate(Math.PI/(o.spokes/2))
        if(i == 0) { ctx.save(); }  
      }
    };
    draw();
    this.timer = setInterval(draw,this.options.speedMS);  
  };
  this.stop = function() {
    clearInterval(this.timer);
    this.c.getContext("2d").clearRect(-this.c.width/2,-this.c.height/2,this.c.width,this.c.height)
  };
};

You just add this code to your site's JS, create a new Thobber object passing in the ID of the element you want your throbber to live inside and call the throb() method on it. You can use your parent element to style the background color and the options within the throbber element to customize it. For context, the gif-based throbber on a website I built a while back was fully 3,208 bytes while the code above at 702 bytes covers not just one kind of throbber but a vast array of customizations. Here is a little demo:



Obviously there are more impressive things you can do with canvas, but I really enjoyed coding this up and think I'll find it useful (especially for projects that are focussed exclusively on iPhone or Android). I hope you might too. There's even a whole framework (processing.js) designed to make scripting canvas easier. I think I may look at that next...

So it seems like canvas is a welcome addition to the HTML family (it is a lot nicer than Flash and ActionScript in my humble opinion). I guess as browser adoption increases, we'll see more and more of it.

Tuesday, February 03, 2009

Simple maths

Seems like the music industry proved again this week that it is incapable of acting rationally (seriously, there is a great paper for any budding behavioral economist in how the music industry incentives got so screwed up).

The offending action came this time in the form of labels leaning on fabulous new music streaming service spotify to add greater restrictions to the service. No doubt a bunch of these restrictions were needed to support the arcane company and rights structures the music industry dreamt up over the years. As an example of how crazy this can be, if you want to set up a site which lets users watch, interact with and mashup music videos you need:

  • at least 5 separate rights (covering the performance, the score, the recording, the video be the sync/mashup right - it's different in every country, but this is about it)
  • deals with a ton of different subsidiaries and rights middle-men in each of the countries where your users live
  • oh, and if your users want to use TV or movie clips, then try repeating the whole process with the moving picture industry - even hulu hasn't managed to get rights outside the US and they are owned by the TV industry!
But this is just another symptom of an industry that has become so overrun with lawyers that they have lost both the ability to do simple maths and the imagination to identify a massive opportunity when of comes to them and offers a substantial slice of the pie.

So let me spell it out for them:

People don't steal music
This is the first thing the industry needs to learn. When I see estimates of revenue lost to piracy they infuriate me. At the right price (and the right convenience) many of the folks that torrent stuff today would buy (especially if they knew that most of their payment went to the artist). That price might be very close to zero, but for legitimacy alone many folks would pay a nominal fee (either direct of
through advertising). The problem is that the music business has invested virtually no effort into providing a low cost, legitimate, easy alternative to bit-torrent and has instead spent lots of effort trying to shut down every promising avenue.


There is way more demand than you thought
Seriously, you did your elasticity calculations and optimised around your £10 price point. But you completely missed the explosion of demand when prices approach zero. You just labelled it piracy and moved on.

Distributing music is free now
Virtually. Which means you can make a gross profit at few pence per track if you think it through.

And then there is the simple maths:
£1 Pross Profit * 20k units << £0.01 GP * 20m units

So record companies, please, get with the programme. And in the meantime try to help build businesses that represent the bull of your future earnings rather than shutting them down.

Thursday, January 15, 2009

YouTube and eBay in awesome ad shocker!

I skipped over to YouTube to check out the latest trailer for the new Star Trek film today (I'm not sold yet, but I am excited). And I saw this amazing ad.



It got me very excited for lots of reasons. Here are a few:

1. It's a great ad. It's interactive, it's useful, it's got prices, it's not flashing or jumping around. This is content as advertising.
2. It's amazingly targeted. Star Trek items on eBay advertised next to a Star Trek trailer - yes, this is how I want my ads (and this is how advertisers should want them)
3. It's from eBay - generally I've not been a fan of their ads, but this is exactly what they should be doing.

This is what I was hoping for when Google bought YouTube. Let's hope we see a lot more of it.

Only in cinemas

I'm confused. On my regular morning walk through Victoria station I keep seeing posters that advertise new movies with the strangest of boasts: Only in cinemas.

I'm confused because I would have thought that the marketing teams at MGM and Lucasfilm would be keen to gloss over this obvious product shortcoming. I'm sure they must have made the case for their
customers. I'm sure that they must have made the point that the product would be considerably enhanced if it was available everywhere. That some of their customers might not want to go to a cinema and heck it doesn't cost much to release it on DVD or over the internet at the same time.

But no, this is not how it works in the movie industry. They have a formula you see. One honed over years of research that tells them (or so they think) how to squeeze every last drop out of every movie that they release. First you release at the cinema, then later on DVD, then VOD, then TV. It is a model (like most old school media business models) that is designed to ensure that customers pay the highest possible price per item of content consumed (in this case a movie) through inconvenience. And this formula is so ingrained in movie-land, that the marketing folks actually think that the inconvenience is actually a selling point.

Sadly, like most old school media companies the movie studios are trying to cling on to something that made sense in the 1980s but today is just ridiculous. In fact, I'd go as far as saying that the formula is actively hurting both customers viewing experience and movie studios' profits.


1. 'Only in cinemas' means that cinemas do not compete for your business on the basis of the quality of their product. It creates a local monopoly. If you want to see the film, and you want to see it now, then your going to the cinema. If you want to go to the cinema you probably have 1 or maybe 2 theatre's that are close enough to where you want to be to get your business. This is why cinemas are expensive and universally poor. Imagine if cinemas were competing with a simultaneous Internet, DVD and VOD release. They'd have to sell you on the experience. Maybe they'd have lovely big arm chairs, maybe they'd have amazing sound and visuals, maybe they'd sell beer. One thing is for sure, they'd be a lot less complacent.

2. All those customers that want to see the movie now (and are prepared to pay a premium to do so), but don't have the time to get out to a cinema (I'm a new dad - this is me!) have to wait 6 months for their fix. Basically this means that I see far fewer films than I would otherwise and it relegates DVD rental, VOD and Internet to some sort of bargain basement, entertainment-of-last choice. I really wanted to see The Day the Earth Stood Still (I know it was rubbish) but I didn't because I couldn't find the time to go out, and now, I probably never will (or will wait for TV) because seeing it was mainly about the hype!

These two customer complaints mean that movie industry is missing out. The cinemas are missing out on creating a real connection with their customers. On becoming the place that I have to go to see a new movie. And the studios are missing out on massive untapped demand. There are a lot of millions to be made here.

I've had this rant in my head for a long time. It started out with hard back books - I want the book now, I don't mind paying a premium, I don't want to take a hard back on the tube; why are you forcing me to wait a year to read your book, and why are you forcing me to pay a cut down price for that... But I think the movies are a better example. Primarily because they seem so proud of their model, so focussed on a meaningless metric optimized through inconvenience.

The first studio to opt for simultaneous multi-channel distribution of all its films is going to make a fortune. I bet it's not one of the current crop.

Saturday, January 10, 2009

2008 Music Highlights

I'm even later than usual with my top picks post this year...

That said it wasn't a bad year for music, (and it was a great year for music technology) so it'd be a shame not to recognise some of the hits and misses of 2008.

Top Records

Bon Iver - For Emma, Forever (amazon)
This album is just heart-wrenchingly delicate and beautiful. It is the perfect album for a cold, dark winter's day. Every song is brilliant, and my favourite seems to switch with the seasons. When I first listened, it was Creature Fear, then Blindsided, now re:Stacks. I'm sure this album still has more to give and it will remain a staple in our house in 2009. 

Glasvegas - Glasvegas (amazon)
I was switched on to Glasvegas by a friend's Google Talk status, saying simply 'Album of the Year'. Well Simon was right on that one. This Scottish group make the most incredible racket. They remind me of Jesus and Mary Chain or My Bloody Valentine, but this is no pastiche. The lyrics and melodies are touching and sometimes childlike (even when they're about getting stabbed) and the production is staggering. Favourite track right now is S.A.D. Light (Ruthie likes the nursery rhyme!)

Kings of Leon - Only the Night (amazon)
I resisted KOL almost until the very end of the year. Finally, in December, I succumed and made it my first purchase through Amazon's new UK MP3 store. I have to say that everyone else was right on this one. It blew me away. The best out and out rock album I have heard in years. It has echoes of so many great bands of the past, but is absolutely KOL at it's heart. Sex on Fire is my favourite single of the year, and that is nowhere near the best track on the album.

Portishead - Third (amazon)
Portishead have been away for what seems like ages. I remember hearing Dummy for the first time as a student and having my ears opened to a completely new sound. So it's pretty astonishing that one band could do that twice. Third sounds like nothing else released this year. The beats are harder, there is a new mechanical edge as evidenced in tracks like Machine Gun and there is liberal use of old school synths. Portishead have obviuosly been listening to a lot of Kraftwerk while they've been away.

Special Mention
Radiohead - I Might be Wrong (amazon)
I know this is an old album, but it gets a special mention as it was playing through most of the birth of our first child Ruthie. Pippa is a nut for Radiohead and this, I think, is their finest moment. The versions of True Love Waits and Like Spinning Plates are breath-taking. And now it will have the added benefit of always making me think of little Ruth.

Honorable Mentions
Spiritualized - Songs in A&E (amazon)
Sigur Ros - Með suð í eyrum við spilum endalaust (amazon)
Beck - Modern Guilt (amazon)


Top Music Technology

The big tech event in our house this year was switching 100% to the Apple. We ditched our old desktop and now meet all of our computing needs with a black Mac Book and a shiny silver Mac Bpook Pro. This had an additional massive benefit for our music enjoyment of enabling us to access the awesome music stack on the Mac. So now we have all our music living on the Mac Book, which is wirelessly connected to our amp via the AirPort Express and is controlled via the iTunes Remote on my iPhone (or the TuneRemote app on Pippa's Android). Our CDs are finally in the loft!

The other big Apple news was Genius Playlists on iTunes. We have been using it loads in order to re-disciver the music on our hard drive. I'm really impressed by their algorithm (and I'd forgotten quite how good Beck was!)

The last.fm application on my iPhone gave me a glimpse of a future that I thought was a lot further away. The first time I streamed personalized, Internet radio over a mobile 3G network to my phone I had a huge grin on my face. This is the way it's going to be in the future and I can't wait!

On the desktop, Spotify pointed the way to free streaming ad-supported music on-demand. It's a great service with a nice lightweight client and a very large library. The ads every 5-6 songs are absolutely fine and have even turned me on to a couple of things (my observation is that Movie ads work best in this media). I'm not sure if they can make the numbers turn round at this rate, but I hope they can.

In December, I rejoiced in the long awaited launch of Amazon MP3 in the UK (all the amazon links on this page point there). It's a great service. Big catalogue. Cheap (KOL was 4 quid). DRM-free. iTunes eat you heart out.

Finally the new year has brought two great music zeitgeists which are starting to live up to the promise of the internets ability to aggregate our music tastes. Last.fm have a chart made up of music scrobbles while Hype Machine have one based on blogs written. Both of these are great services and I'd like to see more automated music discovery in 2009.


I've definitely resolved to get back on the blogging machine in earnest in 2009, so expect a bit more traffic than the miserely 3 posts in Q4 :-) I might also try to post a few songs on Tumblr if I can make integration with this blog work.

Monday, December 08, 2008

ZX81 - seriously ZX81

One of the guys at work is setting up a computer museum in the office. The idea is to have as many (working) examples of historic computing devices as we can find. Apparently Google New York has one, and we in London don't want to be outdone. Especially since some of the best early examples of home computers were invented and built over here in the UK.

When the email went out asking for people to donate their old computers, I immediately thought of my old ZX81, sitting on top of a wardrobe at my grandad's house. My grandad is an ex-Television Engineer from the days when you could open up a TV and fix it, and he gave me the ZX81 when I was 6 or 7. I gave it back to him for safe keeping when I graduated to an Amiga, but never really lost my love for that little black box of magic with its 1K onboard ram and 16K RAM expansion pack.

So I was delighted this weekend to find that not only was the ZX81 all atill there (RAM expansion pack, manual, power supply, computer) but that in the intervening years my grandad had built it (along with a tape recorder for loading and storing programs) into the inside of a large wooden suitcase (is this the world's first and most antiquated laptop?)


When I got it home, I tentatively connected the RF lead to my ridiculously over-specced Sony flat screen TV and hooked up the power. After tuning in the TV, there was the cursor, a little bit blurry, a little bit of interference - but it works! Not bad after 20 odd years.  I mustered as much of my BASIC programming knowledge as I could and set about getting some output. And here are the results!


Taking a leaf through the manual, I remembered the 'special characters' that let you do graphics and the 100 line programs that delighted me when they ran fiorst time (or more likely second or third). Oh heady days...


Well now the ZX81 is headed in to Google and hopefully with a bit of love and care we can have it running in our museum for all to enjoy. I'll post a few more pictures when it is finally in situ.

Thursday, November 27, 2008

KTUU 2008 Sarah Palin turkey interview

Oh gosh. This, apparently, is fun!

Monday, November 03, 2008

My iPhone - 1 month in

I got an iPhone about a month ago and I have to say I love it. I thought it'd be fun to lay out some of the things that make me smile about the iPhone, and some of the things I want Apple to fix, so here I go...

Happiness

  • Safari - The real internet, really. It's so cool, and it's way better for not having flash ;-). The only thing better than browsing the full on internet on you iPhone is using...
  • iPhone optimised sites - Remember the Milk, Google, Friendfeed. Silky smooth and super responsive.
  • The 'silent' switch - The only physical switch on the iPhone. No need to unlock the phone to go on silent. Great tactile feedback. Just really well thought out.
  • Google Maps My Location - The big pulsating blue range finder that zooms into your location makes me feel like I'm in an episode of Spooks.
  • Twitteriffic - Great Twitter app. Integrated with twitpic.
  • last.fm - Listening to recommended radio streaming direct to your mobile phone is like the future now...
  • Google Earth - Enough said.
  • Oh, and it's beautiful
Fixes
  • Text messaging sucks - there's no letter count, you can't forward texts, and the app itself takes about 10 seconds to launch which is absolutely unforgivable.
  • Mail client is clunky - there's no way to rotate the keyboard into landscape mode, the 'Mark as Read' button is inexplicably hidden in 'details'
  • Mail client UI (Mark as read, add attachment), you can't add attachments (hello, photos...)
  • Folders on the home screen. Grouping icons would fit my mental model a little better
  • There's no Copy and Paste - I genuinely thought this was a joke...
  • No background tasks - Given patchy 3G coverage I want all of my apps to go off and cache data while I'm not doing anything with the phone (that's like 90% of the time people).
So, the upshot is that the iPhone has some amazing features and some serious (silly) bugs. I love it, and I can't wait for version 2.2!

Thursday, September 25, 2008

The Daily Politics

Yesterday was a big day for the political leaders of the US and the UK. In the US, Bush put forward his case for the massive rescue package currently going through congress . In the UK, Gordon Brown made the 'speech of his life' to try to retain control of the Labour Party and hence the position of Prime Minister.

Most of the accounts that I read gave both a B- type response. Good, but certainly not great. Bush's aid package is no doubt necessary, but a bunch of folks have huge concerns about potential market distortion. And Brown made a few nice policy announcements (free prescriptions for Cancer patients and free nursery for every 2 year old), but generally lacked substance.

As a quick test I wordled their speeches to see if anything interesting came out:

Bush:




Brown:



That has to be the most high-brow word cloud ever created from words uttered by George W Bush! And in Brown's cloud you can see the root of the problem. Those are the words of a generic socialist leader speech. Fairness, people, every. The one thing that jumps out at me is that the most popular word he used was 'new'. Yet I watched his speech and I can say that in my opinion, that is the one thing it wasn't...

Tuesday, September 23, 2008

Apple's Genius business model is all wrong


I recently installed iTunes 8 and for once, I'm pretty happy with the upgrades they made. I like the new interface, I like the new look, and most of all I like Genius.

Genius is Apple's attempt at collaborative filtering. You nominate a song in your library and it builds a playlist of your music to match that song (based on the masses of data Apple collects from iTunes users). So far, the playlists it has created for me have been excellent. They've been coherent, listenable collections and have resurfaced some excellent music I had forgotten that I owned. For once, I am not angry that I had to accept the iTunes ToS yet again :-)

One thing I think that Apple have missed though is the monetisation strategy. Right now this consists of a persistent sidebar that shows stuff you could buy on the iTunes store that relates to what you are listening to right now. It's a very small evolution from the old mini-store panel.

That's all very well and good, but here's my beef with it. When I am using iTunes, I am listening to music. I am not looking at my computer and reading a bunch of text telling me about tracks that I have no idea how to rate. I'm afraid that response rates on these ads are going to suck, monumentally, for the reason that this is old fashioned interuption marketing. It's pretty well targeted I'll give you that, but it gives me nothing, and I have to stop what I am doing to interact with it.

My suggestion for a better monetisation strategy would be this:

1. Every Genius playlist that is created adds 2 relevant tracks that you do not own and streams them from the iTunes store.
2. Before these tracks play there is a little unobtrusive sonic logo that let's you know you are about to here something you don't own.
3. While these tracks are playing, there is a big button on iTunes that let's you buy them with a single click (you could even have it set up so that pressing 'Menu' on your remote would do that).
4. Every time you play the Genius playlist it inserts a different two tracks.
5. Once a week, Apple emails you about all of the stuff that it inserted into your Genius playlists that you didn't buy at the time. These emails give you the context of the track and a 30 sec reminder. They replace the awful emails that iTunes currently sends out.
6. There could even be a nice bit of the iTunes store fr you to go and review this info whenever it suits you.

I guarantee that this approach would sell more tunes than the current sidebar.

No doubt the lawyers would say that there are all sorts of issues with streaming and DRM etc , but hell, if you are going to build a walled garden, why don't you take advantage of it. Better than that, if I was Apple I'd go to the record companies not asking how much I'd need to pay for streaming rights, but how much they will pay to get their tracks inserted. I'd build AdWords for iTunes, with record companies / bands bidding a higher rev share to Apple on the inserted tunes, and Apple figuring out AdWords style what combination of bids and quality score (clicks, purchases, match etc) delivers the best result for the end user and for Apple. New bands just getting started might offer Apple a huge rev share to get started. Getting inserted into a million playlists automatically is a great way to build a fan base (if you are good!)

As a user, I would absolutely love this. It's what I want from last.fm, but sadly they don't have the assets to complete the sale there and then. Apple on the other hand has built exactly that. So please Mr Jobs, give me the chance to really discover and buy new music on iTunes...