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

Blood drips

Get Adobe Flash player
by tjoen 16 Aug 2010
/**
 * Copyright tjoen ( http://wonderfl.net/user/tjoen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kJnn
 */

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import flash.geom.*;
    import flash.filters.ColorMatrixFilter;
    
    public class BloodEffect extends Sprite
    {
        private var timer:Timer;
        private var fadeTimer:Timer;
        private var drops:Array;
        private var bmd:BitmapData;
        private var bitmap:Bitmap;
        private var dropPath:Sprite;
        private var fadeColorMatrix:ColorMatrixFilter;
        private var clearBmd:BitmapData;
        private var clearBitmap:Bitmap;
        
        public function BloodEffect()
        {    
            // define the fading color matrix - reduce Red, subtract Alpha
            var matrix:Array = new Array();
            matrix = matrix.concat([.96, 0, 0, 0, 0]);
            matrix = matrix.concat([0, 1, 0, 0, 0]);
            matrix = matrix.concat([0, 0, 1, 0, 0]);
            matrix = matrix.concat([0, 0, 0, 1, -5]);
            
            fadeColorMatrix = new ColorMatrixFilter(matrix);
            
            // init the droplets
            drops = new Array();
            
            for (var i:Number = 0; i < 10; i++)
            {
                var s:Sprite = new Sprite();
                drops.push(s);
            }
            
            // create the BitmapData and Bitmap objects
            bmd = new BitmapData(465, 465, true, 0x000000);
            bitmap = new Bitmap(bmd);
            addChild(bitmap);
            
            addEventListener(Event.ADDED_TO_STAGE, addedToStage);
        }
        
        public function addedToStage(e:Event):void
        {
            // draw the droplet path graphic
            dropPath = new Sprite();
            dropPath.graphics.beginFill(0xAA0000, 0.4)
            dropPath.graphics.drawCircle(0, 0, 6);
            dropPath.graphics.endFill();
            dropPath.graphics.beginFill(0xFFFFFF, .8);
            dropPath.graphics.drawCircle(-2, 0, 1.5);
            
            // draw blood droplets
            for each (var s:Sprite in drops)
            {
                s.graphics.beginFill(0xAA0000);
                s.graphics.drawCircle(0, 0, 6);
                s.graphics.endFill();
                s.graphics.beginFill(0xAA0000);
                s.graphics.moveTo(-7, 0);
                s.graphics.curveTo(-8, -8, -4, -16);
                s.graphics.curveTo(0, -20, 4, -16);
                s.graphics.curveTo(8, -8, 7, 0);
                s.graphics.endFill();
                
                var flare:Sprite = new Sprite();
                flare.graphics.beginGradientFill(GradientType.RADIAL, [0xCC0000, 0xCC0000], [1, 0], [0, 15]);
                flare.x = -3;
                flare.y = -4;
                flare.graphics.drawCircle(0, 0, 8);
                flare.graphics.endFill();
                s.addChild(flare);
            
                s.x = stage.stageWidth * Math.random();
                s.y = -80 * Math.random();
                s.scaleX = s.scaleY = 0.5 + 1 * Math.random();
                addChild(s);
                Wonderfl.capture_delay(9);
                
            }
            
            // init motion timer - fired every 50ms
            timer = new Timer(50);
            timer.addEventListener(TimerEvent.TIMER, onTick);
            timer.start();
            
            // init fade timer - fired every 1000ms
            fadeTimer = new Timer(1000);
            fadeTimer.addEventListener(TimerEvent.TIMER, onFadeTick);
            fadeTimer.start();
        }
        
        public function onTick(e:TimerEvent):void
        {
            for each (var s:Sprite in drops)
            {
                // move the droplet down 2px
                s.y += 2;
                
                // copy the path graphic to the BitmapData
                bmd.draw(dropPath, s.transform.matrix);
                
                // send the droplet back to the top if its off the screen
                if (s.y > stage.stageHeight + 30)
                {
                    s.x = stage.stageWidth * Math.random();
                    s.y = -80 * Math.random();
                }
            }
        }
        
        public function onFadeTick(e:TimerEvent):void
        {
            // apply the color matrix filter
            bmd.applyFilter(bmd, new Rectangle(0, 0, 465, 465), new Point(0, 0), fadeColorMatrix);
        }
    }
}