Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthorericr
    • CommentTimeMay 8th 2008 edited
     
    I came up with a crude way to convert BitmapData based images into pixels for the PixelRenderer to play with. This is all done with a new Initializer and some carefully considered settings. This allows you to load an image as a BitmapData object and then do interesting things like blow it up. (If you think of the end scene from the movie The Mummy where the mummy blows away in the sand... something like that is possible with this.)

    SharedBitmapData:package org.flintparticles.initializers
    {
    import flash.display.BitmapData;

    import org.flintparticles.emitters.Emitter;
    import org.flintparticles.particles.Particle;

    public class SharedBitmapData extends Initializer
    {
    private var _bitmapData:BitmapData;
    private var curX:uint = 0;
    private var curY:uint = 0;

    public function SharedBitmapData( bmd:BitmapData )
    {
    _bitmapData = bmd;
    }

    override public function initialize( emitter:Emitter, particle:Particle ):void
    {
    particle.x += curX;
    particle.y += curY;

    particle.color = _bitmapData.getPixel32(curX, curY);

    // Update curX and curY.
    if (curX >= _bitmapData.width - 1)
    {
    if (curY >= _bitmapData.height - 1)
    {
    curX, curY = 0;
    }
    else
    {
    curX = 0;
    ++curY;
    }
    }
    else
    {
    curX++;
    }
    }
    }
    }

    Example Implementation Snippet:var renderer:PixelRenderer = new PixelRenderer(new Rectangle(0, 0, 100, 100));
    renderer.addFilter(new BlurFilter(4, 4, 1));
    addChild(renderer);

    var bmd:BitmapData = someBitmapDataObjectWotWasLoadedElsewhere;
    emitter = new Emitter();
    emitter.counter = new Blast(bmd.width * bmd.height);

    emitter.addInitializer(new Position(new PointZone(new Point(renderer.width/2 - bmd.width/2, renderer.height/2 - bmd.height/2))));
    emitter.addInitializer(new Velocity(new DiscZone(new Point(0, 0), 30, 30)));
    emitter.addInitializer(new Lifetime(1, 1.5));
    emitter.addInitializer(new SharedBitmapData(bmd));

    emitter.addAction(new Move());
    emitter.addAction(new Age());
    emitter.addAction(new DeathZone(new DiscZone(new Point(0, 0), 50, 50)));
    emitter.renderer = renderer;
    emitter.start();

    Of specific import is the line involving the counter. You are essentially adding the number of pixels located in the image to the emitter (one particle per pixel). This is calculated simply by Width times Height. Cake.

    The above effect will explode your loaded image into pixel-particles. They will blur and fade as they go. The entire effect lasts around 1.5 seconds.

    Thoughts? Anyone have any ideas on how to better implement this kind of thing?
    • CommentAuthorRichard
    • CommentTimeMay 10th 2008
     
    It seems this is an idea who's moment has arrived. I've had an email from another Flint developer about some similar ideas. Nice work.
    • CommentAuthorericr
    • CommentTimeMay 12th 2008
     
    Just came across this. How about creating an emitter that can handle that kind of thing ;)

    They apparently use a class called Particle3D. Are you working on something similar for the 3D-capable version of Flint or is it more making the particle effects renderable (put the renderers on texture/normal maps, etc)?

    Also, did the other developer provide any test implementation code? I'd like to compare notes if so ;D
    • CommentAuthorRichard
    • CommentTimeMay 12th 2008
     
    That's pretty.

    The plan for 3d is a full 3d space for the particle system, with particles rendered on billboards or as 3d objects, with stand-alone renderers plus renderers for Papervision3D and Sandy in the library and a renderer interface that enables the creation of renderers for other 3d systems too. It may take awhile to get there but I believe it is a good plan and I hope to have something very rough to show by the end of this month - time permitting.

    P.S. The other developer hasn't sent me any code yet. He was working on a more general system of zones and renderers that included initialising particles based on the properties of an image. I'm hoping he will send me some code or better still share it on this forum.
    • CommentAuthorjmp909
    • CommentTimeMay 12th 2010
     
    could anyone convert this to the new 2D API? I don't really understand it enough to extend the Initializers

    thanks
    j
    • CommentAuthorRichard
    • CommentTimeMay 19th 2010
     
    There's now a utility method for creating pixel particles from bitmap data - Particle2DUtils.createPixelParticlesFromBirmapData().