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

擬似球面体(2)

マウスクリックでエフェクトが発生
Get Adobe Flash player
by okoi 11 Sep 2010
    Embed
/**
 * Copyright okoi ( http://wonderfl.net/user/okoi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hJDn
 */

//
//    擬似球面体(2)
//        マウスクリックでエフェクトが発生
//
package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.display.GradientType;
    import flash.display.SpreadMethod;
    import flash.display.InterpolationMethod;

    
    [SWF(width = "465", height = "465")]
    
    /**
     * ...
     * @author okoi
     */
    public class Main extends Sprite 
    {
        private var _canvas:BitmapData;        
        private var _sphere:LightDotSphere;
        
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            var mat:Matrix = new Matrix();
            mat.createGradientBox( stage.stageWidth, stage.stageHeight, 90 );
            
            graphics.beginFill(0x0);
            graphics.beginGradientFill(
                GradientType.LINEAR,
                [0x000022, 0x000077],
                [1, 1],
                [0, 255],
                mat,
                SpreadMethod.PAD,
                InterpolationMethod.LINEAR_RGB,
                0.0 );        
            graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            graphics.endFill();
            
            _canvas = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0);
            addChild( new Bitmap(_canvas) );
            
            _sphere = new LightDotSphere();
            _sphere.x = stage.stageWidth / 2;
            _sphere.y = stage.stageHeight / 2;
            _sphere.CreateSphere();
            
            addEventListener(Event.ENTER_FRAME, Update);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown);
        }
        
        private    function Update(e:Event):void 
        {
            _sphere.Update();
            
            _canvas.lock();
        //    _canvas.fillRect( _canvas.rect, 0 );
            _canvas.applyFilter(_canvas, _canvas.rect, new Point(), new BlurFilter(2,2,1));
            _sphere.DrawSphere( _canvas );
            _canvas.unlock();
        }
        
        
        private function MouseDown(e:MouseEvent):void
        {
            _sphere.LightStart();
        }
        
    }
    
}
import flash.display.BitmapData;
import flash.geom.Rectangle;

import frocessing.color.ColorHSV;
//////////////////////////////////////////////
class Dot {
    
    protected var _xID:int;
    public function get xID():int { return _xID;    }
    protected var _yID:int;
    public function get yID():int { return _yID;    }
    
    protected var _defx:Number;
    protected var _defy:Number;
    
    protected var _x:Number;
    protected var _y:Number;
    protected var _z:Number;
    public    function get x():Number { return    _x;    }
    public    function get y():Number { return    _y;    }
    public    function get z():Number { return    _z;    }
    
    protected var _radius:Number;
    protected var _angle:Number;
    
    protected var _cos:Number;
    public    function get cos():Number { return    _cos;    }
        
    public    function get size():Number {
        return    4 + _cos * 3;
    }
    
    public function Dot (__xID:int,__yID:int,__defx:Number, __defy:Number,__radius:Number,__angle:Number) {
            
        _xID = __xID;
        _yID = __yID;
        _defx = __defx;
        _defy = __defy;
        _x = 0;
        _y = 0;
        _radius = __radius;
        _angle = __angle;
        
        UpdatePosition();
    }
    
    public function Update(rot:Number):void 
    {
        _angle = (_angle + rot) % 360;
        _cos = Math.cos( _angle * Math.PI / 180 );
        
        UpdatePosition();
    }
    
    private function UpdatePosition() : void 
    {
        _x = _defx + Math.sin( _angle * Math.PI / 180 ) * _radius;
        if ( _radius == 0 )
        {
            _y = _defy;
            _z = 0;
        }else
        {
            _y = _defy + Math.cos( _angle * Math.PI / 180 ) * 5;
            _z = Math.cos( _angle * Math.PI / 180 ) * _radius;    
        }
    }
}
///////////////////////////////////////////////
class LightDot extends Dot {
    
    protected var _flashFlag:Boolean;
    protected var _flashStep:int;
    protected var _flashSize:Number;
    
    protected static const FLASHFRAME:int = 5;
    
    protected var _color:ColorHSV;
    private var _colorS:Number;
    private var _colorA:Number;
    public function get color32():uint { return _color.value32;    }
    
    override public function get size():Number {
        return    (super.size + _flashSize);
    }
    
    
    public function LightDot(__xID:int,__yID:int,__defx:Number, __defy:Number,__radius:Number,__angle:Number) {
            
        super(__xID,__yID,__defx,__defy, __radius, __angle);
        
        _flashFlag = false;
        _flashStep = 0;
        _flashSize = 0;
        
        _colorS = 1;
        _colorA = 0.3;
        _color = new ColorHSV(200, _colorS, 1.0, _colorA);
        ColorInit();
    }
    
    override public function Update(rot:Number) : void
    {
        super.Update(rot);
        
        if ( _flashFlag )
        {
            var s:Number = Math.sin( _flashStep / FLASHFRAME * 180 * Math.PI / 180 );
            _flashSize = s * 3;
            _colorS = 1 - s/2;
            _colorA = 0.5 + s / 3;
            _color.s = _colorS;
            _color.a = _colorA;
            _flashStep++;
            if ( _flashStep >= FLASHFRAME ) FlashEnd();
        }
    }
    
    public function Flash() : void
    {
        _flashStep = 0;
        _flashFlag = true;
        _flashSize = 0;
    }
    
    private function FlashEnd() : void
    {
        _flashStep = 0;
        _flashFlag = false;
        _flashSize = 0;
        ColorInit();
    }
    
    private function ColorInit() : void
    {
        _color.h = 200;
        _color.s = 1;
        _color.v = 1;
        _color.a = 0.5;
    }
    
}
///////////////////////////////////////////////
class LightDotSphere {
    
    private var _x:Number = 0;
    private var _y:Number = 0;
    public function set x(val:Number):void { _x = val;    }
    public function set y(val:Number):void { _y = val;    }
    public function get x():Number { return    _x;    }
    public function get y():Number { return _y;    }
    
    private var _rot:Number;
    
    private var _dots:/*LightDot*/Array;
    private static const RADIUS:int = 200;
    private static const PATHNUM_X:int = 36;
    private static const PATHNUM_Y:int = 20;
    
    private var _flashCtrls:/*FlashControl*/Array = null;
    

    public function LightDotSphere() 
    {
        _flashCtrls = new Array();
    }
    
    public function CreateSphere() : void
    {
        _dots = new Array();
            
        for ( var py:int = 0; py < PATHNUM_Y; py++ )
        {
            var defy:Number = _y - Math.cos( py / PATHNUM_Y * 180 * Math.PI / 180 ) * RADIUS;
            for ( var px:int = 0; px < PATHNUM_X; px++ )
            {
                var radius:Number = RADIUS * Math.sin((py / PATHNUM_Y) * 180 * Math.PI / 180);
                var angle:Number = 360 * (px / PATHNUM_X);
                var dot:Dot = new LightDot(px,py,_x, defy, radius, angle );
                _dots[_dots.length] = dot;
            }
        }    
        
        _rot = 0;
    }
    
    public function Update() : void
    {
        var i:int;
        _rot = (_rot + 0.5) % 360;    
        
        
        for ( i = _flashCtrls.length - 1; i >= 0; i-- )
        {
            if ( !_flashCtrls[i].Step(_dots,PATHNUM_X,PATHNUM_Y) )
            {
                _flashCtrls.splice( i, 1 );
            }
        }
        
        var dotnum:int = _dots.length;
        for ( i = 0; i < dotnum; i++ )
        {
            _dots[i].Update(0.5);
        }
    }
    
    public function DrawSphere( canvas:BitmapData ) : void
    {
        var dotnum:int = _dots.length;
        
        for ( var i:int = 0; i < dotnum; i++ )
        {
            canvas.fillRect( new Rectangle( _dots[i].x -  _dots[i].size/2, _dots[i].y -  _dots[i].size/2, _dots[i].size, _dots[i].size ), _dots[i].color32 );
        }
    }
    
    public function LightStart() : void
    {        
        var val:int = int(Math.random() * 3);
        if ( val == 0 )
        {
            _flashCtrls[_flashCtrls.length] = new FlashControl1();
        }else
        if ( val == 1 )
        {
            _flashCtrls[_flashCtrls.length] = new FlashControl2();
        }else
        {
            _flashCtrls[_flashCtrls.length] = new FlashControl3();
        }
    }

}
/////////////////////////////////////////////////
class FlashControl {
    public var step:int;
    
    public function FlashControl() {
        step = 0;
    }
    
    public function Step(dots:/*LightDot*/Array, xnum:int, ynum:int) : Boolean
    {
        return false;
    }
}
class FlashControl1 extends FlashControl {
    public function FlashControl1() {
        super();
    }
    override public function Step(dots:/*LightDot*/Array, xnum:int, ynum:int) : Boolean
    {
        var dotnum:int = dots.length;
        for ( var i:int = 0; i < dotnum; i++ )
        {
            if ( dots[i].xID == step )    dots[i].Flash();
        }
        step++;
        if ( step == xnum ) return    false;
        return true;
    }
}
class FlashControl2 extends FlashControl {
    public function FlashControl2() {
        super();
    }
    override public function Step(dots:/*LightDot*/Array, xnum:int, ynum:int) : Boolean
    {
        var dotnum:int = dots.length;
        for ( var i:int = 0; i < dotnum; i++ )
        {
            if ( dots[i].yID == step )    dots[i].Flash();
        }
        step++;
        if ( step == ynum ) return    false;
        return true;
    }
}
class FlashControl3 extends FlashControl {
    public function FlashControl3() {
        super();
    }
    override public function Step(dots:/*LightDot*/Array, xnum:int, ynum:int) : Boolean
    {
        var dotnum:int = dots.length;
        
        var ratio:Number = (step / 300) * dotnum;
        var y:int = ratio / xnum;
        var x:int = ratio % xnum;
        
        for ( var i:int = 0; i < dotnum; i++ )
        {
            if ( dots[i].yID == y && Math.abs( dots[i].xID - x ) < 2 )    dots[i].Flash();
        }
        step++;
        if ( step == 300 ) return    false;
        return true;
    }
}