forked from: Shaaa ...Zaaam !!!

by s8t1h12akj forked from Shaaa ...Zaaam !!! (diff: 121)
SHAA ...ZAAM ! by the FLAHMAFIA
~ lil' optimizations & tweaks ~
♥0 | Line 192 | Modified 2014-03-23 21:57:43 | MIT License
play

ActionScript3 source code

/**
 * Copyright s8t1h12akj ( http://wonderfl.net/user/s8t1h12akj )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7pF5
 */

package {
    import flash.display.GradientType;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.display.StageQuality;
    import flash.events.Event;
    import flash.filters.BitmapFilterQuality;
    import flash.filters.GlowFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;

    [SWF(width='465', height='465', frameRate='45', backgroundColor='0x00000')]
    public class ShaaaZaaam extends Sprite {
        //
        public static const SW : Number = 465;
        public static const SH : Number = 465;
        private static const MAXLIGHTS : uint = 150;
        private const STARTRADIUS : Number = 32;
        //
        private var _bg : Shape;
        private var _container : Sprite;
        private var _lights : Vector.<Light>;
        private var _lum : Number;
        private var _ct : ColorTransform;
        private var _rotation : Number;

        public function ShaaaZaaam() {
            super();

            stage.quality = StageQuality.LOW;
            mouseEnabled = mouseChildren = tabEnabled = tabChildren = false;

            _lum = Math.PI / 2;
            _ct = new ColorTransform();

            var m : Matrix = new Matrix();
            var a : int = Math.min(SW, SH);
            m.createGradientBox(a, a, 0, (SW - a) * 0.5, (SH - a) * 0.5);

            addChild(_bg = new Shape());
            _bg.filters = [new GlowFilter(0x00000, 0.22, SW / 4, SH / 4, 2, BitmapFilterQuality.HIGH, true)];
            _bg.graphics.beginGradientFill(GradientType.RADIAL, [0xFFFFFF, 0x808080], [1, 1], [0x00, 0xFF], m);
            _bg.graphics.drawRect(0.0, 0.0, SW, SH);
            _bg.graphics.endFill();
            _bg.opaqueBackground = _bg.cacheAsBitmap = true;

            addChild(_container = new Sprite());
            _container.x = SW / 2;
            _container.y = SH / 2;

            _lights = new Vector.<Light>(MAXLIGHTS, true);
            var n : uint = _lights.length;
            while (n-- != 0) _container.addChild(_lights[n] = new Light());

            _rotation = 0.0;

            addEventListener(Event.ENTER_FRAME, update);
        }

        private function update(e : Event) : void {
            // animate lum
            _lum += 0.0088;
            var lumSin : Number = Math.sin(_lum);

            // reset
            for each (var light : Light in _lights) {
                var rnd : Number = lumSin * Math.random();

                if (light.invAlpha < 0.01) {
                    light.invAlpha = 0.1 + 0.9 * rnd;
                    light.rotation = 360 * 3 * rnd;
                    var angle : Number = light.rotation / 360 * Math.PI * 2;

                    light.speed = 1 + light.invAlpha;
                    light.x = (light.dx = Math.cos(angle)) * light.speed * STARTRADIUS;
                    light.y = (light.dy = Math.sin(angle)) * light.speed * STARTRADIUS;
                }

                // animate light
                light.alpha = 1 - (light.invAlpha *= 0.8);
                light.speed *= 1.11;
                light.x += light.dx * light.speed;
                light.y += light.dy * light.speed;
            }

            // animate light space
            _container.rotation += 2.0;

            // apply lum
            _ct.redMultiplier = (_ct.greenMultiplier = (_ct.blueMultiplier = lumSin) * 0.9) * 0.9;
            _bg.transform.colorTransform = _ct;
        }
    }
}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.Shape;
import flash.filters.BitmapFilterQuality;
import flash.filters.BlurFilter;

class Light extends Bitmap {
    //
    private const BLUR : Number = 2;
    //
    public var dx : Number;
    public var dy : Number;
    public var speed : Number;
    public var invAlpha : Number;

    public function Light() {
        var length : Number = 4 + 24 * Math.random();
        var line : Shape = new Shape();
        line.graphics.lineStyle(0, 0xFFFFFF);
        line.graphics.moveTo(BLUR, BLUR);
        line.graphics.lineTo(BLUR + length, BLUR);
        line.filters = [new BlurFilter(BLUR, BLUR, BitmapFilterQuality.HIGH)];

        super(new BitmapData(length + BLUR * 2, BLUR * 2, true, 0x00000000));
        bitmapData.draw(line);

        blendMode = BlendMode.ADD;

        invAlpha = alpha = 0.0;
    }
}
{
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Matrix3D;
    
    [SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="30")]
    
    class Main extends Sprite
    {
        private var container:Sprite;
        private var cube:Sprite;
        private var objects:Array;
        private var planes:Array;
        private var xx:Number
        private var ss:Number;
        private var planeN:int;
        
        // ジャンプする度合いを決める定数
        private const k:Number=20;
        
        public function Main()
        {
            container=addChild(new Sprite) as Sprite;
            container.x=465 / 2;
            container.y=465 / 2;
            container.scaleX=container.scaleY=container.scaleZ=0.15;
            container.rotationX=50;
            container.rotationY=40;
            planeN=xx=ss=0;
            cube=container.addChild(new Sprite) as Sprite;
            objects = [];
            objects.push(cube);
            planeN++;
            
            // Cubeを作る
            planes = [];
            planes.push(createPlane(0, 90, 50, 0, 0, cube, Math.random()*0xffffff));
            planes.push(createPlane(0, -90, -50, 0, 0, cube, Math.random()*0xffffff));
            planes.push(createPlane(-90, 0, 0, -50, 0, cube, Math.random()*0xffffff));
            planes.push(createPlane(90, 0, 0, 50, 0, cube, Math.random()*0xffffff));
            planes.push(createPlane(0, 0, 0, 0, -50, cube, Math.random()*0xffffff));
            planes.push(createPlane(0, 0, 0, 0, 50, cube, Math.random()*0xffffff));
            
            var h:int=-50;
            var s:Number=0;
            for(var i:int=0; i < 140; i++)
            {                
                objects.push(createPlane(90, 0, 1.1 * s * Math.cos(s * Math.PI / 180), -h, 1.1 * s * Math.sin(s * Math.PI / 180), container, 0x00ff00));
                h+=10;
                s+=20;
                planeN++;
            }
            
            addEventListener(Event.ENTER_FRAME, onFrame);
        }
        
        // 平面を作成する関数
        private function createPlane(rotationX:Number, rotationY:Number ,x:Number, y:Number, z:Number, sp:Sprite, color:uint):Sprite
        {
            var shape:Sprite = sp.addChild(new Sprite) as Sprite;
            var g:Graphics = shape.graphics;
            g.beginFill(color, 0.6);
            g.drawRect(-50, -50, 100, 100);
            g.endFill();
            
            shape.rotationX = rotationX;
            shape.rotationY = rotationY;
            shape.x = x;
            shape.y = y;
            shape.z = z;
            
            return shape;
        }
        
        private function onFrame(e:Event):void
        {
            cube.z=1.1 * ss * Math.sin(ss * Math.PI / 180);
            cube.x=1.1 * ss * Math.cos(ss * Math.PI / 180);
            cube.y=-10 * (-1 * (2 * k - 1 + 2 * Math.sqrt(k * k - k)) * (xx - k + Math.sqrt(k * k - k) - Math.floor(xx)) * (xx - k + Math.sqrt(k * k - k) - Math.floor(xx)) + k + Math.floor(xx));
            
            xx+=0.05;
            ss+=1;
            
            // 色々ソート
            var array:Array=[];
            for(var i:int=0; i < 6; i++)
            {
                var shape:Sprite = planes[i];
                var mat:Matrix3D=shape.transform.getRelativeMatrix3D(this);
                array.push({sp:shape, z:mat.position.z});
            }
            array.sortOn("z", Array.NUMERIC | Array.DESCENDING);
            for(i=0; i < 6; i++)
            {
                shape = array[i].sp as Sprite;
                cube.setChildIndex(shape, i);
            }
            array=[];
            for(i=0; i < planeN; i++)
            {
                shape = objects[i] as Sprite;
                mat=shape.transform.getRelativeMatrix3D(this);
                array.push({sp:shape, z:mat.position.z});
            }
            array.sortOn("z", Array.NUMERIC | Array.DESCENDING);
            for(i=0; i < planeN; i++)
            {
                shape = array[i].sp as Sprite;
                container.setChildIndex(shape, i);
            }
        }
    }
}