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

虹色重力マウス(5000パーティクル)

リンクリストにしてみたけどそんなに速くない??
_bmd.fillRect()を_bmd.setPixel()に変更。
sin(),cos(),atan2(),sqrt()を排除。
Add final class / mouseEnalbled = false by clockmaker
CJ Cat: Used vector instead of linked list.
/**
 * Copyright s26 ( http://wonderfl.net/user/s26 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wlK6
 */

// forked from cjcat2266's 重力マウス(プチ軽量化:25万パーティクル)
// 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
// CJ Cat: Used vector instead of linked list.
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.utils.ByteArray;
	import frocessing.color.*;
import net.hires.debug.Stats;
	[SWF(frameRate='60', width='465', height='465', backgroundColor='0x0')]

	import flash.utils.Dictionary;
	public class main extends Sprite {
		private var _bmp:Bitmap;
		private var _bmd:BitmapData;
		private var _bmdRect:Rectangle;
		private var _colorTransform:ColorTransform = new ColorTransform(0.99, 0.99, 0.99, 1.0);

		private const _maxNum:int = 5000; //50万パーティクルでも45fpsぐらいでる
		private var _cnt:int = 0;
		
		private const _particleData:Vector.<Number> = new Vector.<Number>(_maxNum * 4, true);
		

		public function main() {
			if(stage) init(null);
			else addEventListener(Event.ADDED_TO_STAGE, init);
			return;
		}
		
		private var kyori:Number
		private var hsv : ColorHSV 
		private function init(evt:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			kyori = Point.distance(new Point(0,0),new Point(stage.stageWidth,stage.stageHeight));
			hsv = new ColorHSV(0, 1, 1);
			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;
		
			_bmd = new BitmapData(465, 465, false, 0x000000);
			_bmp = new Bitmap(_bmd);
			addChild(_bmp);
			this._bmdRect = _bmd.rect;
			
			var i0:int, i1:int, i2:int, i3:int;
			i0 = 0;
			while (i0 < _maxNum) {
				i1 = i0;
				i2 = ++i1;
				i3 = ++i2;
				i3++;
				
				_particleData[i0] = Math.random() * 465 >> 0;
				_particleData[i1] = Math.random() * 465 >> 0;
				_particleData[i2] = 0;
				_particleData[i3] = 0;
				
				i0 = ++i3;
			}
			addChild(new Stats());
			addEventListener(Event.ENTER_FRAME, onEnter);
		}

		private function onEnter(evt:Event):void {
			//var ccc = ((Math.sin(new Date().getTime()/700)+1)/2)%360
			var ccc = new Date().getTime()/2000
			var gravPoint_x:Number = mouseX;
			var gravPoint_y:Number = mouseY;
			//var n:Node = _first;
			var calc:Boolean = _cnt % 4 == 0;
			
			this._bmd.lock();
			
			var i0:int, i1:int, i2:int, i3:int;
			i0 = 0;
			while (i0 < _maxNum)
			{
				i1 = i0;
				i2 = ++i1;
				i3 = ++i2;
				i3++;
				
				// 4回に1回ぐらいの処理に
				if(calc){
					var diff_x:Number = gravPoint_x - _particleData[i0];;
					var diff_y:Number = gravPoint_y - _particleData[i1];
					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;
					_particleData[i2] += acc * diff_x;
					_particleData[i3] += acc * diff_y;
				}
				
				_particleData[i0] += _particleData[i2];
				_particleData[i1] += _particleData[i3];
				
				_particleData[i2] *= 0.96;
				_particleData[i3] *= 0.96;
				
				if(calc)
				{
					if (_particleData[i0] > 465)
						_particleData[i0] -= 465;
					else if (_particleData[i0] < 0)
						_particleData[i0] += 465;
					if (_particleData[i1] > 465)
						_particleData[i1] -= 465;
					else if (_particleData[i1] < 0)
						_particleData[i1] += 465;
				}
				hsv.h = (1080 * Point.distance(new Point(mouseX,mouseY),new Point(_particleData[i0],_particleData[i1])) / kyori+360*ccc)%360
				this._bmd.setPixel(_particleData[i0], _particleData[i1] , hsv.value);
				i0 = ++i3;
			}
			this._bmd.colorTransform(this._bmdRect, this._colorTransform);
			this._bmd.unlock();
			
			_cnt++;
		}
	}
}