In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Smoking Cursor G2

/**
 * Copyright 0xFFFFFF ( http://wonderfl.net/user/0xFFFFFF )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ji5J
 */

package 
{
    import flash.display.StageScaleMode;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BitmapDataChannel;
    import flash.display.BlendMode;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.filters.ColorMatrixFilter;
    import flash.filters.DisplacementMapFilter;
    import flash.filters.DisplacementMapFilterMode;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.geom.Point;

    /**
     * @author Tatyana '0xFFFFFF' White
     * no comments, no optimization
     */
    [SWF(width=300,height=300, backgroundColor=0)]

    public class SmokingCursor2_2 extends MovieClip 
    {
        private const WIDTH : Number = 300;
        private const HEIGHT : Number = 300;
        private var bmpClouds : BitmapData;

        private var pixelsBmp : BitmapData;

        private var origin : Point = new Point(0, 0);

        private var displace : DisplacementMapFilter;

        private var channels : uint;
        private var seed : Number;

        private var cursor : Sprite = new Sprite();

        private var cf : ColorMatrixFilter;
        private var output : BitmapData;
        private var num : int;

        private var pixels : Array;
        private var ct : ColorTransform;
        private var p1 : Point;
        private var black : BitmapData;
        private var px : Number;
        private var py : Number;
        private var size : int;
        private var curSize : int;

        public function SmokingCursor2_2()
        {
            num = 6;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            bmpClouds = new BitmapData(WIDTH + num * 7 + 20 * 2, HEIGHT, false);
        
            pixelsBmp = new BitmapData(WIDTH, HEIGHT, false, 0);//,0xFFFFFF);

            output = new BitmapData(WIDTH, HEIGHT, false, 0);
            addChild(new Bitmap(output));
            
            black = new BitmapData(WIDTH, HEIGHT, false, 0);
            
            
            pixels = [];
            for(var i : int = 0;i < num;i++)
            {
        
                var pixel : BitmapData = new BitmapData(WIDTH, HEIGHT, false, 0);//,0xFFFFFF);
                pixels.push(pixel);
            }
        
            seed = 3;
            channels = BitmapDataChannel.RED | BitmapDataChannel.BLUE;
            
            cf = new ColorMatrixFilter([2, 0, 0, 0, 0, 
                                               0, 1, 0, 0, 0, 
                                               0, 0, 1, 0, 0, 
                                            0, 0, 0, 1, 0]);
                                            
            
            addEventListener(Event.ENTER_FRAME, update);
            
            
            ct = new ColorTransform();
            ct.alphaMultiplier = 1 / num;
            
            p1 = new Point();
            
       
            
            px = mouseX;
            py = mouseY;
            size = 5;
            curSize = 0;
            
            var blur : BlurFilter = new BlurFilter(3, 3, 2);
            cursor.filters = [blur];
        }

        private function update(evt : Event) : void
        {
            with(cursor)
            {
                graphics.clear();
                if(px == mouseX && py == mouseY)
                {
                    graphics.beginFill(0xffffff);
                    
                    graphics.moveTo(mouseX - 2, mouseY - 2);
                    graphics.lineTo(mouseX + 11 - 2, mouseY + 10 - 2);
                    graphics.lineTo(mouseX + 6 - 2, mouseY + 10 - 2);
                    graphics.lineTo(mouseX + 2 - 2, mouseY + 12 - 2);
                
                    if(curSize < size) curSize++;
                } 
                else 
                {
                    graphics.moveTo(px, py);
                    graphics.lineStyle(.7, 0xffffff, .6);
                    graphics.lineTo(mouseX, mouseY);
                    curSize = 0;
                }
                px = mouseX;
                py = mouseY;
            }
            //--
            var m : Matrix = new Matrix();
            m.translate(mouseX, mouseY);
            var tmpOut : BitmapData = new BitmapData(WIDTH, HEIGHT, false, 0);
            
            output.copyPixels(black, black.rect, origin);
            var blur : BlurFilter = new BlurFilter(3, 3, 1);


            bmpClouds.perlinNoise(140, 130, 1, seed, true, true, channels, false, [p1]);
            bmpClouds.applyFilter(bmpClouds, bmpClouds.rect, origin, cf);

            for(var i : int = 0;i < num;i++)
            {
                pixelsBmp = pixels[i];

                tmpOut.draw(pixelsBmp, null, ct, BlendMode.ADD);
                pixelsBmp.draw(cursor);
                
                
                displace = new DisplacementMapFilter(bmpClouds, new Point(-(i % 3) * 20 - i * 7, 0), BitmapDataChannel.BLUE, BitmapDataChannel.RED, 15, 5, DisplacementMapFilterMode.COLOR, 0);
                
                pixelsBmp.applyFilter(pixelsBmp, pixelsBmp.rect, origin, displace);
            }
            
            output.copyPixels(tmpOut, tmpOut.rect, origin);
            
            p1.offset(5.5, .5);
        }
    }
}