PolarDistort class updated and optimized (some)

Updated this with some optimization tricks. Got the render time down from about 150 ms to under 100 on my machine. It’s actually to the point where you can do some relatively uncrappy animation with it. Click the image below to toggle anim:

[kml_flashembed movie=”http://www.bit-101.com/blog/wp-content/uploads/2008/03/polaranim.swf” width=”400″ height=”400″/]

I still wouldn’t consider it animation worthy. But I think it’s at least speedy enough to render with new values on the fly, like if you wanted to adjust params with sliders or something like my original demo. FYI, I tried removing the sqrt call in the loop, as suggested in the comments of the last post, but realized I still need the unsquared distance to calculate other values.

I also checked to make sure that neither dimension of the temp bitmap is over 2880, just in case someone wants to use a portrait mode image as source.

Furthermore, I changed the api a bit. The first version put the inner and outer radius and invert in the constructor. I realized that those made a lot more sense in the render method. So I put them there, along with the seam as another parameter. Now that they are in the render method, I removed them as setters on the object itself.

PolarDistort.as

Next up, I’m going to look at something to handle the seam better, and maybe sky removal…

This entry was posted in Flash. Bookmark the permalink.

8 Responses to PolarDistort class updated and optimized (some)

  1. Bartek says:

    Looks good – I have a pretty slow computer and the animation is still relatively smooth. The link to the AS class does not work though.

  2. Mike Duguid says:

    I wonder if it’d be possible to do the reverse conversion i.e from polar to rectangular – this would be useful to convert images from a panoramic ‘cone’ shaped lense on a camera into a 360º panorama. You could point a webcam at one of these lenses then have a live 360 pannable video feed albeit with a fairly slow framerate.

  3. Nice animation. I also did a few experiments with polar coordinates. Check it out http://labs.blitzagency.com/?p=118

  4. kp says:

    Very nice, Patrick. Great idea to use it as a displacement.

  5. p says:

    nice polarization going on! would be cool if the images changed.

  6. Hi Keith! I just added a “twirl” to the polar distort.

    Change this line:
    angle = Math.atan2(dy, dx) – seam;

    to this:
    angle = Math.atan2(dy, dx) – seam+(Math.PI/270*dist);

    …where the “270” can be played with to give different twirl “tightness”.

  7. Aleksey says:

    Great script, Keith!

    Is it possible to modify the script for any degree distortion (not just 360)?

    Thanks forward for you answer!

Leave a Reply