HI all. I need to create an effect of one image "swirling" into the next. Can
someone please point me in the right direction to get started. I know this can
be done with bitmapdata but I haven't really used this before. Thanks!
I'm replying to my own topic here. I took a stab at creating a file that could
use an image from the library as the source of a bitmapdata effect. I am
loading the image into a container movieclip on the stage. It works, but very
slow, and I have transparency issues. I am wondering if anybody has any
suggestions on how to improve this (make it faster) and fix the black pixels
that appear when it swirls. Thanks for any help! It's much appreciated.
import flash.display.BitmapData;
this.initBitmap = function(){
_global.myBitmap = BitmapData.loadBitmap("image");
container.attachBitmap(myBitmap,0);
}
// attach bitmap
initBitmap();
var imageW:Number; // width
var imageH:Number; // height
var step:Number = 0; // step size
var angStep:Number = 0; // angle for each step
var angStepIncr:Number = 0.1; // increase angle
var radius:Number; // radius
var radius2:Number; // square of radius
var diameter:Number; // diameter
var cY:Number; // center vertical
function initialize() {
imageW = 300;
imageH = 250;
radius = Math.round(Math.max(imageW,imageH)/2);
radius2 = radius*radius;
diameter = 2*radius;
cX = imageW/2;
cY = imageH/2;
var distortTimes:Number = 0
var dInterval:Number = setInterval(distortImage, 100);
}
function distortImage () {
// distort the image
//
var i2:Number;
var dist:Number;
var dsqrt:Number;
var c:Number;
var inew:Number;
var jnew:Number;
var angle:Number;
// loop over all possible candidates for distortion
for (var i:Number=-imageW;i<imageW;++i) {
i2 = i*i;
for (var j:Number=-imageH;j<imageH;++j) {
dist = i2+j*j;
if (dist<radius2) {
// get color of pixel (i,j)
c = myBitmap.getPixel(cX+i,cY+j);
// determine new coordinates
//
// calculate distance
dsqrt = Math.sqrt(dist);
// calculate angle to rotate point (i,j) to
angle = (Math.atan2(j,i)+angStep*Math.sin(dsqrt/30))*180/Math.PI+step;
// determine new coordinates to use
inew = Math.round(cX+dsqrt*Math.cos(angle*Math.PI/180));
jnew = Math.round(cY+dsqrt*Math.sin(angle*Math.PI/180));
// set pixel
myBitmap.setPixel(inew,jnew,c);
}
}
}
//
// update step
step++;
angStep += angStepIncr;
}
initialize();