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

MediaRSS - DotFlower's EffectViewer

@author dubfrog aka 'dubflash'
project [ MediaRSS - DotFlower's EffectViewer ]

読み込まれた画像をドットフラワーで構築します
マウスクリックで以下の3モードが展開します
["NORMAL", "DRUNK", "CRAZY"]

ローディングは「ロードオブ・ザ・ポンデリング」とかなんとか。
/**
 * Copyright dubfrog ( http://wonderfl.net/user/dubfrog )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wAUm
 */

// forked from Event's Simple MediaRSS Viewer

package  
{
    import flash.text.*;
    import flash.utils.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.system.*;
    import flash.net.*;
    import flash.events.*;
    import flash.display.*;
    import caurina.transitions.*;
    import caurina.transitions.properties.*;

    /**
     *
     * @author dubfrog aka 'dubflash'
     * project [ MediaRSS - DotFlower's EffectViewer ]
     *
     * 読み込まれた画像をドットフラワーで構築します
     * マウスクリックで以下の3モードが展開します
     * ["NORMAL", "DRUNK", "CRAZY"]
     *
     * ローディングは「ロードオブ・ザ・ポンデリング」とかなんとか。
     */
    [SWF(backgroundColor='0', width='465', height='465')] 
     
    public class Main extends Sprite 
    {
        public function Main():void
        {
            Wonderfl.capture_delay(6);
            
            if(stage) init();
            else stage.addEventListener(Event.ADDED_TO_STAGE, init);
            
            stageDetail();
        }
        private function loadin():void
        {
            bool = false;
            bloader = new BasicLoader(0xffffff, 12);
            bloader.x = stage.stageWidth/2;
            bloader.y = stage.stageHeight/2;
            bloader.scaleX = bloader.scaleY = 0;
            bloader.start();
            addChild(bloader);
            Tweener.removeTweens(bloader);
            Tweener.addTween(bloader, {scaleX:1, scaleY:1, time:.5, transition:"easeOutExpo"});
            
            t.alpha = 1;
            t.text = nodeList.title[numList.now];
            t.x = stage.stageWidth / 2 - t.width / 2;
            t.y = stage.stageHeight / 2 + 20;
            t.text = "";
            code.start(nodeList.title[numList.now], 10, 1);
            
            pblack();
        }
        private function loadout():void
        {
            Tweener.removeTweens(bloader);
            Tweener.addTween(bloader, {scaleX:0, scaleY:0, time:.5, transition:"easeOutExpo", onComplete:function():void
            {
                bloader.stop();
                removeChild(bloader);
            }});
            //code.backReset(1, 1);
            Tweener.removeTweens(t);
            Tweener.addTween(t, {y:stage.stageHeight + 100, time:1, transition:"easeOutExpo" });
        }
        private function vars():void
        {
            numList      = {now:0, cache:0, max:0, modeNow:0};
            nodeList     = {title:[], image:[], thumb:[]};
            dprop        = {scx:0, scy:-10};
            pprop        = {bx:10, by:10};
            particles    = [];
            interval     = 5000;
            blur         = new BlurFilter(5,5,1);
            cut          = 150;
            move         = .25;
            spd          = .1;
            bool         = false;
            offsets      = [new Point(), new Point()];
            mode         = ["NORMAL", "DRUNK", "CRAZY"];
        }
        private function init(e:Event = null):void
        {
            vars();
            mediaRSSReader();
        }
        private function start():void
        {
            canvas = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x000000);
            bitmap = new Bitmap(canvas);
            ebmp = canvas.clone();
            addChild(bitmap);
            bitmap.blendMode = BlendMode.ADD;
            
            addEventListener(Event.ENTER_FRAME, update);
            
            addText();
            imageLoad(0);
            callChangeEvent();
        }
        private function flowerPixel(p:Particle):void
        {
            canvas.setPixel(p.x, p.y+2, p.color);
            canvas.setPixel(p.x, p.y-2, p.color);
            canvas.setPixel(p.x+2, p.y, p.color);
            canvas.setPixel(p.x-2, p.y, p.color);
            
            canvas.setPixel(p.x+2, p.y+2, p.color);
            canvas.setPixel(p.x+2, p.y-2, p.color);
            canvas.setPixel(p.x-2, p.y+2, p.color);
            canvas.setPixel(p.x-2, p.y-2, p.color);
            
            canvas.setPixel(p.x, p.y+3, p.color);
            canvas.setPixel(p.x, p.y-3, p.color);
            canvas.setPixel(p.x+3, p.y, p.color);
            canvas.setPixel(p.x-3, p.y, p.color);
            
            canvas.setPixel(p.x+3, p.y+3, p.color);
            canvas.setPixel(p.x+3, p.y-3, p.color);
            canvas.setPixel(p.x-3, p.y+3, p.color);
            canvas.setPixel(p.x-3, p.y-3, p.color);
            
            canvas.setPixel(p.x, p.y+4, p.color);
            canvas.setPixel(p.x, p.y-4, p.color);
            canvas.setPixel(p.x+4, p.y, p.color);
            canvas.setPixel(p.x-4, p.y, p.color);
        }
        private function update(e:Event):void
        {
            ++offsets[0].x;
            ++offsets[1].y;
            ebmp.perlinNoise(pprop.bx, pprop.by, 2, Math.random() * 0xffffff, false, true, (8|4|2|1) , true , offsets);
            
            dmf = new DisplacementMapFilter(ebmp, new Point(), BitmapDataChannel.BLUE, BitmapDataChannel.BLUE, dprop.scx ,dprop.scy, DisplacementMapFilterMode.IGNORE);
            
            canvas.applyFilter(canvas, canvas.rect, new Point(0,0), dmf);
            canvas.applyFilter(canvas, canvas.rect, new Point(0,0), blur);
            
            if(particles.length > 0)
            {
                for(var i:int = 0; i <= particles.length-1; i++)
                { 
                    flowerPixel(particles[i]);
                    
                    if(mode[numList.modeNow] == "NORMAL")
                    {
                        particles[i].x += (particles[i].px - particles[i].x) * spd;
                        particles[i].y += (particles[i].py - particles[i].y) * spd;
                        
                    }else{
                        
                        particles[i].x = particles[i].sx + (Math.random() * move-move / 2);
                        particles[i].y = particles[i].sy + (Math.random() * move-move / 2);
                        particles[i].sx = particles[i].x;
                        particles[i].sy = particles[i].y;
                    }
                }
            }
        }
        private function callTimer():void
        {
            timer = new Timer(interval, 1);
            timer.addEventListener(TimerEvent.TIMER_COMPLETE, timeAct);
            timer.start();
        }
        private function stopTimer():void
        {
            if(timer)
            {
                timer.stop();
                timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timeAct);
                timer = null;
            }
        }
        private function timeAct(e:TimerEvent):void
        {
            numList.now++;
            if(numList.now > numList.max) numList.now = 0;
            
            imageLoad(numList.now);
        }
        
        private function mediaRSSReader():void
        {
            var ldr:URLLoader = new URLLoader;
            ldr.addEventListener(Event.COMPLETE, function(e:Event):void 
            {
                ldr.removeEventListener(Event.COMPLETE, arguments.callee);
                nodeList.title = XML(ldr.data)..media::title;
                nodeList.thumb = XML(ldr.data)..media::thumbnail.@url.toXMLString().split('\n');
                nodeList.image = XML(ldr.data)..media::content.@url.toXMLString().split('\n');
                numList.max = nodeList.image.length-1; //最大値格納
                start();
            });
            ldr.load(new URLRequest(_feed));
        }
        
        private function imageLoad(_n:int):void 
        {    
            var loader:Loader = new Loader();
            var context:LoaderContext = new LoaderContext(true);
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void
            {
                loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, arguments.callee);
                if(bool)
                {
                    delayStart(loader);
                    
                }else{
                    addEventListener(Event.ENTER_FRAME, function(e:Event):void
                    {
                        if(bool)
                        {
                            removeEventListener(Event.ENTER_FRAME, arguments.callee);
                            delayStart(loader);
                        }
                    });
                }
            });
            loader.load(new URLRequest(nodeList.image[_n]), context);
            loadin();
        }
        private function delayStart(_loader:Loader):void
        {
            var ld:Loader = _loader;
            Tweener.removeTweens(this);
            Tweener.addCaller(this, {time:1, count:1, onComplete:function():void
            {
                convert(ld);
                loadout();
            }});
        }
        
        private function convert(_target:Loader):void
        {
            var source:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
            //サイズ調整(stw,sth)
            var matrix:Matrix = new Matrix();
            var perx:Number = _target.width / stage.stageWidth;
            var pery:Number = _target.height / stage.stageHeight;
            var sx:Number, sy:Number;
            sx = 1 / perx;
            sy = 1 / pery;
            
            source.lock();
            matrix.scale(sx, sy);
            source.draw(_target, matrix);
            source.unlock();
            
            var cnt:int = 0;
            particles    = [];
            for(var w:int = 0; w<=stage.stageWidth; w++)
            {
                for(var h:int = 0; h<=stage.stageHeight; h++)
                {
                    if(cnt % cut == 0)
                    {
                        var dcolor:* = source.getPixel(w, h).toString(16);
                        var p:Particle = new Particle();
                        p.x = w;
                        p.y = h;
                        p.px = p.sx = p.x;
                        p.py = p.sy = p.y;
                        p.color = Number("0x" + String(dcolor));
                        
                        particles.push(p);
                    }
                    cnt++;
                }
            }
            callTimer(); //interval start...
        }
        private function pblack():void
        {
            for(var i:int = 0; i <= particles.length-1; i++)
            {
                particles[i].color = 0x000000;
            }
        }
        private function addText():void
        {
            var tf:TextFormat = new TextFormat();
            tf.color = 0xffffff;
            tf.size = 12;
            tf.font = "Arial";
            t = new TextField();
            t.width = t.height = 1;
            t.autoSize = TextFieldAutoSize.LEFT;
            t.selectable = false;
            t.defaultTextFormat = tf;
            t.x = stage.stageWidth / 2;
            t.y = stage.stageHeight / 2;
            addChild(t);
            
            code = new TextCharCode(t);
            code.addEventListener(TextCharCode.COMPLETE, function(e:Event):void{ bool = true; });
        }
        
        private function callChangeEvent():void
        {
            stage.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void
            {
                numList.modeNow++;
                if(numList.modeNow > mode.length - 1) numList.modeNow = 0;
                
                switch(mode[numList.modeNow])
                {
                    case "NORMAL":
                    dprop.scx = 0,  dprop.scy = -10;
                    pprop.bx = 10, pprop.by = 10; 
                    move = .25;
                    break;
                    
                    case "DRUNK":
                    dprop.scx = 0, dprop.scy = -20;
                    pprop.bx = 30, pprop.by = 30;
                    move = 5;
                    break;
                    
                    case "CRAZY":
                    dprop.scx = 0, dprop.scy = -100;
                    pprop.bx = 150, pprop.by = 150;
                    move = 10;
                    break;
                }
            });
        }
        
        private function stageDetail():void
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.quality = StageQuality.MEDIUM;
            
            //dummy
            var _bmp:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x000000);
            var _bitmap:Bitmap = new Bitmap(_bmp);
            addChild(_bitmap);
        }
        
        /*_Vars______________________________________________________________________________________*/
        
        private var _feed:String = "http://api.flickr.com/services/feeds/photos_public.gne?tags=rastaman&format=rss_200";
        private var bloader:BasicLoader;
        private var media:Namespace = new Namespace("http://search.yahoo.com/mrss/");
        private var nodeList:Object, numList:Object;
        private var canvas:BitmapData, ebmp:BitmapData;
        private var bitmap:Bitmap;
        private var colorList:Array, particles:Array, mode:Array;
        private var blur:BlurFilter, dmf:DisplacementMapFilter;
        private var timer:Timer;
        private var interval:int, cut:int;
        private var move:Number, spd:Number;
        private var offsets:Array;
        private var dprop:Object, pprop:Object;
        private var t:TextField;
        private var code:TextCharCode;
        private var bool:Boolean;
    }
}



import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.text.*;

class BasicLoader extends Sprite{
    
    public function BasicLoader(_color:Number = 0x000000, _size:Number = 5):void
    {
        color = _color;
        size = _size;
        createLoader();
    }
    private function createLoader():void
    {
        var radian:Number = Math.PI / 180;
        var cutmax:Number = 8;
        var radius:Number = size;
        parts = [];
        for (var i:int = 0; i <= cutmax-1; i++)
        {
            var angle:Number = (360 / cutmax) * i;
            var mc:Sprite = partsRect();
            mc.x = Math.sin(radian * angle) * radius;
            mc.y = Math.cos(radian * angle) * radius;
            mc.rotation = -angle;
            mc.alpha = .3;
            addChild(mc);
            parts[i] = mc;
        }
    }
    private function partsRect():Sprite 
    {
        var mc:Sprite = new Sprite();
        mc.graphics.beginFill(color);
        mc.graphics.drawCircle(0, 0, size/4);
        mc.graphics.endFill();
        return mc;
    }
    public function start():void
    {
        cnt = 0;
        bool = true;
        timer = new Timer(40, 0);
        timer.addEventListener(TimerEvent.TIMER, loading);
        timer.start();
    }
    private function reset():void
    {
        timer.stop();
        timer.removeEventListener(TimerEvent.TIMER, loading);
        timer = null;
        
        for (var i:int = 0; i <= parts.length - 1; i++) {
            parts[i].removeEventListener(Event.ENTER_FRAME, alphaup);
        }
    }
    private function loading(e:TimerEvent):void
    {
        if (bool)
        {
            parts[cnt].alpha = 1;
            parts[cnt].removeEventListener(Event.ENTER_FRAME, alphaup);
            parts[cnt].addEventListener(Event.ENTER_FRAME, alphaup);
            cnt--;
            if (cnt < 0) cnt = parts.length - 1;
        }
    }
    private function alphaup(e:Event):void
    {
        var target:* = e.target;
        target.alpha += (.3 - target.alpha) * .1;
    }
    public function stop():void
    {
        reset();
    }
    
    /*_Vars______________________________________________________________________________________*/
    
    private var color:Number;
    private var size:Number;
    private var bool:Boolean;
    private var parts:Array;
    private var timer:Timer;
    private var cnt:Number;
}

class TextCharCode extends EventDispatcher
{    
    public function TextCharCode(_tf:TextField)
    {
        tf      = _tf;
        vars();
    }
    private function vars():void
    {
        strAry  = [];
        pushAry = [];
        delay   = 1 / 60;
        bool    = false;
    }
    public function start(_str:String, _waitCount:Number = 100, _changeSpeed:Number = 5):void
    {
        for (var i:int = 0; i <= _str.length - 1; i++)
        {
            strAry[i] = String(_str.substr(i, 1));
        }
        
        getStr = "";
        cnt = 0;
        now = -1;
        max = _str.length - 1;
        waitCount = _waitCount;
        changeSpeed = _changeSpeed;
        
        if(bool)
        {
            timer.stop();
            timer.removeEventListener(TimerEvent.TIMER, backAction);
            timer.removeEventListener(TimerEvent.TIMER, action);
            timer = null;
        }
        bool = true;
        timer = new Timer(delay, 0);
        timer.addEventListener(TimerEvent.TIMER, action);
        timer.start();
    }
    public function backReset(_waitCount:Number = 100, _changeSpeed:Number = 5):void
    {
        cnt = 0;
        max = tf.length - 1;
        waitCount = _waitCount;
        changeSpeed = _changeSpeed;
        
        if(max > 0)
        {
            if(bool)
            {
                timer.stop();
                timer.removeEventListener(TimerEvent.TIMER, action);
                timer.removeEventListener(TimerEvent.TIMER, backAction);
                timer = null;
            }
            bool = true;
            timer = new Timer(delay, 0);
            timer.addEventListener(TimerEvent.TIMER, backAction);
            timer.start();
        }
    }
    private function action(e:TimerEvent):void
    {
        cnt++;
        
        for (var i:int = 0; i <= max; i++) 
        {
            pushAry[i] = getCode();
        }
        if (cnt > waitCount) 
        {
            if (cnt % changeSpeed == 0) 
            {
                now++;
                max--;
                pushAry.pop();
                getStr = getStr + strAry[now].toString();
            }
        }
        
        tf.text = getStr + String(pushAry.join(""));
        
        if (max < 0) 
        {
            bool = false;
            timer.stop();
            timer.removeEventListener(TimerEvent.TIMER, action);
            timer = null;
            dispatchEvent(new Event(COMPLETE));
        }
    }
    
    private function backAction(e:TimerEvent):void
    {
        cnt++;
        
        pushAry = [];
        for (var i:int = 0; i <= max; i++) pushAry[i] = getCode();
        
        if (cnt > waitCount) 
        {
            if (cnt % changeSpeed == 0)  --max;
        }
        tf.text = String(pushAry.join(""));
        
        if (max < 0) 
        {
            tf.text = "";
            bool = false;
            timer.stop();
            timer.removeEventListener(TimerEvent.TIMER, backAction);
            timer = null;
        }
    }
    
    private function getCode():String 
    {
        var tf:String, tl:String;
        tf = "A";
        tl = "z";
        var code1:* = tf.charCodeAt(0);
        var code2:* = tl.charCodeAt(0);
        var ranCode:* = code1 + Math.random()*(code2-code1);
        return String.fromCharCode(ranCode);
    }
    
    /*_Vars______________________________________________________________________________________*/
    
    private var tf:TextField;
    private var strAry:Array, pushAry:Array;
    private var delay:Number, now:Number, max:Number, cnt:Number;
    private var waitCount:Number, changeSpeed:Number;
    private var getStr:String;
    private var timer:Timer;
    private var bool:Boolean;
    public static const COMPLETE:String = "complete";
}


class Particle
{
    public var px:Number;
    public var py:Number;
    public var sx:Number;
    public var sy:Number;
    public var x:Number;
    public var y:Number;
    public var color:Number;
}