There are so many reasons to admire Yugo Nakamura’s work I wouldn’t know where to start. The incredible range, quality, and singularity of work on display at tha.jp (the studio’s site) is simply puzzling. I had the chance to see Yugo’s talk at FITC in Toronto a few years ago, and the modesty and insight he showed was absolutely amazing. One of his topics was -if I remember well- about over sophistication, and how he relentlessly seeks to push boundaries emerging from a seemingly simple form. The Wonderwall is in my opinion a perfect example of that commitment. And as you’ll see, we’ll barely scratch the surface of it and yet have a peek at how technically and artistically refined the original interactive piece is.
A Wonderwall-like thingy with Traer AS3
What this little experiment is focusing on is the deformation of the grid when interacting. The underlying grid pattern is not stretched and deformed as in the original (which I do realize is absolutely part of the awesomeness of it). This experiment solely focuses on the use of physics simulation to recreate the effect, and yes, there’s way more to it in the real thing. Anyways, here’s the quick experiment, in just shy of 370 lines of non-engine code:
WonderwallLikeRefined.swf, hover the grid
The differences with the original
As previously mentioned, the grid pattern is regular. Rollovers are basic (lines connecting the particles). There’s no text, just images.
But from a code perspective, the main difference is probably that there’s springiness in this experiment, while THA’s original piece shows none. The reason is (I’m guessing) that another integration method was used to set the constraints: Verlet integration. Traer uses a Runge-Kutta integrator which is less suitable for stiff joints, usually approximated by infinite stiffness springs. Well, no need to hide it. I kept the springiness in.
How this is done

Using two sets of particles
I believe this diagram is pretty self explanatory. Two sets of particles are in use, linked together in a one-to-one relation (in our case using a Spring). Attached to the mouse is an Attractor (with negative strength) that repulses the free particles. A face of the final and deformed grid is defined by four free particles. Now, if we were to use this as-is, we would get an awful amount of distortion within each image.

Subdividing the faces
Given these four points, some subdivision is necessary to minimize distortion showing the triangles used to draw the faces. In the bin/ directory, you will find one .swf without face subdivision: not so pretty. In the source code (WonderwallLikeRefined.as), I’m using 6 subdivisions (72 triangles) for each face.
There’s a lot of room for improvement there, the number of subdivisions required to draw a nice face depends on its dimensions and the amount of deformation applied. One possible improvement could be to check the difference in slope between the top and bottom edges: the greater the difference, the greater the number of subdivisions necessary. I am inclined to think that in THA’s piece some system is in place: their grid is huge, runs real smooth, with minimal distortion.

Where is the mouse?
Another problem arise. How do we handle rollovers? One simple way is to check if the mouse position is within a given polygon (here, a face defined by 4 free particles). Luckily, Paul Bourke’s line-to-line intersection algorithm comes in handy, as illustrated in the diagram above. If we take half a line starting from the current mouse position and passing through an arbitrary point, the mouse is inside the polygon if the number of intersections is an odd number (or just 1 or 3 in our case). Yup. It’s that simple!
Again, in this piece of code, I am performing the check for every single face every time the physics simulation advances. A variety of techniques could be used to improve this. One way to do this could be to perform this test on the polygon encompassing half the particles. If the test yields a true, divide it in half. And again, until we get a false. Or the subset is a face. Yup, even a good old divide and conquer would be a real improvement.
A disclaimer
I don’t pretend I know for sure how the original Wonderwall was built by THA. They may have taken a totally different approach and the only way to make sure would be to ask them. But I’m too shy. Or to decompile the .swf, which would be totally sacrilegious given how much I respect these guys and their work. So really, I have no clue. This is simply an exploration of how one could have done something a bit similar with the Traer physics engine for AS3. And this was only driven by my admiration for the studio’s work, and sheer curiosity (how did they do it??! this is sooo cool!!).
Useful links
Github repo for TraerAs3 (includes the Wonderwall-like effect files)
The gorgeous original Wonderwall
Paul Bourke’s line-to-line intersection algorithm
Tha, Yugo Nakamura’s studio: an absolute must-see
And of course, Yugop

18 Comments
Hey Arnaud, I agree Yugo’s work is amazing – I remember visiting his site when I first started out with ActionScript and being so inspired! I also had a go at re-creating the wonderwall a while back and you can see it (along with source) here:
example 1 (with just color blocks)
example 2 (with images)
Hey Stephen, very nice! We came to the same conclusions, pretty much
Yep pretty much. Your port of Traer looks interesting – will have to take a look at it! Nice blog by the way – really like the explanation with diagrams
Thanks! I’d be really interested in what you would come up with the Traer port! BTW, I’ve seen your WobbleWall experiment, really nice. It would be nice to render the blobs with Catmull-Rom Splines, so it’s all smooth and curvy. I’ve got a class for it if you’re interested.
Yeh definitely! Email it over an I’ll take a look – also the source code for WobbleWall is on my blog if you wanted to download it. I’ve grabbed the code for Traer too, so will play around with it once the mad Christmas rush is over!
Just emailed it. Cheers!
Many thanks.
great work and well explained, i may be a bit late on this post, but do you think the grid can be created as triangles and not squares?
Any underlying structure for the particles could probably be used.
i.e.: http://blog.sqrtof5.com/wp-content/uploads/2010/03/structure.jpg
hello there!!!!
what can i do to make this a true gallery
add Mouse listeners to each picture and so on
thanks in advance…
by the way…. very good job and you make the physics explanation so clear
cheers!!!!!
Hi Arnaud,
we were also very impressed by the effect. Since we had no time we’re a little bit late but as of last week we also tried to reproduce it. Your post was very helpful, especially the AS3 port of Traer. You can see our result here.
Compared to your version we made single MovieClips out of each image. That was very helpful: the rollovers were easy to achieve, so was the deformation of the starting grid. For the image transformation we wrote a custom class (it can easily handle 10 subdivisions or more). I can send it to you if you’re interested.
Thanks again for the great starting point you provided!
Sorry … one more point:
I guess with “springiness” you meant the “wobble”-effect? If so you can easily reduce that by reducing the mass of the floating particles to “.1″. At least that works for us ..
But … we haven’t done it because we find it even more “organic” along with the wobbling
Mick, very nice! Glad you found this helpful.
Yes,
MovieClipinstances are convenient to use, but with a large number of images directly drawing the triangles in one pass should offer a nice performance boost.hi arnaud,
first of all – thanks for this great kind of work. i was looking for about a couple of month, for somebody who accept the challange. i tweaked some values, and the result is pretty close to what we need. the last thing to make this baby perfect, is to add the posibility to have movieclip capabilities on rollover, where you can put text and links into, like on the original one. we just played around with graphics., vertices and indices, but get stuck. is this a particular step to achieve the effect? could you give us a clue, where to start?
kind regards from germany
michael
Michael,
Thanks for your kind comment.
Yes, it should be possible to treat individual cells as MovieClip instances. Actually, a previous commenter used a custom transform class to do so. Basically the idea is that given the Graphics and BitmapData of a MovieClip, to deform it according to the four vertices associated with it in the underlying grid (use the MovieClip graphics as its own texture). Another approach could be to update portions of the “big” texture’s BitmapData when mouse events occur (writing at the proper uv coordinate the content of an animated clip for example). Hope this helps!
Arnaud,
we tried to draw the movieclips into the bitmaps for each single container and update them on mouseevent. also we treid to put new movieclips on the stage and to transform them accoding to the vertices and indices, but both without success. we would be very happy, if you could give us some assitance with a small example script, on how you would achieve the effect.
many thanks and kind regards
michael
Great work, respect!
I´am quite new to ActionScript Programming. I would like to know if someone could make a working gallery example from this like on http://wonder-wall.com/. So setting up event listeners for the grid items, tweening the item and transition it to a new container movieclip holding actually the “loaded content” and bringing it to stage with a “navigation back button” jumping back to the main grid overview.
Thanks in advance for your help guys.
hi arnaud.
awesome blog mate. really helped me understand the mathematics behind doing a cool effect like this… one question though. understand the explanation of deforming a movieclip so it matches the coordinates of the bitmap segment once clicked for instance, but how do you know what movieclip you would need to deform if the item clicked on is just BitmapData???
thanks again#
ben.
4 Trackbacks
[...] 1. A Wonderwall-Like Effect, with Traer AS3 [...]
[...] 1. A Wonderwall-Like Effect, with Traer AS3 [...]
[...] 1. A Wonderwall-Like Effect, with Traer AS3 [...]
[...] trabajo está basado en un Script de Sqrtof5, que a su vez es un homenaje al genial trabajo de Yugop Wonderwall. 05 Ago This entry was written [...]