[AS2/AS3] Stretcher and DistortGrid (image distortion)

Hi!

I made an image distortion class (similar to the DistortImage class of the Sandy3D engine) and I’m sharing it. “Why did you make it since the perfectly good DistortImage class exists?” will you ask me. Well, the license under which the DistortImage class is released doesn’t allow commercial use and I had to use it on a commercial project. I made both an AS2 and an AS3 version of the class. By the way I called it Stretcher…

You can see the AS2 demo here.
You can see the AS3 demo here
.

Source files (AS2 & AS3)

*Note that I made a gizmo for the demo to show the functionality of the class, but you don’t NEED the Gizmo to distort the image, you can distort using just ActionScript (Tweens for example).

Features

  • Works on any MovieClip
  • About 30% faster than DistortImage
  • You can set the horizontal and vertical precision independently
  • You can change the precision after creating your object
  • You can define a line style (to make a wireframe effect, for example)
  • You can smooth the distorted MovieClip (or not, see limitations below)
  • You can change only one corner at the time if needed

Limitations

  • You cannot control the way triangles overlap.
  • When smoothing is active, moving a corner past the diagonal sometimes causes the swf to freeze for a couple of secs. From the tests I did, it seems to be a Flash problem (the DistortImage class have the same problem if you turn the smoothing on).

The base class of the Stretcher class (DistortGrid) can be used to freely distort any MovieClip. Not sure how useful this can be, but we never know!

You can see the AS2 demo here.
You can see the AS3 demo here.

Source files (AS2 & AS3)

Features

  • Works on any MovieClip
  • You can set the horizontal and vertical precision independently
  • You can define a line style (to make a wireframe effect, for example)
  • You can smooth the distorted MovieClip (or not, see limitations below)

Limitations

  • You cannot control the way triangles overlap.
  • When smoothing is active, moving a corner past the diagonal sometimes causes the swf to freeze for a couple of secs. From the tests I did, it seems to be a Flash problem (the DistortImage class have the same problem if you turn the smoothing on).
  • You cannot change the precision after you set it when you create the DistortGrid object. Instead, you must create another DistortGrid object with the new precision.

Whew! Sorry for the long post. Hope it’s useful for some people! (By the way it’s released under the MIT License, which autorizes any use)

Finally I must thank senocular for his wonderful tutorial on transform matrices. It helped me a lot! (http://www.senocular.com/flash/tutorials/transformmatrix/)

Philippe Van Kessel