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

forked from: forked from: Laser Beaver

// forked from Fiddler_whirled's forked from: Laser Beaver
// forked from Beaver's Laser Beaver
// forked from BAM5's forked from: LaserTest
// forked from broken's LaserTest
package {
    
    import flash.display.*;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.*;
    import flash.text.TextFormat;
    
    [SWF(backgroundColor="0x000000", frameRate="30", width="465", height="465")]
    public class LaserTest extends Sprite {
        
        protected const TEXT:String = "Fantasy Beam";

        private var _m : Matrix3D = new Matrix3D(); 
        private var _uvts : Vector.<Number> = new Vector.<Number>();
        
        private var _textEdge : TextEdge;
        private var _bitmap : BitmapData;
        private var _laserLayer : Sprite;

        private var _delay : ColorTransform;

        private var _mouseX : Number = 0;
        private var _mouseY : Number = 0;
        private var _mousePress : Boolean = false;
        
        private var _offset : int = 0;
        
        public function LaserTest() {
            
            var sp : Sprite = new Sprite();
            var g : Graphics = sp.graphics;
            g.clear();
            g.beginFill(0x000000);
            g.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            g.endFill();
            addChild(sp);

            var textFormat : TextFormat = new TextFormat();
            textFormat.size = 48;

            _textEdge = new TextEdge(TEXT, textFormat);
            _delay = new ColorTransform(1, 1, 1, 1, -16, -8, -9);
            
            _bitmap = new BitmapData(stage.stageWidth, stage.stageHeight);
            _bitmap.fillRect(_bitmap.rect, 0x00000000);
            addChild(new Bitmap(_bitmap) );

            _laserLayer = new Sprite();
            addChild(_laserLayer);

            addEventListener(Event.ENTER_FRAME, enterFrameHandler);

            stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_mouseDownHandler);
        }

        private function stage_mouseDownHandler(event : MouseEvent) : void {
            if (_mousePress) return;
            _mousePress = true;
            _mouseX = mouseX;
            _mouseY = mouseY;
            _offset = 0;
            stage.addEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler);
            stage.addEventListener(Event.MOUSE_LEAVE, stage_mouseLeaveHandler);
        }

        private function stage_mouseUpHandler(event : MouseEvent) : void {
            mouseRelease();
        }

        private function stage_mouseLeaveHandler(event : Event) : void {
            mouseRelease();
        }
        
        private function mouseRelease() : void {
            if (!_mousePress) return;            
            _mousePress = false;
            stage.removeEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler);
            stage.removeEventListener(Event.MOUSE_LEAVE, stage_mouseLeaveHandler);
        }
        
        private function enterFrameHandler(event : Event) : void {

            // now, no rotate
            //_m.appendRotation(0.1, Vector3D.Z_AXIS); 

            var projectedVerts : Vector.<Number> = new Vector.<Number>();
            Utils3D.projectVectors(_m, _textEdge.verts, projectedVerts, _uvts); 

            var g : Graphics = _laserLayer.graphics;
            g.clear();            

            _bitmap.lock();

            if (_mousePress) {
                
                var cx : Number = _mouseX - _textEdge.width  / 2;
                var cy : Number = _mouseY - _textEdge.height / 2;
                
                g.lineStyle(0.5, 0xFFFFFF * Math.random(), 0.5);
    
                for (var i : int = 0; i < 200; i++) {

                    var x : Number = projectedVerts[_offset] + cx;
                    var y : Number = projectedVerts[_offset + 1] + cy;
                    _offset = (_offset + 2) % projectedVerts.length;
                    
                    var r : Number = Math.random();
                    
                    if (r < 0.6) {                    
                        _bitmap.setPixel32(x, y, 0xFFFFFFFF);
                    }

                    if (r < 0.1) {                    
                        g.moveTo(stage.stageWidth / 2, stage.stageHeight);
                        g.lineTo(x, y);
                    }
                }
            }

            _bitmap.colorTransform(_bitmap.rect, _delay);
            _bitmap.unlock();
        }
        
    }
}

import flash.display.*;
import flash.text.TextFormat;
import flash.filters.ConvolutionFilter;
import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

class TextEdge {
    
    public var width : Number;
    public var height : Number;
    public var verts : Vector.<Number>;

    public function TextEdge(text : String, textFormat : TextFormat) {

        var textField : TextField = new TextField();
        textField.defaultTextFormat = textFormat;
        textField.autoSize = TextFieldAutoSize.LEFT;
        textField.text = text;            
    
        var bmp : BitmapData = new BitmapData(textField.width, textField.height, false);
        bmp.draw(textField);
        
        var edgeFilter : ConvolutionFilter = new ConvolutionFilter(3, 3, 
            [-1, -1, -1, -1, 8, -1, -1, -1, -1], 3, 0);
        bmp.applyFilter(bmp, bmp.rect, new Point(0, 0), edgeFilter);
        
        
        var verts : Vector.<Number> = new Vector.<Number>();
        for (var x : int = 0; x < bmp.width; x++) {
            for (var y : int = 0; y < bmp.height; y++) {
                if (bmp.getPixel(x, y) > 0x100000) {
                    verts.push(x, y, 0);                    
                }
            }
        }

        this.width = bmp.width;
        this.height = bmp.height;
        this.verts = verts;
    }
}