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: 重力マウス(シンクロカラー)

リンクリストにしてみたけどそんなに速くない??
_bmd.fillRect()を_bmd.setPixel()に変更。
sin(),cos(),atan2(),sqrt()を排除。
パーティクルの多色化&モーションシンクロ
/**
 * Copyright Aquioux ( http://wonderfl.net/user/Aquioux )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/b3ru
 */

// 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()を排除。
// パーティクルの多色化&モーションシンクロ
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='465', height='465', backgroundColor='0x0')]

	public class ParticleTest1 extends Sprite
	{
		private var _bmd:BitmapData;
		
		private var _first1:Node;
		private var _first2:Node;
		private var _first3:Node;
		private var _first4:Node;
		
		private const NUM_OF_PARTICLE:int = 12500;
		private const OFFSET:uint = 120;

		private const RECT:Rectangle = new Rectangle(0, 0, 465, 465);
		private const CT:ColorTransform = new ColorTransform(1.0, 1.0, 1.0, 0.92);


		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);

			_bmd = new BitmapData(465, 465, false, 0x000000);
			addChild(new Bitmap(_bmd));

			var old1:Node;
			var old2:Node;
			var old3:Node;
			var old4:Node;
			for (var i:int = 0; i < this.NUM_OF_PARTICLE; i++)
			{
				var n1:Node = new Node();
				var n2:Node = new Node();
				var n3:Node = new Node();
				var n4:Node = new Node();
				n1.pos_x = Math.random() * 465;
				n1.pos_y = Math.random() * 465;
				n2.pos_x = Math.random() * 465;
				n2.pos_y = Math.random() * 465;
				n3.pos_x = Math.random() * 465;
				n3.pos_y = Math.random() * 465;
				n4.pos_x = Math.random() * 465;
				n4.pos_y = Math.random() * 465;
				// リンクリスト
				if (_first1 == null) {
					old1 = _first1 = n1;
					old2 = _first2 = n2;
					old3 = _first3 = n3;
					old4 = _first4 = n4;
				} else {
					old1.next = n1;
					old1 = n1;
					old2.next = n2;
					old2 = n2;
					old3.next = n3;
					old3 = n3;
					old4.next = n4;
					old4 = n4;
				}
			}
			
			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 n1:Node = _first1;
			var n2:Node = _first2;
			var n3:Node = _first3;
			var n4:Node = _first4;

			this._bmd.lock();

			do
			{
				var diff_x1:Number = gravPoint_x - n1.pos_x - OFFSET;
				var diff_y1:Number = gravPoint_y - n1.pos_y - OFFSET;
				var diff_x2:Number = gravPoint_x - n2.pos_x + OFFSET;
				var diff_y2:Number = gravPoint_y - n2.pos_y - OFFSET;
				var diff_x3:Number = gravPoint_x - n3.pos_x - OFFSET;
				var diff_y3:Number = gravPoint_y - n3.pos_y + OFFSET;
				var diff_x4:Number = gravPoint_x - n4.pos_x + OFFSET;
				var diff_y4:Number = gravPoint_y - n4.pos_y + OFFSET;

				var acc1:Number = 25 / (diff_x1 * diff_x1 + diff_y1 * diff_y1);
				var acc_x1:Number = acc1 * diff_x1;
				var acc_y1:Number = acc1 * diff_y1;
				var acc2:Number = 25 / (diff_x2 * diff_x2 + diff_y2 * diff_y2);
				var acc_x2:Number = acc2 * diff_x2;
				var acc_y2:Number = acc2 * diff_y2;
				var acc3:Number = 25 / (diff_x3 * diff_x3 + diff_y3 * diff_y3);
				var acc_x3:Number = acc3 * diff_x3;
				var acc_y3:Number = acc3 * diff_y3;
				var acc4:Number = 25 / (diff_x4 * diff_x4 + diff_y4 * diff_y4);
				var acc_x4:Number = acc4 * diff_x4;
				var acc_y4:Number = acc4 * diff_y4;

				n1.v_x += acc_x1;
				n1.v_y += acc_y1;
				n1.pos_x += n1.v_x;
				n1.pos_y += n1.v_y;
				n1.v_x *= 0.96;
				n1.v_y *= 0.96;
				n2.v_x += acc_x2;
				n2.v_y += acc_y2;
				n2.pos_x += n2.v_x;
				n2.pos_y += n2.v_y;
				n2.v_x *= 0.96;
				n2.v_y *= 0.96;
				n3.v_x += acc_x3;
				n3.v_y += acc_y3;
				n3.pos_x += n3.v_x;
				n3.pos_y += n3.v_y;
				n3.v_x *= 0.96;
				n3.v_y *= 0.96;
				n4.v_x += acc_x4;
				n4.v_y += acc_y4;
				n4.pos_x += n4.v_x;
				n4.pos_y += n4.v_y;
				n4.v_x *= 0.96;
				n4.v_y *= 0.96;
				/*
				if (n1.pos_x > 465) {
					n1.pos_x = 0;
				} else if (n1.pos_x < 0) {
					n1.pos_x = 465;
				}
				if (n1.pos_y > 465) {
					n1.pos_y = 0;
				} else if (n1.pos_y < 0) {
					n1.pos_y = 465;
				}
				if (n2.pos_x > 465) {
					n2.pos_x = 0;
				} else if (n2.pos_x < 0) {
					n2.pos_x = 465;
				}
				if (n2.pos_y > 465) {
					n2.pos_y = 0;
				} else if (n2.pos_y < 0) {
					n2.pos_y = 465;
				}
				if (n3.pos_x > 465) {
					n3.pos_x = 0;
				} else if (n3.pos_x < 0) {
					n3.pos_x = 465;
				}
				if (n3.pos_y > 465) {
					n3.pos_y = 0;
				} else if (n3.pos_y < 0) {
					n3.pos_y = 465;
				}
				if (n4.pos_x > 465) {
					n4.pos_x = 0;
				} else if (n4.pos_x < 0) {
					n4.pos_x = 465;
				}
				if (n4.pos_y > 465) {
					n4.pos_y = 0;
				} else if (n4.pos_y < 0) {
					n4.pos_y = 465;
				}
				*/
				this._bmd.setPixel(n1.pos_x, n1.pos_y, 0xFF0033);
				this._bmd.setPixel(n2.pos_x, n2.pos_y, 0xFFCC00);
				this._bmd.setPixel(n3.pos_x, n3.pos_y, 0x66FF66);
				this._bmd.setPixel(n4.pos_x, n4.pos_y, 0x3366FF);
			}
			while (n1 = n1.next, n2 = n2.next, n3 = n3.next, n4 = n4.next);

			this._bmd.colorTransform(this.RECT, this.CT);
			this._bmd.unlock();
		}
	}
}


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;
}