重力マウス(100万パーティクル)
リンクリストにしてみたけどそんなに速くない??
_bmd.fillRect()を_bmd.setPixel()に変更。
sin(),cos(),atan2(),sqrt()を排除。
Add final class / mouseEnalbled = false by clockmake
Use setVector & getVector by shohei909
/**
* Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lPGq
*/
// 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.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;
import flash.display.BitmapData;
[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.875, 0.75, 0.50, 1.0);
private var _first:Node;
function ParticleTest1()
{
const _maxNum:uint = 1000000;
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:uint = 0; i < _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);
_bmd.lock();
stage.addChild( new Stats() ).cacheAsBitmap = false;
stage.removeChildAt(0);
addEventListener( "exitFrame", frame )
}
final private function frame( e:Event ):void{
const rect:Rectangle = _bmd.rect;
const gx:Number = mouseX, gy:Number = mouseY, vec:Vector.<uint> = _bmd.getVector(rect);
vec.fixed = true;
var n:Node = _first;
do{
var p0:Number, p1:Number, p2:Number, p3:Number;
const diff_x:Number = gx - ( p0 = n.pos_x += p2 = n.v_x );
const diff_y:Number = gy - ( p1 = n.pos_y += p3 = n.v_y );
const acc:Number = 256 / (diff_x * diff_x + diff_y * diff_y + 1);
n.v_x = p2 * 0.875 + acc * diff_x;
n.v_y = p3 * 0.875 + acc * diff_y;
if( (p0>>>=0) < 465 && (p1>>>=0) < 465 ){ vec[(p0 + p1*465)>>>0] = 0xffffff }
}while( (n = n.next) !== null );
_bmd.setVector( rect, vec );
_bmd.colorTransform( rect, this._colorTransform );
_bmd.unlock();
_bmd.lock();
}
}
}
final internal 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;
}