November 18, 2008
I’m releasing this filter as I couldn’t find an appropriate one out there. It lets you twirl a spiral into any Actionscript display object, and is fast enough to allow it to be animated.
You can get the source from here, both an animated and static examples are included.
hi, thanks for the filter idea.
i made it a little bit lighter and faster:
public static function twirl(x_pos:Number,y_pos:Number,w:Number,h:Number,radius:Number,twistyness:Number):DisplacementMapFilter
{
var imageData:BitmapData=new BitmapData(w,h,true,0xFF808080);
var half_w:Number=w/2
var half_h:Number=h/2
var maxDistance:Number=Math.sqrt(Math.pow(half_w,2)+Math.pow(half_h,1));
for(var x:int=0;x<w;x++)
{
for(var y:int=0;y<h;y++)
{
var p:Point=new Point(x-half_w,y-half_h);
var r:Number=Math.sqrt(Math.pow(p.x,2)+Math.pow(p.y,2));
var angularDisplacement:Number=Math.atan2(p.y,p.x)+Math.pow(twistyness*Math.max(Math.max(radius,radius)-r,0)/maxDistance,2);
imageData.setPixel(x,y,new ColorTransform(1,1,1,1,128*(1+(((r)*Math.cos(angularDisplacement))-p.x)/maxDistance),128*(1+(((r)*Math.sin(angularDisplacement))-p.y)/maxDistance)).color);
};
};
return new DisplacementMapFilter(imageData,new Point(x_pos,y_pos),BitmapDataChannel.RED,BitmapDataChannel.GREEN,w,h,"ignore");