重力マウス(ダイイングメッセージ)
リンクリストにしてみたけどそんなに速くない??
_bmd.fillRect()を_bmd.setPixel()に変更。
sin(),cos(),atan2(),sqrt()を排除。
Add final class / mouseEnalbled = false by clockmaker
/**
* Copyright dice ( http://wonderfl.net/user/dice )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rYBh
*/
// forked from dice's 重力マウス(ハーティクル)
// forked from fumix's forked from: 重力マウス(プチ軽量化:10万パーティクル)
// 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 clockmaker
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 flash.text.TextField;
import flash.text.TextFormat;
import net.hires.debug.Stats;
[SWF(frameRate='60', width='465', height='465', backgroundColor='0x0')]
import flash.utils.Dictionary;
public class Yasu extends Sprite
{
private const MARK:String = " くそっやられた犯人は ヤス";
private var _bmp:Bitmap;
private var _bmd:BitmapData;
private var _bmdRect:Rectangle;
private var _colorTransform:ColorTransform = new ColorTransform(0.9, 0.1, 0.1, 1,0,1);
private var _bmd_h:BitmapData;
private var _first:Node;
private var _maxNum:int = 50000;
private var _cnt:int = 0;
public function Yasu()
{
if(stage) init(null);
else addEventListener(Event.ADDED_TO_STAGE, init);
return;
}
private function init(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
this.stage.align = StageAlign.TOP_LEFT;
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.quality = "low";
this.stage.frameRate = 120;
this.mouseEnabled = false;
this.mouseChildren = false;
var old:Node;
_bmd = new BitmapData(465, 465, false, 0x000000);
_bmp = new Bitmap(_bmd);
addChild(_bmp);
this._bmdRect = _bmd.rect;
var i:int;
for (i = 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 tf:TextFormat = new TextFormat(null, 128, 0xffffff);
var txts:Vector.<TextField> = new Vector.<TextField>(9);
for (i = 0; i < 16; i++) {
txts[i] = new TextField();
txts[i].defaultTextFormat = tf;
txts[i].autoSize = "center";
txts[i].text = MARK.substr(i,1);
txts[i].x = ((465 / 8) * (i%4*2+1)) - txts[i].width / 2;
txts[i].y = ((465 / 8) * (int(i/4)*2+1)) - txts[i].height / 2;
addChild(txts[i]);
}
_bmd_h = new BitmapData(465, 465, false, 0);
_bmd_h.draw(this);
for (i = 0; i < 16; removeChild(txts[i++]) ){};
txts = null;
addChild(new Stats());
addEventListener(Event.ENTER_FRAME, onEnter);
}
private function onEnter(evt:Event):void
{
var gravPoint_x:Number = mouseX;
var gravPoint_y:Number = mouseY;
var n:Node = _first;
//var calc:Boolean = _cnt % 4 == 0;
this._bmd.lock();
this._bmd.colorTransform(this._bmdRect, this._colorTransform);
do
{
// 4回に1回ぐらいの処理に
//if(calc){
var diff_x:Number = gravPoint_x - n.pos_x;
var diff_y:Number = gravPoint_y - n.pos_y;
var acc:Number = 200 / (diff_x * diff_x + diff_y * diff_y);
var acc_x:Number = acc * diff_x;
var acc_y:Number = acc * diff_y;
n.v_x += acc_x;
n.v_y += acc_y;
//}
n.pos_x += n.v_x;
n.pos_y += n.v_y;
if(_bmd_h.getPixel(n.pos_x,n.pos_y) != 0){
n.v_x *= 0.2;
n.v_y *= 0.2;
} else {
n.v_x *= 0.95;
n.v_y *= 0.95;
}
/*
if(calc)
{
if (n.pos_x > 465)
n.pos_x -= 465;
else if (n.pos_x < 0)
n.pos_x += 465;
if (n.pos_y > 465)
n.pos_y -= 465;
else if (n.pos_y < 0)
n.pos_y += 465;
}
*/
this._bmd.setPixel(n.pos_x >> 0, n.pos_y >> 0, 0xff0000);
}
while (n = n.next);
this._bmd.unlock();
//_cnt ++;
}
}
}
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;
}