BitmapData Glow Trails

Many people have created trails using BitmapData so today I actually learned how to do it. This is really fun stuff!

[as]import mx.transitions.easing.*;
import mx.transitions.Tween;
import flash.display.BitmapData;
import flash.filters.*;
import flash.geom.ColorTransform;

var bmd:BitmapData = new BitmapData(600,400,true,0×00000000);
this.createEmptyMovieClip(“bmdc”,1);

this.createEmptyMovieClip(“ballc”,2);
ballc.attachMovie(“ball”,”ball”,0);

var bf:BlurFilter = new BlurFilter(5,5,1);
var gf:GlowFilter = new GlowFilter(0x0099CC,30,35,35,1,1,false,false);
bmdc.filters = [bf,gf];
var ct:ColorTransform = new ColorTransform(.5,.9,.2,.99,1,1,.7,.99);

bmdc.attachBitmap(bmd,0);

function moveIt(who) {
var tw:Tween = new Tween(who,”_x”,Normal.easeOut,who._x,Math.random()*Stage.width,2,true);
var tw2:Tween = new Tween(who,”_y”,Normal.easeOut,who._y,Math.random()*Stage.height,2,true);
var tw3:Tween = new Tween(who,”_rotation”,Normal.easeOut,who._rotation,Math.random()*720,2,true);
tw.onMotionStopped = function() {
moveIt(who);
}
}

this.onEnterFrame = function() {
bmd.draw(ballc);
bmd.colorTransform(bmd.rectangle,ct);
}

moveIt(ballc.ball);
[/as]

Lee


Commentary

  1. Sean Foushee says:

    Very nice, and less than 3K, excellent! I take it the star shape is a vector drawn in Flash for the Bitmap Class to manipulate?

  2. Lee Brimelow says:

    Yeah the star is just a simple vector shape created with the polygon tool

  3. skanda says:

    Thanks for sharing this piece of code, it saved me some time. Nice job :)

  4. china_Tamome says:

    GOOD very beautiful ~~~~~~

  5. randygland says:

    Here’s a AS3 version of this example :D

    import flash.display.Bitmap;
    import flash.display.MovieClip;
    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.filters.*;
    import flash.geom.ColorTransform;
    import caurina.transitions.Tweener;

    var bmd:BitmapData = new BitmapData(580, 360, true, 0×00);
    var bmdc:Bitmap = new Bitmap(bmd);
    addChild(bmdc);

    var ballc:MovieClip = new MovieClip();
    addChild(ballc);

    var ball:MovieClip = new MovieClip();
    ball.graphics.lineStyle(2, 0xFFFFFF, 1, true, “normal”);
    ball.graphics.drawCircle(0, 0, 20);
    ball.graphics.endFill();
    ballc.addChild(ball);

    var bf:BlurFilter = new BlurFilter(5,5,1);
    var gf:GlowFilter = new GlowFilter(0x0099CC,30,35,35,1,1,false,false);
    bmdc.filters = [bf,gf];
    var ct:ColorTransform = new ColorTransform(.5,.9,.2,.99,1,1,.7,.99);

    function moveIt() {

    Tweener.addTween(ball, { time:2, rotation:Math.random()*720, x:Math.random() * stage.stageWidth, y:Math.random() * stage.stageHeight, transition:”easeInSine”, onComplete:moveIt } );

    }

    function frame(e:Event):void
    {
    bmd.draw(this);
    bmd.colorTransform(bmd.rect,ct);
    }

    addEventListener(Event.ENTER_FRAME, frame);

    moveIt();

  6. guk says:

    i cant get it to work, i replaced all of the \ with \ because it didnt work with the ones posted for some reason. i also made an mc with an export of ball cuz i saw that u placed one in the code. but i get an error:
    ‘)’ or ‘,’ expected

  7. guk says:

    sorry it cut off, on lines
    var bmd:BitmapData = new BitmapData(600,400,true,0×000000);
    and
    var gf:GlowFilter = new GlowFilter(0×0099CC,30,35,35,1,1,false,false);

  8. guk says:

    sorry for all the comments but there was really no error, i retyped the code exactly as it was and it worked haha :D

  9. jesse says:

    is there a way to make this work in a motion tween?

  10. Marquizzo says:

    Thank you so much for this, Lee! I’ve been searching the webs for over an hour, and this is exactly what I was looking for!

    PS, guk: Code needs a MC to be created, with “ball” as its “Export for actionscript” property. I also had to replace smart quotes with dumb quotes, and re-type line 7 and 14. It must be a character type issue.

  1. [... Many people have created trails using BitmapData so today I actually learned how to do it. This is really fun stuff! [as]import mx.transitions.easing.*; import mx.transitions.Tween; import flash.display.BitmapData; import flash.filters.*; import flash.geom.ColorTransform; var bmd:BitmapData = new BitmapData(600,400,true,0x00000000); this.createEmptyMovieClip("bmdc",1); this.createEmptyMovieClip("ballc",2); ballc.attachMovie("ball","ball",0); var ...]

  2. [... Many people have created trails using BitmapData so today I actually learned how to do it. This is really fun stuff! [as]import mx.transitions.easing.*; import mx.transitions.Tween; import flash.display.BitmapData; import flash.filters.*; import flash.geom.ColorTransform; var bmd:BitmapData = new BitmapData(600,400,true,0x00000000); this.createEmptyMovieClip("bmdc",1); this.createEmptyMovieClip("ballc",2); ballc.attachMovie("ball","ball",0); var ...]

Leave a Comment