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

tamaClock

...
@author umhr
Get Adobe Flash player
by umhr 27 Jun 2012
/**
 * Copyright umhr ( http://wonderfl.net/user/umhr )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/diQD
 */

package 
{
    /**
     * ...
     * @author umhr
     */
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import flash.events.Event;
    import flash.display.StageScaleMode;
    [SWF(backgroundColor="0x000000")]
    public class Main extends Sprite
    {
        public function Main():void {
this.graphics.beginFill(0x000000);
this.graphics.drawRect(0, 0, 465, 465);
this.graphics.endFill();            
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = "TL";
            var cubes_array:Array = new Array();
            var cube:Object;
            var cColor:Array = new Array(0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0x303030,0x272727,0x202020,0x171717,0x101010)
            for (var i:int= 0; i<3; i++){
                for (var j:int= 0; j<6; j++){
                    var jn:Number = 100/6;
                    for (var k:int= -5; k<5; k++){
                        var kn:Number = (jn*5)/5;
                        cube = new Object();
                        cube.shape = [[jn/2+(jn*j),kn/2+(kn*k),0]];
                        cube.poz = [100*i,0,0,0,0,0];
                        cube.n = k+5;
                        cube.fillColor = cColor[k+5];
                        cubes_array.push(cube);
                    }
                }
            }
            
            var renderObj:render = new render();
            var zSortObj:zSort = new zSort();
            var moveObj:move = new move();
            
            function fnMain(e:Event):void {
                var _length:int = cubes_array.length;
                var obj_array:Array = new Array(_length);
                obj_array = moveObj.movement(cubes_array,[(stage.mouseX-500)/10,(stage.mouseY-stage.stageHeight)/2+400]);
                var z_array:Array = zSortObj.sort(obj_array);
                renderObj.toRender(_sp_array,obj_array,cubes_array,z_array);
            }
            
            stage.addEventListener(Event.ENTER_FRAME,fnMain);
            var _sp_array:Array = new Array();
            function iniMakeSprite(arg_i:int):void{
                for (var i:int = 0; i < arg_i; i++) {
                    var sp:Sprite = new Sprite();
                    stage.addChild(sp);
                    _sp_array.push(sp);
                }
            }
            iniMakeSprite(cubes_array.length);
        }
    }
}

class zSort{
    //インスタンスメソッド
    public function sort(arg_data_array:Array):Array {
        var _length:int = arg_data_array.length;
        var _array:Array = new Array(_length);
        for (var i:int = 0; i<_length; i++) {
            _array[i] = _distance3d(arg_data_array[i][0],[0,0,-100000]);
        }
        return _array.sort(Array.NUMERIC|Array.RETURNINDEXEDARRAY|Array.DESCENDING).reverse();
    }
    private function _distance3d(arg0_array:Array,arg1_array:Array):Number {
        import flash.geom.Point;
        var pt0xy:Point = new Point(arg0_array[0], arg0_array[1]);
        var pt1xy:Point = new Point(arg1_array[0], arg1_array[1]);
        var _xy:Number = Point.distance(pt0xy,pt1xy);
        var ptxyz:Point = new Point(_xy, arg1_array[2]-arg0_array[2]);
        return ptxyz.length;
    }        
}

import flash.display.Sprite;
import flash.geom.Matrix;
import flash.display.*;
class render{
    public function toRender(sp_array:Array,obj_array:Array,cubes_array:Array,z_array:Array):void{
        var _length:int = cubes_array.length;
        var onoff_array:Array = onoff(_length);
        for (var j:int= 0; j<_length; j++){
            var k:int = z_array[j];
            circleRenderG(sp_array[j],obj_array[k],cubes_array[k],onoff_array[k]);
        }
    }
    private function onoff(_l:int):Array{
        var date:Date = new Date();
        var timeString:String = String(date).substr(-22,8);
        var s:int = date.getSeconds();
        var _array:Array = new Array();
        _array = _array.concat(dotNumber(int(timeString.substr(0,1))));
        _array = _array.concat(dotNumber(int(timeString.substr(1,1))));
        _array = _array.concat(dotNumber(int(timeString.substr(3,1))));
        _array = _array.concat(dotNumber(int(timeString.substr(4,1))));
        _array = _array.concat(dotNumber(int(timeString.substr(6,1))));
        _array = _array.concat(dotNumber(int(timeString.substr(7,1))));
        return _array;
    }
    private function dotNumber(_n:int):Array{
        var _array:Array = new Array(30);
        for (var j:int= 0; j<30; j++){
            if(j == _n/2){
                _array[j] = false;
            }else{
                _array[j] = true;
            }
        }
        if(_n == 0){
            _array = [false,true,true,true,false,false,true,true,true,false,
                      true,false,false,false,true,true,false,false,false,true,
                      false,true,true,true,false,false,true,true,true,false];
        }else if(_n == 1){
            _array = [false,false,false,false,false,false,false,false,false,false,
                      true,true,true,true,true,true,true,true,true,true,
                      false,false,false,false,false,false,false,false,false,false];
        }else if(_n == 2){
            _array = [true,false,false,true,true,true,true,true,false,true,
                      true,false,true,false,true,true,false,true,false,true,
                      false,true,false,false,true,true,false,true,true,true];
        }else if(_n == 3){
            _array = [true,false,true,false,true,true,false,true,false,true,
                      true,false,true,false,true,true,false,true,false,true,
                      false,true,false,true,false,false,true,false,true,false];
        }else if(_n == 4){
            _array = [true,true,true,false,false,false,false,true,true,true,
                      false,false,true,false,false,false,false,true,false,false,
                      true,true,true,true,true,true,true,true,true,true,];
        }else if(_n == 5){
            _array = [true,true,true,false,true,true,false,true,true,true,
                      true,false,true,false,true,true,false,true,false,true,
                      true,false,false,true,false,false,true,false,false,true,];
        }else if(_n == 6){
            _array = [false,true,true,true,true,true,true,true,true,false,
                      true,false,true,false,true,true,false,true,false,true,
                      true,false,true,true,true,true,true,true,false,true];
        }else if(_n == 7){
            _array = [true,false,false,false,false,false,false,false,false,true,
                      true,false,true,true,true,true,true,true,false,true,
                      true,true,false,false,false,false,false,false,true,true];
        }else if(_n == 8){
            _array = [false,true,false,true,false,false,true,false,true,false,
                      true,false,true,false,true,true,false,true,false,true,
                      false,true,false,true,false,false,true,false,true,false];
        }else if(_n == 9){
            _array = [true,true,true,false,true,true,false,true,true,true,
                      true,false,true,false,true,true,false,true,false,true,
                      true,true,true,true,false,false,true,true,true,true];
        }
        return _array;
    }
    private function circleRenderG(sp:Sprite,arg:Array,argObj:Object,isOnOff:Boolean):void {
        sp.graphics.clear();
        if(!isOnOff){
            return;
        }
        var p_x:Number = arg[0][0]*0.5;    // 中心座標
        var p_y:Number = arg[0][1]*0.5;
        var radius:Number = arg[0][2]*8;// 線の太さ
        var scale:Number = 1.0 / 1638.4 * radius*1.25;//球の大きさ
        var m:Matrix = new Matrix();
        m.identity();        // 正規化
        m.scale(scale , scale);    // 行列 *= スケーリング
        m.translate( p_x,p_y);    // 行列 *= 平行移動
        var ratios:Array;
        var alphas:Array;
        if(argObj.n < 5){
            alphas = [1.0,0.9,0];
            ratios = [0x64,0xc2,0xff];
        }else{
            alphas = [1,0.8,0];
            ratios = [0x0,0xc2,0xff];
        }
        //sp.graphics.lineStyle (1, 0x000000, 1.0);    // 線のスタイル
        sp.graphics.beginGradientFill (        // 面のスタイル
            GradientType.RADIAL,
            [argObj.fillColor , argObj.fillColor , argObj.fillColor],alphas,ratios,m);
        
        sp.graphics.drawCircle (p_x, p_y , radius);
        sp.x = 180;
        sp.y = 200;
    }
}

class move{
    private var count:int;
    //インスタンスメソッド
    public function movement(cubes_array:Array,mouse_Array:Array):Array {
        var _length:int = cubes_array.length;
        var _array:Array = new Array(_length);
        count++;
        var _rxy:Array = poz();
        var gPoz:Array = new Array(6);
        gPoz = [-10-(_rxy[0][1]+_rxy[1][1]+_rxy[2][1]+Math.cos(_rxy[2][0]*(2*Math.PI/360))*100/60)/3,50,-190+(_rxy[0][2]+_rxy[1][2]+_rxy[2][2]+Math.sin(_rxy[2][0]*(2*Math.PI/360))*100/60)/3,0.1*Math.PI/2+mouse_Array[1]/1000,mouse_Array[0]/1000,0];
        for (var j:int= 0; j<_length; j++){
            var i:int = Math.floor(j/(_length/3));
            var lPoz:Array = new Array(cubes_array[i].poz[0],cubes_array[i].poz[1],cubes_array[i].poz[2],cubes_array[i].poz[3],cubes_array[i].poz[4],cubes_array[i].poz[5]);
            lPoz[0] = _rxy[i][1];
            lPoz[2] = -_rxy[i][2];
            lPoz[4] = _rxy[i][0]/57.29;
            _array[j] = _mov(cubes_array[j],gPoz,lPoz);
        }
        return _array;
    }
    private function _mov(arg:Object,gPoz:Array,lPoz:Array):Array {
        var _length:int = arg.shape.length;
        var ar:Array = new Array(_length);
        for (var i:int= 0; i<_length; i++) {
            ar[i] = [arg.shape[i][0],arg.shape[i][1],arg.shape[i][2]];
        }
        return _pertrans(_affine(_affine(ar,lPoz),gPoz));
    }
    private function poz():Array {
        var date:Date = new Date();
        var h:int = date.getHours()-12;
        var m:int = date.getMinutes()-30;
        var s:int = date.getSeconds()-30;
        var rxy:Array = new Array(3);
        rxy[0] = [h,0,0];
        rxy[1] = [m,Math.cos(rxy[0][0]*(2*Math.PI/360))*100,Math.sin(rxy[0][0]*(2*Math.PI/360))*100];
        rxy[2] = [s,rxy[1][1]+Math.cos(rxy[1][0]*(2*Math.PI/360))*100,rxy[1][2]+Math.sin(rxy[1][0]*(2*Math.PI/360))*100];
        return rxy;
    }

    private function _pertrans(arg_array:Array):Array{
        var _length:int = arg_array.length;
        var _ar:Array = new Array(_length);
        for (var i:int = 0; i<_length; i++) {
            var _per:Number = 300/(300+arg_array[i][2]);
            _ar[i] = [arg_array[i][0]*_per,arg_array[i][1]*_per,_per];
        }
        return _ar;
    }
    private function _affine(data_array:Array,poz_array:Array):Array {
        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 dX:Number = poz_array[uint(0)];
        var dY:Number = poz_array[uint(1)];
        var dZ:Number = poz_array[uint(2)];
        var afXx:Number = cz*cy+sx*sy*sz;
        var afXy:Number = sx*sy*cz-sz*cy;
        var afXz:Number = sy*cx;
        var afYx:Number = cx*sz;
        var afYy:Number = cx*cz;
        var afYz:Number = -sx;
        var afZx:Number = cy*sx*sz-sy*cz;
        var afZy:Number = sy*sz+cy*sx*cz;
        var afZz:Number = cx*cy;
        var _length:uint = data_array.length;
        var ar:Array = new Array(_length);
        for (var i:uint = 0; i<_length; i++) {
            var afX:Number = data_array[i][uint(0)];
            var afY:Number = data_array[i][uint(1)];
            var afZ:Number = data_array[i][uint(2)];
            ar[i] = [afX*afXx+afY*afXy+afZ*afXz+dX,afX*afYx+afY*afYy+afZ*afYz+dY,afX*afZx+afY*afZy+afZ*afZz+dZ];
        }
        return ar;
    }
}