svn checkout svn://labs.trolltech.com/svn/graphics/dojo/genie
cd genie && qmake && make && ./genie
For the impatient, a screencast is worth a thousand screenshots. For your pleasure, here is the 20-second screencast. Or view it on blip.tv, YouTube, or grab the Ogg Theora file (1.4 MB).
Usually you would not want to do the genie effect (made famous in Mac OS X) like in this implementation, as you can get mesh deformation easily using GLSL. Here I just want to show code as another example of one of the messages from my graphics talk in Qt Developer Days, namely "cheat whenever you can". If you inspect the inner loop, you can see that it is fairly simple. The idea is to store the outline of the genie shape in a table (I use logistic function, as "S" shape looks really good). During the animation, the left start-point and right end-point of each row is used to scale a horizontal slice of the original pixmap. One dimensional scaling like this is fairly cheap, as in ray casting trick. Furthermore, the only division in the loop can be optimized (at the cost of visual quality) to be carried out every N rows (the alternative is a look-up table). Since we are animating anyway, decide yourself if you can get away with the sacrificed quality.
I have no doubt that the experienced readers can further squeeze the scaling code, I left it just like it is because it starts to be less readable. Of course, feel free to have more fun there!
Final word: special thanks to Enrico Ros for the discussion, initial code, and the feedback.