hacks.mozilla.org

the tristan washing machine

This is another demo from Paul Rouget. It’s a very simple demonstration of what you can do when you combine video, SVG and some fun transformations.

View the Demo in Firefox 3.5
tristan

This puts a HTML5-based <video> element into an SVG document like so:

<svg:svg xmlns:svg="http://www.w3.org/2000/svg"
               width="194" height="194">
  <svg:foreignObject x="1" y="1" width="192" height="192">
    <html:video src="tristan3.ogv" ontimeupdate="rotateMePlease()"/>
  </svg:foreignObject>
</svg:svg>
Lots of code and many attributes removed for clarity. Please view the source for more details.

If you look at the rest of the source code you will also see that the rest of the player is also defined and controlled from SVG. And we’re also using some of the CSS and SVG capabilities that are in Firefox 3.5 to define the player as well. For example if you look at the CSS you will see:

#video {
    filter: url(#filter);
    clip-path: url(#circle);
}

The clip-path property lets you define a clip path for any element – html, svg or otherwise. This can be extremely powerful and can be any arbitrary path defined in SVG. Much like a cookie cutter this cuts out the center of the otherwise square video and uses that for display. Here’s what our clip path looks like:

<svg:clipPath id="circle" clipPathUnits="objectBoundingBox">
   <svg:circle cx="0.5" cy="0.5" r="0.5"/>
</svg:clipPath>

The filter property lets you define an SVG filter to use in the same way as a clip path. In our case we use a feColorMatrix:

<svg:filter id="filter">
  <svg:feColorMatrix values="0.3 0.3 0.3 0 0 0.3 0.3 0.3 0 0 0.3 0.3 0.3 0 0 0 0 0 1 0"/>
</svg:filter>

Although it is not used in this demo note that you can also use SVG to define gradient masks for any element in Firefox 3.5 as well.

When the video runs it uses the transformation property to rotate the video while it’s playing:

function rotateMePlease() {
    // Sure
    if (!video) return;
    video.style.MozTransform='rotate(' + i + 'deg)';
    i += 3;
}

You will notice that Paul built this into an XHTML document, carefully using namespaces and XML syntax. But most people would probably want to use SVG in plain-old-HTML. In Firefox 3.5 there is a way to do this using SVG External Document References. What this means is that instead of defining your SVG in the HTML file directly you can define it in its own file and refer to it through CSS like this:

.target { clip-path: url(resources.svg#c1); }

What this does is load the SVG from the resources.svg file and then use the object with the ID “c1″ as the clip path for the target. This is a very easy way to add SVG to your document without making the full switch to XHTML.

I hope that this gives you a taste of what’s possible when mixing SVG, HTML, video and CSS all together. Enjoy!

16 Responses to “the tristan washing machine”


  1. 1 Thomas Broyer

    Makes me think of the demos from Microsoft showing how XAML/WPF is powerful ;-)

  2. 2 Ken Saunders

    Wow, that’s so very cool (and funny).
    Great demonstration.

  3. 3 Quezako

    How many degrees washes a Tristan? ;)

  4. 4 Jason Orendorff

    This is cool, but it would have been cooler if Tristan had been blowing bubbles.

  5. 5 N

    I just love how the video controls rotate with the video :-)

  6. 6 belarmino

    espero la copia ya que poseeo el 3.0

  1. 1 颠覆网络35天 ─ Tristan牌滚筒洗衣机 < MJiA
  2. 2 Monthly Interesting Links Roundup (June 2009) - 2
  3. 3 Así es el nuevo Firefox 3.5 « UN BLOG SHULO!
  4. 4 » Blog Archive » Así es el nuevo Firefox 3.5
  5. 5 Así es el nuevo Firefox 3.5 » OkeyPeru.NeT
  6. 6 Así es el nuevo Firefox 3.5 - [:: WWW.ARKANGELES.BIZ ::]
  7. 7 Assim é o novo Firefox 3.5 | Patrijosa.INFO
  8. 8 Así es el nuevo Firefox 3.5 | 21segundos.com
  9. 9 Así es el nuevo Firefox 3.5 | Unión de Bloggers Hispanos
  10. 10 video - more than just a tag at hacks.mozilla.org

Leave a Reply