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

物欲レボリューション

物欲レボリューション。

初出:2008/9/16
この頃はタイムラインにas書く比率が高かった。
それにしてもコード汚すぎw

wonderflやFlashDevelopでいろいろ作っているうちに、
上達したかも。
Get Adobe Flash player
by umhr 15 Jul 2015
/**
 * Copyright umhr ( http://wonderfl.net/user/umhr )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mmhH
 */

/*
物欲レボリューション。

初出:2008/9/16
この頃はタイムラインにas書く比率が高かった。
それにしてもコード汚すぎw

wonderflやFlashDevelopでいろいろ作っているうちに、
上達したかも。


*/
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Stage;
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.net.navigateToURL;
    import flash.display.Loader;
    import flash.display.BitmapData;
    [SWF(width="465", height="465", frameRate="30", backgroundColor="0xFFFFFF")]
    public class Main extends Sprite {
        public function Main(){
//↓タイムラインに書いていたコード


var Math3d:Math3dClass = new Math3dClass();
var Poz:PozClass = new PozClass();
var Render:RenderClass = new RenderClass();
var LoadImg:LoadImgClass = new LoadImgClass();
var Ctrl:CtrlClass = new CtrlClass();
var Utilities:UtilitiesClass = new UtilitiesClass();

var model_array:Array = new Array();

function setModel():void{
    for (var i:int = 0; i<100; i++) {
        model_array[i] = [[0,0,0],[-75,-75,0],[0,-75,0],[75,-75,0],[-75,0,0],[0,0,0],[75,0,0],[-75,75,0],[0,75,0],[75,75,0]];
        var _z:Number = (i-50)/4;
        Poz.local_array[i] = [0,0,_z,0,0,0];
        Poz.localTo_array[i] = [Math.random()*10-5,Math.random()*10-5,_z,0,0,0];
        spriteCount_array[i] = 0;
    }
}
var spriteCount_array:Array = new Array();

setModel();

var count100:int = 0;
var count100To:int = 0;
var count100Count:int = -1;
function shuffle():void{
    var shuffle_array:Array = Utilities.shuffle(100);
    for (var i:int = 0; i<100; i++) {
        var j:int = shuffle_array[i];
        spriteCount_array[i] = 0;
        Poz.localTo_array[i] = [Math.random()*10-5,Math.random()*10-5,(j-50)/4,0,0,0];
    }
    Poz.globalTo_array[4] = 0;
    if(count100To == 0){
        count100To = (img_array.length)%100;
    }else{
        count100To = 0;
    }
    count100Count = 0;
}

function setSprite():void{
    var _length:int = model_array.length;
    for (var i:int = 0; i<_length; i++) {
        var _sp:Sprite = new Sprite();
        stage.addChild(_sp);
        _sp.x = stage.stageWidth/2;
        _sp.y = stage.stageHeight/2;
        _sp.name = "thumb__"+i;
        sp_array[i] = _sp;
    }
}
var sp_array:Array = new Array();
setSprite();
//
function fnMain(e:Event):void{
    if(count100 == 0){
        Poz.globalTo_array[4] += 0.01;
    }else{
        Poz.globalTo_array[4] -= 0.01;
    }
    Poz.global_array[4] = Poz.global_array[4]*0.99 + Poz.globalTo_array[4]*0.01;
    fnMov(Poz.local_array);

    var poz_array:Array = new Array();
    poz_array = Math3d.arrayClone(model_array);
    //fnRotation(Poz.local_array);
    Math3d.localAffine(poz_array,Poz.local_array);
    Math3d.globalAffine(poz_array,Poz.global_array);
    Math3d.pertrans(poz_array);
    Poz.zSort(poz_array,sp_array,stage);
    
    render(poz_array);
}
function fnMov(local_array:Array):void{
    for (var i:int = 0; i<100; i++) {
        if(spriteCount_array[i] < 1){
            spriteCount_array[i] += 0.01;
        }else{
            continue
        }
        spriteCount_array[i] = Math.min(spriteCount_array[i],1);
        var countX:Number = xTween(spriteCount_array[i]);
        Poz.local_array[i][0] = Poz.local_array[i][0]*(1-countX) + Poz.localTo_array[i][0]*countX;

        var countY:Number = yTween(spriteCount_array[i]);
        Poz.local_array[i][1] = Poz.local_array[i][1]*(1-countY) + Poz.localTo_array[i][1]*countY;
        
        var countRY:Number = pow2Tween(spriteCount_array[i]);
        Poz.local_array[i][2] = Poz.local_array[i][2]*(1-countRY) + Poz.localTo_array[i][2]*countRY;
        Poz.local_array[i][4] = Poz.local_array[i][4]*(1-countRY) + Poz.localTo_array[i][4]*countRY;
    }
    if(Math.random() > 0.1){
        var a:int = Math.floor(Math.random()*100);
        var b:int = Math.floor(Math.random()*100);
        var abX:Number = Poz.localTo_array[a][0] - Poz.localTo_array[b][0];
        var abY:Number = Poz.localTo_array[a][1] - Poz.localTo_array[b][1];
        var abZ:Number = Poz.localTo_array[a][2] - Poz.localTo_array[b][2];
        var abXY:Number = Math.sqrt(abX*abX+abY*abY+abZ*abZ);
        if(abXY < 300){
            Poz.localTo_array[a][0] += abX;
            Poz.localTo_array[a][1] += abY;
            Poz.localTo_array[a][2] += abZ;
            Poz.localTo_array[b][0] -= abX;
            Poz.localTo_array[b][1] -= abY;
            Poz.localTo_array[b][2] -= abZ;
            spriteCount_array[a] = 0;
            spriteCount_array[b] = 0;
        }
    }else{
        if(Math.random() > 0.95 && Math.abs(Poz.globalTo_array[4]) > 20){
            shuffle();
        }
    }
        if(Math.abs((Math.abs(Poz.global_array[4])+Math.PI/2)%Math.PI-Math.PI) < 0.1){
            if(Math.abs((Math.abs(Poz.global_array[4])+Math.PI/2)%(Math.PI*2)-Math.PI) < Math.PI/2){
                for (var j:int = 0; j<100; j++) {
                    Poz.localTo_array[j][4] = Math.PI;
                    if(0.5 < spriteCount_array[j] && spriteCount_array[j] < 1){
                        spriteCount_array[j] = 0.5;
                    }
                }
            }else{
                for (var k:int = 0; k<100; k++) {
                    Poz.localTo_array[k][4] = 0;
                    if(0.5 < spriteCount_array[k] && spriteCount_array[k] < 1){
                        spriteCount_array[k] = 0.5;
                    }
                }
            }
            
        }
}
function xTween(c:Number):Number{
    return pow2Tween(Math.min(1,c*2));
}
function yTween(c:Number):Number{
    return pow2Tween(Math.max(0,(c-0.5)*2));
}
function pow2Tween(c:Number):Number{
    return c*c;
}
function pow4Tween(c:Number):Number{
    return c*c*c*c;
}


function fnRotation(local_array:Array):void{
    var _length:int = local_array.length;
    for (var i:int = 0; i<_length; i++) {
        var _y:Number = local_array[i][1];
        var _z:Number = local_array[i][2];
        local_array[i][3] = Math.atan2(_z,_y)-Math.PI/2;
    }
}


function render(poz_array:Array):void{
    var _length:int = poz_array.length;
    if(count100Count > -1){
        if(count100Count < 20){
            count100Count ++
        }else{
            count100Count = -1;
            count100 = count100To;
        }
    }
    for (var i:int = 0; i<_length; i++) {
    
        var _sp:Sprite = sp_array[i];
        _sp.graphics.clear();
        if(poz_array[i][0][2] < 0 || 1.5 < poz_array[i][0][2]){
            continue;
        }
        Render.drawQuadrangleImage(_sp,[poz_array[i][1],poz_array[i][3],poz_array[i][7],poz_array[i][9]],bmp1_array[count100+i]);
        }
}


var loadComp:Function = function ():void{
    var _length:int = img_array.length;    
    for (var i:int = 0; i<_length; i++) {
        var bmp_data:BitmapData = new BitmapData(150,150, false, 0x00FFFFFF);
        bmp_data.draw(img_array[i]);
        bmp1_array[i] = bmp_data;
        
    }
    stage.addEventListener(Event.ENTER_FRAME,fnMain);
    //stage.removeChild(_nowloading);

}
var bmp1_array:Array = new Array();
var bmp4_array:Array = new Array();
var img_array:Array = new Array();
LoadImg.loadComp = loadComp;

var linkURL_array:Array = new Array();
var url:URLRequest = new URLRequest("http://mztm.jp/wonderfl/3d/arss/data.xml");
var url_loader : URLLoader = new URLLoader();

// 読み込み完了時に呼び出されるイベント
url_loader.addEventListener (Event.COMPLETE,LoaderInfoCompleteFunc);
function LoaderInfoCompleteFunc (event : Event):void {
    var xml:XML = new XML(url_loader.data);
    var _length:int = xml.items.length();
    var jpgURL_array:Array = new Array();
    for (var i:int = 0; i<_length; i++) {
        var _xml:XML = new XML(xml.items[i]);
        var i_length:int = _xml.item.length();
        for (var j:int = 0; j<i_length; j++) {
            var str:String = _xml.item[j].jpg;
            if(str != ""){
                str = str.split("/").pop();
                str = str.replace(/%/g,"");
                str = "http://mztm.jp/wonderfl/3d/arss/revolution/" + str;
                jpgURL_array.push(str);
                linkURL_array.push(_xml.item[j].url);
            }
        }
        
    }
    img_array = LoadImg.loadArray(jpgURL_array);
}

url_loader.load(url)

stage.addEventListener(MouseEvent.MOUSE_MOVE,stageMouseEventMOUSE_MOVE);
function stageMouseEventMOUSE_MOVE(event:MouseEvent):void{    
    var _array:Array = Ctrl.getHighestDepthObjectUnderPoint(stage);
    if(_array[0] == "thumb"){
        spriteCount_array[_array[1]] = 0;
    }
}
//
stage.addEventListener(MouseEvent.MOUSE_UP,stageMouseEventMOUSE_UP);
function stageMouseEventMOUSE_UP(event:MouseEvent):void{    
    var _array:Array = Ctrl.getHighestDepthObjectUnderPoint(stage);
    if(_array[0] == "thumb"){
        var url:URLRequest = new URLRequest(linkURL_array[count100 + int(_array[1])]);
        navigateToURL( url );
    }
}

//↑タイムラインに書いていたコード
        }
    }
}

/////////////////////////////////////////

import flash.geom.Point;
class CtrlClass{
    //クラスプロパティ
    //クラスメソッド
    //コンストラクタ
    public function CtrlClass(){};
    //インスタンスプロパティ
    //マウス位置の一番手前のオブジェクトの名前を取得
    public function getHighestDepthObjectUnderPoint(_stage:Object):Array{
        var list:Array = _stage.getObjectsUnderPoint(new Point(_stage.mouseX , _stage.mouseY));
        var l:int = list.length;
        var _array:Array = new Array();    
        if(l > 0){
            //上から順にnameを確認
            for (var i:int = 0; i<l; i++) {
                var str:String = list[l-1-i].name;
                _array = str.split("__");
                if(_array.length == 2){break};
                //該当無しの場合、-1を返す。
                _array = [-1,-1];
            }
        };
        return _array;
    }
}

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.net.URLRequest;
class LoadImgClass{
    public var loadImgRequest:int = 0;
    public var loadImgComp:int = 0;
    
    //全てのロード完了時に実行される関数を登録する。
    public var loadComp:Function = function():void{};
    
    private function comp():void{
        loadImgComp ++;
        if(loadImgRequest == loadImgComp){
            loadImgComp = 0;
            loadImgRequest = 0;
            loadComp();
        }
    }

    public function loadImg(_url:String):Loader{
        loadImgRequest++;
        var loader_obj:Loader = new Loader();
        var url:URLRequest = new URLRequest(_url);
        var info:LoaderInfo = loader_obj.contentLoaderInfo;
        info.addEventListener (Event.COMPLETE,fnLoaderInfoComplete);
        function fnLoaderInfoComplete(event:Event):void{
            comp();
            //info.removeEventListener(Event.COMPLETE,fnLoaderInfoComplete);
        }
        loader_obj.load(url);
        return loader_obj;
    }    
    public function loadArray(request_array:Array):Array{
        var return_array:Array = new Array();
        var _length:int = request_array.length;
        for (var i:int = 0; i < _length; i++) {
            var _url:String = request_array[i];
            if(_url != ""){
                return_array[i] = loadImg(request_array[i]);
            }else{
                return_array[i] = "";
            }
        }
        return return_array;
    }        
}

class Math3dClass{
    //arrayの複製。再起処理を行っている。
    public function arrayClone(ar:Array):Array {
        var _array:Array = new Array();
        var _len:int = ar.length;
        for (var i:int = 0; i<_len; i++) {
            _array[i]=(ar[i] is Array)?arrayClone(ar[i]):ar[i];
        }
        return _array;
    }
            
    //ペアトランス
    public function pertrans(arg_array:Array):void{
        var _length:int = arg_array.length;
        for (var i:int = 0; i<_length; i++) {
            var j_length:int = arg_array[i].length;
            for (var j:int = 0; j<j_length; j++) {
                var _per:Number = 1000/(1000+arg_array[i][j][2]);
                arg_array[i][j] = [arg_array[i][j][0] * _per,arg_array[i][j][1] * _per,_per];
            }
        }
    }
    //ローカル座標でのアフィン変換Affin transform
    //,index_array:Array
    public function localAffine(data_array:Array,poz_array:Array):void {
        var _length:uint = new uint(data_array.length);
        for (var i:int = 0; i<_length; i++) {
            //var index:int = index_array[i];
            var index:int = i;
            var n_cx:Number = Math.cos(poz_array[index][3]);
            var n_sx:Number = Math.sin(poz_array[index][3]);
            var n_cy:Number = Math.cos(poz_array[index][4]);
            var n_sy:Number = Math.sin(poz_array[index][4]);
            var n_cz:Number = Math.cos(poz_array[index][5]);
            var n_sz:Number = Math.sin(poz_array[index][5]);
            var d_x:Number = poz_array[index][0];
            var d_y:Number = poz_array[index][1];
            var d_z:Number = poz_array[index][2];
            var af_xx:Number = n_cz*n_cy+n_sx*n_sy*n_sz;
            var af_xy:Number = n_sx*n_sy*n_cz-n_sz*n_cy;
            var af_xz:Number = n_sy*n_cx;
            var af_yx:Number = n_cx*n_sz;
            var af_yy:Number = n_cx*n_cz;
            var af_yz:Number = -n_sx;
            var af_zx:Number = n_cy*n_sx*n_sz-n_sy*n_cz;
            var af_zy:Number = n_sy*n_sz+n_cy*n_sx*n_cz;
            var af_zz:Number = n_cx*n_cy;
            
            var i_length:uint = new uint(data_array[i].length);
            for (var j:uint = 0; j<i_length; j++) {
                var af_x:Number = data_array[i][uint(j)][uint(0)];
                var af_y:Number = data_array[i][uint(j)][uint(1)];
                var af_z:Number = data_array[i][uint(j)][uint(2)];
                data_array[i][uint(j)][uint(0)] = af_x*af_xx+af_y*af_xy+af_z*af_xz+d_x;
                data_array[i][uint(j)][uint(1)] = af_x*af_yx+af_y*af_yy+af_z*af_yz+d_y;
                data_array[i][uint(j)][uint(2)] = af_x*af_zx+af_y*af_zy+af_z*af_zz+d_z;
            }
        }
    }
    //グローバル座標でのアフィン変換Affin transform
    public function globalAffine(data_array:Array,poz_array:Array):void {
        var d_x:Number = poz_array[uint(0)];
        var d_y:Number = poz_array[uint(1)];
        var d_z:Number = poz_array[uint(2)];
        var _cx:Number = Math.cos(poz_array[uint(3)]);
        var _sx:Number = Math.sin(poz_array[uint(3)]);
        var _cy:Number = Math.cos(poz_array[uint(4)]);
        var _sy:Number = Math.sin(poz_array[uint(4)]);
        var _cz:Number = Math.cos(poz_array[uint(5)]);
        var _sz:Number = Math.sin(poz_array[uint(5)]);
        var af_xx:Number = _cz*_cy+_sx*_sy*_sz;
        var af_xy:Number = _sx*_sy*_cz-_sz*_cy;
        var af_xz:Number = _sy*_cx;
        var af_yx:Number = _cx*_sz;
        var af_yy:Number = _cx*_cz;
        var af_yz:Number = -_sx;
        var af_zx:Number = _cy*_sx*_sz-_sy*_cz;
        var af_zy:Number = _sy*_sz+_cy*_sx*_cz;
        var af_zz:Number = _cx*_cy;
        var _length:uint = new uint(data_array.length);
        for (var i:uint = 0; i<_length; i++) {
            var i_length:uint = new uint(data_array[i].length);
            for (var j:uint = 0; j<i_length; j++) {
                var af_x:Number = data_array[i][uint(j)][uint(0)];
                var af_y:Number = data_array[i][uint(j)][uint(1)];
                var af_z:Number = data_array[i][uint(j)][uint(2)];
                data_array[i][uint(j)][uint(0)] = af_x*af_xx+af_y*af_xy+af_z*af_xz+d_x;
                data_array[i][uint(j)][uint(1)] = af_x*af_yx+af_y*af_yy+af_z*af_yz+d_y;
                data_array[i][uint(j)][uint(2)] = af_x*af_zx+af_y*af_zy+af_z*af_zz+d_z;
            }
        }
    }
}

class PozClass{
    //globalの座標[x,y,z,xr,yr,zr];
    public var global_array:Array = new Array(0,0,2000,0,0,0);
    public var globalTo_array:Array = new Array(0,0,2000,0,0,0);
    public var local_array:Array = new Array();
    public var localTo_array:Array = new Array();
    //インスタンスメソッド
    public function zSort(poz_array:Array,sp_array:Array,target:Object):void{
        var _length:int = poz_array.length;
        var z_array:Array = new Array();
        for (var i:int = 0; i<_length; i++) {
            z_array[i] = poz_array[i][0][2];
        }
        z_array = z_array.sort(Array.NUMERIC|Array.RETURNINDEXEDARRAY|Array.DESCENDING);
        for (var j:int = 0; j<_length; j++) {
            var _z:int =    z_array[j];
            target.setChildIndex(sp_array[_z],0);
        }
    }
}

class RenderClass{
    import flash.display.Sprite;
    import flash.geom.Matrix;
    import flash.display.BitmapData;        
    public function drowLine(_sp:Sprite,poz_array:Array,_thickness:Number = 0,_color:int = 0xff0000,_alpha:Number = 1):void{
        //if(_color == -1){_color = defaultColor};
        _sp.graphics.lineStyle(_thickness,_color,_alpha)
        //_sp.graphics.beginFill (0,0);
        var _l:int = poz_array.length;
        _sp.graphics.moveTo(poz_array[_l-1][0],poz_array[_l-1][1]);
        for (var j:int = 0; j<_l; j++) {
            _sp.graphics.lineTo(poz_array[j][0],poz_array[j][1]);
        }
        _sp.graphics.lineStyle()
    }
    
    public function drawQuadrangleImage(_sp:Sprite,poz_array:Array,bmp_data:BitmapData):void{
        var bmp_dataW:Number = bmp_data.width;
        var bmp_dataH:Number = bmp_data.height;
        var _matrix:Matrix = setMatrix(poz_array[0],poz_array[1],poz_array[2],bmp_dataW,bmp_dataH);
        _sp.graphics.beginBitmapFill(bmp_data, _matrix, false, false);
        _sp.graphics.moveTo(poz_array[0][0],poz_array[0][1]);
        _sp.graphics.lineTo(poz_array[1][0],poz_array[1][1]);
        _sp.graphics.lineTo(poz_array[2][0],poz_array[2][1]);
        _sp.graphics.endFill();
    
        var _ltX:Number = poz_array[2][0] - poz_array[3][0] + poz_array[1][0];
        var _ltY:Number = poz_array[2][1] - poz_array[3][1] + poz_array[1][1];
        _matrix = setMatrix([_ltX,_ltY],poz_array[1],poz_array[2],bmp_dataW,bmp_dataH);
        _sp.graphics.beginBitmapFill(bmp_data, _matrix, false, false);
        _sp.graphics.moveTo(poz_array[1][0],poz_array[1][1]);
        _sp.graphics.lineTo(poz_array[2][0],poz_array[2][1]);
        _sp.graphics.lineTo(poz_array[3][0],poz_array[3][1]);
        _sp.graphics.endFill();    
    }
    
    private function setMatrix(poz0_array:Array,poz1_array:Array,poz2_array:Array,_w:Number,_h:Number):Matrix{
        var _matrix:Matrix = new Matrix();
        _matrix.a = (poz1_array[0]-poz0_array[0])/_w;
        _matrix.b = (poz1_array[1]-poz0_array[1])/_w;
        _matrix.c = (poz2_array[0]-poz0_array[0])/_h;
        _matrix.d = (poz2_array[1]-poz0_array[1])/_h;
        _matrix.tx = poz0_array[0];
        _matrix.ty = poz0_array[1];    
        return _matrix;
    }
}

class UtilitiesClass{
    import flash.geom.ColorTransform;
    /*
    色の明度を相対的に変える関数。
    rgb値と割合を与えて、結果を返す。
    rgbは、0xffffff段階の値。
    ratioが0の時に0x000000に、1の時にそのまま、2の時には0xffffffになる。
    相対的に、ちょっと暗くしたい時には、ratioを0.8に、
    ちょっと明るくしたい時にはratioを1.2などに設定する。
    */
    public function rgbBrightness(rgb:int,ratio:Number):int{
        if(ratio < 0 || 2 < ratio){ratio = 1;trace("function colorBrightness 範囲外")}
        var _r:int = rgb >> 16;//16bit右にずらす。
        var _g:int = rgb >> 8 & 0xff;//8bit右にずらして、下位8bitのみを取り出す。
        var _b:int = rgb & 0xff;//下位8bitのみを取り出す。
        if(ratio <= 1){
            _r *= ratio;
            _g *= ratio;
            _b *= ratio;
        }else{
            _r = (255 - _r)*(ratio-1)+_r;
            _g = (255 - _g)*(ratio-1)+_g;
            _b = (255 - _b)*(ratio-1)+_b;
        }
        return _r<<16 | _g<<8 | _b;
    }
    //フィールドカラーに変色するための関数
    //6桁16進数から、2桁ぶんずつを取り出す。 
    //色情報は24bit。r8bit+g8bit+b8bit。24桁の二進数         
    public function rgb2color(rgb:int,ratio:Number = 1):ColorTransform{
        //ratioが1以外の場合、明度変更関数へ
        if(ratio != 1){rgb = rgbBrightness(rgb,ratio)};
        var color:ColorTransform = new ColorTransform();
        color.redMultiplier = color.blueMultiplier = color.greenMultiplier = 0;
        color.redOffset = rgb >> 16;//16bit右にずらす。
        color.greenOffset = rgb >> 8 & 0xff;//8bit右にずらして、下位8bitのみを取り出す。
        color.blueOffset = rgb & 0xff;//下位8bitのみを取り出す。
        return color;
    }
    public function shuffle(_n:int):Array { 
        var _array:Array = new Array(); 
        for (var i:int= 0; i<_n; i++){ 
            _array[i] = Math.random(); 
        } 
        return _array.sort(Array.RETURNINDEXEDARRAY); 
    }
}