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

ストロボ投影的ななにか

ストロボ投影的ななにか。
*
*  写真は @corleonis さんから拝借いたしました :-)
*
*  @see http://twitter.com/corleonis
*  @see http://www.flickr.com/photos/corleonis/4698962709/
Get Adobe Flash player
by soundkitchen 28 Jun 2010
/**
 * Copyright soundkitchen ( http://wonderfl.net/user/soundkitchen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dFCR
 */

/**
 *  ストロボ投影的ななにか。
 *
 *  写真は @corleonis さんから拝借いたしました :-)
 *
 *  @see http://twitter.com/corleonis
 *  @see http://www.flickr.com/photos/corleonis/4698962709/
 */
package
{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.net.*;
    import flash.system.*;

    [SWF(width=465, height=465, frameRate=30, backgroundColor=0x000000)]
    public class Main extends Sprite
    {
        public static const IMAGE_URL:String = "http://farm5.static.flickr.com/4040/4698962709_9b41657778.jpg";

        private var _shadow:Shape;
        private var _mask:Bitmap;
        private var _bitmap:Bitmap;

        public function Main()
        {
            addEventListener(Event.ADDED_TO_STAGE, _onAdded);
        }

        private function _onAdded(evt:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, _onAdded);

            var req:URLRequest,
                ctx:LoaderContext,
                loader:Loader,
                info:LoaderInfo;

            req = new URLRequest(IMAGE_URL);
            ctx = new LoaderContext(true);

            loader = new Loader();
            info = loader.contentLoaderInfo;
            info.addEventListener(Event.COMPLETE, _onLoadComplete);
            info.addEventListener(IOErrorEvent.IO_ERROR, _onLoadFailure);
            info.addEventListener(SecurityErrorEvent.SECURITY_ERROR, _onLoadFailure);

            loader.load(req, ctx);
        }

        private function _onLoadComplete(evt:Event):void
        {
            var info:LoaderInfo,
                loader:Loader,
                data:BitmapData,
                W:Number, H:Number,
                s:Number;

            W = stage.stageWidth;
            H = stage.stageHeight;

            info = LoaderInfo(evt.target);
            info.removeEventListener(Event.COMPLETE, _onLoadComplete);
            info.removeEventListener(IOErrorEvent.IO_ERROR, _onLoadFailure);
            info.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, _onLoadFailure);

            loader = info.loader;

            s = Math.min(loader.width / W, loader.height / H);
            loader.scaleX = loader.scaleY = 1/s;

            loader.x = (W - loader.width) >> 1;
            loader.y = (H - loader.height) >> 1;

            data = new BitmapData(W, H, true, 0);
            data.draw(loader, loader.transform.matrix);

            loader.unload();

            _bitmap = new Bitmap(data);
            _bitmap.x = (W - _bitmap.width) >> 1;
            _bitmap.y = (H - _bitmap.height) >> 1;
            _bitmap.smoothing = true;
            _bitmap.cacheAsBitmap = true;

            data = new BitmapData(W, H, true, 0);
            _mask = new Bitmap(data);
            _mask.cacheAsBitmap = true;
            _bitmap.mask = _mask;

            _shadow = new Shape();

            addChild(_bitmap);
            addChild(_mask);

            addEventListener(Event.ENTER_FRAME, _onEnterFrame);
        }

        private function _onEnterFrame(evt:Event):void
        {
            var g:Graphics,
                m:Matrix,
                data:BitmapData,
                W:Number, H:Number,
                cx:Number, cy:Number,
                nx:Number, ny:Number,
                dx:Number, dy:Number,
                d:Number, r:Number;

            W = stage.stageWidth;
            H = stage.stageHeight;
            d = Math.sqrt(W*W+H*H);
            nx = Math.random() * d;
            ny = Math.random() * d;
            cx = W >> 1;
            cy = H >> 1;
            dx = nx - cx;
            dy = ny - cy;

            d = Math.sqrt(dx*dx + dy*dy);
            r = Math.atan2(dy, dx);

            m = new Matrix();
            m.createGradientBox(1, 1, 0, -.5, -.5);
            m.scale(d, d);
            m.rotate(r);
            m.translate(cx, cy);

            g = _shadow.graphics;
            g.clear();
            g.beginGradientFill(GradientType.RADIAL, [0xFFFFFF, 0], [1, 0], [0, 255], m);
            g.drawRect(0, 0, W, H);
            g.endFill();

            data = _mask.bitmapData;
            data.lock();
            data.colorTransform(data.rect, new ColorTransform(1, 1, 1, .92));
            data.draw(_shadow, null, null, BlendMode.HARDLIGHT);
            data.unlock();
        }

        private function _onLoadFailure(evt:ErrorEvent):void
        {
            var info:LoaderInfo;

            info = LoaderInfo(evt.target);

            info.removeEventListener(Event.COMPLETE, _onLoadComplete);
            info.removeEventListener(IOErrorEvent.IO_ERROR, _onLoadFailure);
            info.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, _onLoadFailure);

            trace(evt);
        }
    }
}