phoboslab

Flash Animation Without Flash

More than two years ago, I created a Flash Animation for my university class. Today, I converted the whole thing to plain Javascript and HTML5, using the new <canvas> tag to draw and the <audio> tag for music playback. It now runs smoother than it ever did in Flash.

Without further ado: Venetianization / HTML5 Animation

Some technical notes: For the original Flash Animation I used ActionScript 3 and created my own classes. Javascript doesn't have classes per se, but you can build something that looks and feels exactly like it. MooTools did an awesome job at that. Converting my ActionScript classes to MooTools classes was a no-brainer.

I was able to reuse most of the code with some basic search and replace throughout the source. One thing however, that is (to date) completely missing in Javascript, is the ability to analyze the current sound spectrum of an audio file. I ended up extracting the raw values of the spectrum with a sampling rate of 15Hz (which is enough for an animation that initially ran at 30Hz) and put them in a large array in one of the source files.

The thing that annoyed me the most however, is that I now have the music in two different formats: OGG Vorbis for Opera, Firefox and Chrome, and MP3 for Safari. I totally understand that Firefox, being open source and all, can't include MP3 support. What I don't get, is that Apple doesn't support OGG Vorbis – an audio format that is clearly superior to MP3 – instead, they choose to sit on their high horse and twiddle their thumbs. This is exactly the behavior that made Internet Explorer a laughable side note.

Side note: Of course none of this works in any version of Internet Explorer.

Tuesday, February 16th 2010
Tags: Javascript, HTML5, Canvas

10 Comments:

#1: ROBOT – Thursday, February 18th 2010, 21:55

amazing, this remembers me that thing don't live forever.
flash r.i.p.


#2: Tsoh – Friday, February 26th 2010, 22:09

sweet
would be well nice as visuals at a concert if you have audio-input that triggers the visuals... Though i guess that's not what you're doing
way to go though!

#3: Dd – Sunday, February 28th 2010, 00:42

Very useful (and pretty) animation (and code) ;) .

#4: Sol – Friday, April 16th 2010, 03:07

Oh wow, this is simply amazing :)

Any chance you could point me in the direction of some good sources for HTML5 and JavaScript knowledge (such as the references you used)? I'll check back here for a response.

#5: Dominic – Friday, April 16th 2010, 11:45

@Sol: Mozilla has a pretty good primer for the <canvas> tag: developer.mozilla.org/en/Canvas_tutorial

For JavaScript itself I can highly recommend all the talks by Douglas Crockford. You should already have some basic understanding of JS, though:
youtube.com/results?search_query=douglas+crockford

#6: sp – Tuesday, April 27th 2010, 14:09

Nice work, keep it up.

#7: J_ROM – Thursday, April 29th 2010, 11:48

Anwsome work! Loved your alert message under IE.

#8: Kevin – Sunday, May 2nd 2010, 19:55

Dude this is great! Thanks for a real sweet example of HTML5's flashlike capability. Does anyone have other HTML5 examples?

props!
Kevin

#9: Antonio – Thursday, May 6th 2010, 21:34

wuaaaaaaaaaau!!

#10: Shennan T. – Tuesday, August 24th 2010, 19:06

WOW is all I can say. That was amazing! I've always wanted to learn flash, but I might have to just go straight to HTML5. Crazy!

Post a Comment:

Comment: (Required)

(use <code> tags for preformatted text; URLs are recognized automatically)

Name: (Required)

URL:

Please type phoboslab into the following input field or enable Javascript. This is an anti-spam measure. Sorry for the inconvenience.