forked from: 重力マウス(もっと軽量化:20万パーティクル)
forked from 重力マウス(もっと軽量化:20万パーティクル) (diff: 2)
リンクリストにしてみたけどそんなに速くない?? _bmd.fillRect()を_bmd.setPixel()に変更。 sin(),cos(),atan2(),sqrt()を排除。 Add final class / mouseEnalbled = false by clockmake Use setVector & getVector by shohei909
ActionScript3 source code
/**
* Copyright xSonoSx ( http://wonderfl.net/user/xSonoSx )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/bLB8
*/
// forked from shohei909's 重力マウス(もっと軽量化:20万パーティクル)
// forked from clockmaker's 重力マウス(プチ軽量化:10万パーティクル)
// forked from coppieee's 重力マウス(さらに軽量化してみた)
// forked from paq's forked from: 重力マウス(ちょっぴり軽量化してみた)
// forked from fumix's 重力マウス(リンクリストにしてみた)
// forked from undo's 重力マウス
// リンクリストにしてみたけどそんなに速くない??
//_bmd.fillRect()を_bmd.setPixel()に変更。
//sin(),cos(),atan2(),sqrt()を排除。
// Add final class / mouseEnalbled = false by clockmake
// Use setVector & getVector by shohei909
package
{
import flash.utils.ByteArray;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.geom.ColorTransform;
import flash.geom.Rectangle;
import net.hires.debug.Stats;
[SWF(frameRate='60', width='465', height='465', backgroundColor='0x0')]
final public class ParticleTest1 extends Sprite
{
private const _bmd:BitmapData = new BitmapData(465, 465, false, 0x000000);
private const _colorTransform:ColorTransform = new ColorTransform(0.75, 0.50, 0.875, 1.0);
private var _first:Node;
private const _maxNum:int = 200000;
function ParticleTest1()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
final private function init(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
this.stage.align = "topLeft";
this.stage.scaleMode = "noScale";
this.stage.quality = "low";
this.stage.frameRate = 60;
//this.stage.colorCorrection = "off";
stage.mouseChildren = false;
stage.tabChildren = false;
var old:Node;
for (var i:int = 0; i < this._maxNum; i++)
{
var n:Node = new Node();
n.pos_x = Math.random() * 465 >> 0;
n.pos_y = Math.random() * 465 >> 0;
//リンクリスト
if (_first == null) {
old = _first = n;
} else {
old.next = n;
old = n;
}
}
var bitmap:Bitmap = new Bitmap(_bmd,"never",false);
bitmap.cacheAsBitmap = false;
stage.addChild(bitmap);
this._bmd.lock();
stage.addChild( new Stats() ).cacheAsBitmap = false;
stage.removeChildAt(0);
addEventListener(Event.EXIT_FRAME, frame);
}
final private function frame(e:Event):void
{
const gravPoint_x:int = mouseX, gravPoint_y:int = mouseY;
var n:Node = _first,p1:int, p0:int;
const vec:Vector.<uint> = _bmd.getVector(this._bmd.rect);
var diff_x:int,diff_y:int,acc:Number,p2:Number, p3:Number;
do
{
diff_x = gravPoint_x - (p0 = n.pos_x += p2 = n.v_x)
diff_y = gravPoint_y - (p1 = n.pos_y += p3 = n.v_y)
acc = 200 / (diff_x * diff_x + diff_y * diff_y + 2)
n.v_x = (p2*0.875 + acc * diff_x)
n.v_y = (p3*0.875 + acc * diff_y)
if( p0 >= 0 ){ if( p0 < 465 ){ if( p1 >= 0 ){ if( p1 < 465 ){
vec[(p0 + p1*465)>>>0] = 0xffffff;
}else{ n.pos_y -= 465 }
}else{ n.pos_y += 465 }
}else{ n.pos_x -= 465 }
}else{ n.pos_x += 465 }
}while (n = n.next)
//_bmd.setVector(this._bmd.rect, vec);
_bmd.colorTransform(this._bmd.rect, this._colorTransform);
_bmd.unlock();
_bmd.lock();
}
}
}
final class Node
{
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 = null;
}