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

重力

Get Adobe Flash player
by shohei909 28 Nov 2010
/**
 * Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/s9DM
 */

// forked from wsapl's 吸引力
package
{
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    [SWF(frameRate="60",backgroundColor="0x222222")]
    public class Suitori extends Sprite
    {
        private var lines:Vector.< Vector.< Anchor > > = new Vector.< Vector.< Anchor > >();
        
        private var mouse_down:Boolean;
        private var speed:Number=0;
        private var cnt:int;
        private var suck_btn:Sprite;
        private var _sucking:Boolean;
        
        private var bx:Number;
        private var by:Number;
        private var r:Number = 4;
        private var r2:Number = r*r;
        
        public function Suitori()
        {
            
           
            stage.addEventListener(MouseEvent.MOUSE_DOWN,_mouseDown);
            stage.addEventListener(MouseEvent.MOUSE_MOVE,_mouseMove);
            stage.addEventListener(MouseEvent.MOUSE_UP,_mouseUp);
            
            addEventListener( Event.ENTER_FRAME,_enterFrame );
            
            //吸引開始
            //sucking(mouseX,mouseY);
        }
        
        private function _mouseMove(event:MouseEvent):void{
            var dx:int = bx - mouseX;
            var dy:int = by - mouseY;
            var diff:Number = dx*dx + dy*dy
            if( mouse_down && r2 < diff  ){
                if( lines.length > 0 ){
                    var anc:Anchor = new Anchor( mouseX, mouseY )
                    lines[ lines.length - 1 ].push( anc );
                    bx = mouseX;
                    by = mouseY;
                }
            }
        }
        
        private function _mouseUp(event:MouseEvent):void{
            mouse_down=false;
        }
        
        private function _mouseDown(event:MouseEvent):void{
            mouse_down=true;
            lines.push(     
                Vector.<Anchor>( [ new Anchor( mouseX, mouseY ) ] ) 
            );
            bx = mouseX;
            by = mouseY;
        }
        
        private function _enterFrame(event:Event):void{
            var g:Graphics = graphics;
            g.clear();
            var ll:int = lines.length;
            
            for( var j:int = 0; j < ll; j++ ){
                var line:Vector.<Anchor> = lines[j]
                var cnt:int = 0;
                var al:int = line.length;
                for( var i:int = 0; i < al; i++ ){
                    var anc:Anchor = line[i] 
                    anc.time++;
                    if( anc.time > anc.start ){
                        if( cnt == 0 ){ g.moveTo( anc.x, anc.y ); }
                        else{ 
                            anc.colorHSV.h++;
                            g.lineStyle( anc.thickness, anc.color() );
                            g.lineTo( anc.x, anc.y );
                        }
                        cnt++;
                    }
                    if( anc.time > anc.move ){
                        var dx:Number = mouseX - anc.x;
                        var dy:Number= mouseY - anc.y;
                        var diff:Number = Math.sqrt(dx * dx + dy * dy);
                        anc.x += anc.vx;
                        anc.y += anc.vy;
                        if( diff != 0){
                            anc.vx += dx/diff * 1;
                            anc.vy += dy/diff * 1;
                            anc.vx *= 0.995;
                            anc.vy *= 0.995;
                        }
                    }
                    if( anc.time > anc.end ){
                        line.splice( i, 1 );
                        i--; al--;
                    }
                }
                if( line.length < 1 ){
                    lines.splice( j, 1 );
                    j--; ll--;
                }
            }
        }
        
    }
}

import frocessing.color.ColorHSV;
    
class Anchor{
    public var vx:Number = 0;
    public var vy:Number = 0;
    public var x:Number;
    public var y:Number;
    public var time:int = 0; 
    public var start:int = 50;
    public var move:int = 300;
    public var end:int = 900;
    public var thickness:Number = 2.5;
    public var colorHSV:ColorHSV = new ColorHSV(0,0.8,0.8);
    function Anchor( x:Number, y:Number ){
        this.x = x;
        this.y = y;
    }
    public function color():uint{
        return colorHSV.value;
    }

}