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

forked from: forked from: 重力マウス(ちょっぴり軽量化してみた)

リンクリストにしてみたけどそんなに速くない??
/**
 * Copyright dodidodidodi ( http://wonderfl.net/user/dodidodidodi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lLbq
 */

// forked from paq's forked from: 重力マウス(ちょっぴり軽量化してみた)
// forked from fumix's 重力マウス(リンクリストにしてみた)
// forked from undo's 重力マウス
// リンクリストにしてみたけどそんなに速くない??
package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.ColorTransform;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import net.hires.debug.Stats;

    [SWF(frameRate='60', width='1900', height='1200', backgroundColor='0x0')]

    public class ParticleTest1 extends Sprite
    {
        private var _bmp:Bitmap;
        private var _bmd:BitmapData;
        private var _bmdRect:Rectangle;


        private var _colorTransform:ColorTransform = new ColorTransform( 0.9, 0.9, 0, 1);

        private var _nodeArray:Array = [];
        private var _first:Node;
        private var _maxNum:int = 30000;
        
        

        public function ParticleTest1()
        {
            this.stage.align = StageAlign.TOP_LEFT;
            this.stage.scaleMode = StageScaleMode.NO_SCALE;
            addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(evt:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            var old:Node;

            _bmd = new BitmapData(1900, 1200, false, 0xffffff);
            _bmp = new Bitmap(_bmd);
            addChild(_bmp);
            this._bmdRect = new Rectangle(0, 0, 1900, 1200);

            for (var i:int = 0; i < this._maxNum; i++)
            {
                var n:Node = new Node();
                n.pos_x = Math.random() * 1900;
                n.pos_y = Math.random() * 1200;
                this._nodeArray.push(n);
                //リンクリスト
                if (_first == null) {
                    old = _first = n;
                } else {
                    old.next = n;
                    old = n;
                }
            }
            
            addChild(new Stats());
            addEventListener(Event.ENTER_FRAME, onEnter);
        }

        private function onEnter(evt:Event):void
        {
            //var gravPoint:Point = new Point(mouseX, mouseY);
            var gravPoint_x:Number = mouseX;
            var gravPoint_y:Number = mouseY;
            var n:Node = _first;
            this._bmd.lock();
            do
            {
                //var n:Node = this._nodeArray[i] as Node;
                //var diff:Point = new Point(gravPoint.x - n.pos.x, gravPoint.y - n.pos.y);
                var diff_x:Number = gravPoint_x - n.pos_x;
                var diff_y:Number = gravPoint_y - n.pos_y;
                var rad:Number = Math.atan2(diff_y, diff_x);
                var grav:Number = 50 / Math.sqrt(diff_x * diff_x + diff_y * diff_y);
                n.acc_x = (Math.cos(rad) * grav);
                n.acc_y = (Math.sin(rad) * grav);
                n.v_x += n.acc_x;
                n.v_y += n.acc_y;
                n.pos_x += n.v_x;
                n.pos_y += n.v_y;
                n.acc_x *= 0.98;
                n.acc_y *= 0.98;
                n.v_x *= 0.96;
                n.v_y *= 0.96
                if (n.pos_x > 1900)
                    n.pos_x = 0;
                else if (n.pos_x < 0)
                    n.pos_x = 1900;
                if (n.pos_y > 1200)
                    n.pos_y = 0;
                    
                else if (n.pos_y < 0)
                    n.pos_y = 1200;
                var _rect:Rectangle = new Rectangle(0, 0, Math.random() * 5, Math.random() * 5);
                var _color:uint = 
                _rect.x = n.pos_x;
                _rect.y = n.pos_y;
                this._bmd.fillRect(_rect, 0x000000 + Math.random() * 0xFFFFFF);
              
            }
            while (n = n.next);
            this._bmd.colorTransform(this._bmdRect, this._colorTransform);
            this._bmd.unlock();
        }
    }
}

import flash.geom.Point;

class Node
{
    public var acc_x:Number;
    public var acc_y:Number;
    public var v_x:Number = 0;
    public var v_y:Number = 0;
    public var pos_x:Number = 0;
    public var pos_y:Number = 0;
    public var next:Node;
}