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

ドット (3)

//////////////////////////////////////////////////////////////////////////////
ドット (3)
//////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 11 Aug 2010
    Embed
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wIBj
 */

////////////////////////////////////////////////////////////////////////////////
// ドット (3)
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.system.Security;

    [SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var base:Sprite;
        private var canvas:BitmapData;
        private var dots:Array;
        private static var deceleration:Number = 0.6;
        private static var friction:Number = 0.8;
        private var filePath:String = "http://www.project-nya.jp/images/flash/piyo.png";

        public function Main() {
            Wonderfl.capture_delay(8);
            init();
        }

        private function init():void {
            Security.allowDomain("www.project-nya.jp");
            Security.loadPolicyFile("http://www.project-nya.jp/crossdomain.xml");
            base = new Sprite();
            base.graphics.beginFill(0x000000);
            base.graphics.drawRect(0, 0, 465, 465);
            base.graphics.endFill();
            addChild(base);
            canvas = new BitmapData(465, 465, false, 0xFF000000);
            var bitmap:Bitmap = new Bitmap(canvas);
            addChild(bitmap);
            var loader:Loader=new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete, false, 0, true);
            loader.load(new URLRequest(filePath));
        }
        private function complete(evt:Event):void {
            var content:Bitmap = evt.target.content;
            content.x = int((465 - content.width)/2);
            content.y = int((465 - content.height)/2);
            initialize(content);
        }
        private function initialize(bitmap:Bitmap):void {
            var bitmapData:BitmapData = bitmap.bitmapData;
            dots = new Array();
            for (var y:uint = 0; y < bitmapData.height; y++) {
                for (var x:uint = 0; x < bitmapData.width; x++) {
                    var tx:uint = x + bitmap.x;
                    var ty:uint = y + bitmap.y;
                    var dot:Dot = new Dot(tx, ty);
                    var color:uint = bitmapData.getPixel(x, y);
                    dot.color = color;
                    dots.push(dot);
                }
            }
            base.buttonMode = true;
            base.addEventListener(MouseEvent.CLICK, click, false, 0, true);
        }
        private function click(evt:MouseEvent):void {
            base.mouseEnabled = false;
            base.useHandCursor = false;
            start();
        }
        private function start():void {
            for (var n:uint = 0; n < dots.length; n++) {
                var dot:Dot = dots[n];
                dot.x = uint(Math.random()*800) - 400 + 232;
                dot.y = uint(Math.random()*800) - 400 + 232;
                dot.completed = false;
            }
            addEventListener(Event.ENTER_FRAME, update, false, 0, true);
        }
        private function stop():void {
            removeEventListener(Event.ENTER_FRAME, update);
            base.mouseEnabled = true;
            base.useHandCursor = true;
        }
        private function update(evt:Event):void {
            canvas.lock();
            canvas.fillRect(canvas.rect, 0xFF000000);
            var completed:uint = 0;
            for (var n:uint = 0; n < dots.length; n++) {
                var dot:Dot = dots[n];
                dot.xamplitude += dot.tx - dot.x;
                dot.yamplitude += dot.ty - dot.y;
                dot.x += dot.xamplitude*friction;
                dot.y += dot.yamplitude*friction;
                dot.xamplitude *= deceleration;
                dot.yamplitude *= deceleration;
                if (!dot.completed) {
                    canvas.setPixel(dot.x, dot.y, dot.color);
                } else {
                    completed ++;
                    if (completed > dots.length - 1) {
                        stop();
                    }
                }
                if (Math.abs(dot.tx - dot.x) < 0.5 && Math.abs(dot.ty - dot.y) < 0.5
                        && Math.abs(dot.xamplitude) < 0.5 && Math.abs(dot.yamplitude) < 0.5) {
                    dot.x = dot.tx;
                    dot.y = dot.ty;
                    dot.completed = true;
                    canvas.setPixel(dot.x, dot.y, dot.color);
                }
            }
            canvas.unlock();
        }

    }

}


//////////////////////////////////////////////////
// Dotクラス
//////////////////////////////////////////////////

class Dot {
    public var x:Number = 0;
    public var y:Number = 0;
    public var tx:int = 0;
    public var ty:int = 0;
    public var color:uint;
    public var completed:Boolean = false;
    public var xamplitude:Number = 0;
    public var yamplitude:Number = 0;

    public function Dot(x:int, y:int) {
        tx = x;
        ty = y;
    }

}