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: Arrows Flow Simulation_5000p

フォーク回数が20回までいってしまった
/**
 * Copyright ryo_2004 ( http://wonderfl.net/user/ryo_2004 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hgSL
 */

// forked from clockmaker's Arrows Flow Simulation
// forked from nemu90kWw's BitmapData直描きにすれば残像付きでも超軽いよ
// forked from nemu90kWw's 画像をトリミングしてみた(中心点未調整)
// forked from keno42's ちょっと変えたけどそんなに速くならなかった
// forked from keno42's forked from: forked from: 速度比較したら一個前の方法が速かったっぽい
// forked from keno42's forked from: 速度比較したら一個前の方法が速かったっぽい
// forked from keno42's 速度比較したら一個前の方法が速かったっぽい
// forked from bkzen's forked from: 色と透明度もいれてみた。こんなのどうだろバージョン
// forked from bkzen's 色と透明度もいれてみた。速度向上したらいいなばーじょん
// forked from keno42's 角度計算修正、色と透明度もいれてみた。重ね順ソートが重い。
// forked from bkzen's forked from: BitmapDataで配列に格納すると高速化するよ(角度修正)
// forked from clockmaker's BitmapDataで配列に格納すると高速化するよ
// forked from clockmaker's 3D Flow Simulation with Field of Blur
// forked from clockmaker's 3D Flow Simulation
// forked from clockmaker's Interactive Liquid 10000
// forked from clockmaker's Liquid110000 By Vector
// forked from munegon's forked from: forked from: forked from: forked from: Liquid10000
// forked from Saqoosha's forked from: forked from: forked from: Liquid10000
// forked from nutsu's forked from: forked from: Liquid10000
// forked from nutsu's forked from: Liquid10000
// forked from zin0086's Liquid10000
package {
    	
	// フォーク回数が20回までいってしまった
	import flash.display.*;
	import flash.geom.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.utils.*;
	import flash.geom.*;
	import net.hires.debug.Stats;	
	
	[SWF(width="465", height="465", backgroundColor="0x0", frameRate="90")]
	import flash.text.TextField;
	import flash.text.TextFormat;
	public class Main extends Sprite {
		
		private var forceMap:BitmapData = new BitmapData( 233, 233, false, 0x000000 );
		private var randomSeed:uint = Math.floor( Math.random() * 0xFFFF );
		private var seed:Number = Math.floor( Math.random() * 0xFFFF );
		private var offset:Array = [new Point(), new Point()];
		private var timer:Timer;
		private var buffer:BitmapData = new BitmapData(465, 465, false	, 0);
		private var screen:Bitmap = new Bitmap(buffer);
		private var particleList:Array = [];
		
		function Main()
		{	
		
			stage.frameRate = 90;
			// フォースマップの初期化をおこないます
			resetFunc();
			
			// ループ処理
			addEventListener( Event.ENTER_FRAME, loop );
			
			// 時間差でフォースマップと色変化の具合を変更しています
			var timer:Timer = new Timer(1000);
			timer.addEventListener(TimerEvent.TIMER, resetFunc);
			timer.start();
			
			// 矢印をプレレンダリング
			var dummy:Sprite = new Sprite();
			var dummyBg:Sprite = new Sprite();
			var dummyHolder:Sprite = new Sprite();
			dummy.graphics.beginFill(0xaa3300, 1);
			dummy.graphics.lineStyle(1, 0xff6622, 1);
			dummy.graphics.drawPath(Vector.<int>([1,2,2,2,2,2,2,2]), Vector.<Number>([-9,-7,-3,-7,-3,-11,9,-4,-3,3,-3,-1,-9,-1,-9,-7]));
			dummyBg.graphics.beginFill(0x0, 1);
			dummyBg.graphics.lineStyle(1, 0x0, 1);
			dummyBg.graphics.drawPath(Vector.<int>([1,2,2,2,2,2,2,2]), Vector.<Number>([-9,-7,-3,-7,-3,-11,9,-4,-3,3,-3,-1,-9,-1,-9,-7]));
			dummyHolder.addChild(dummyBg);
			dummyHolder.addChild(dummy);
			
			var temp:BitmapData = new BitmapData(22, 22, true, 0x0);
			var rect:Rectangle;
			var matrix:Matrix = new Matrix(1, 0, 0, 1, 11, 11);
			var blurF:BlurFilter = new BlurFilter();
			
			var j:int = ALPHA_STEPS;
			while(j--) {
				var i:int = ROT_STEPS;
				var k:int = j * ROT_STEPS;
				dummy.alpha = j / (ALPHA_STEPS) + .2;

				while (i--) {
					var rot:Number = i * RAD
					var scale:Number = j / ALPHA_STEPS + 0.2;
					matrix.a = matrix.d  = scale * Math.cos(rot);
					matrix.b = scale * Math.sin(rot);
					matrix.c = -matrix.b;
					blurF.blurX = (20-j)*Math.cos(rot)>>1;
					blurF.blurY = (20-j)*Math.cos(rot)>>1;

					temp.fillRect(temp.rect, 0x0);
					temp.draw(dummyHolder, matrix);
					temp.applyFilter( temp, temp.rect, new Point(), blurF );
					rotArr[i+k] = temp.clone();
				}
			}
			
			// パーティクルを生成します
			for (i = 0; i < NUM_PARTICLE; i++) {particleList[i] = new Arrow(Math.random() * 465, Math.random() * 465);}
			addChild(screen);
			//addChild(new Pattern(465, 465));
			addChild(setText());
			
			// デバッグ用のスタッツを表示しています
			addChild(new Stats);													
		}
		
		private var p:Point = new Point();
		private var cTrans:ColorTransform = new ColorTransform(1, 1, 1, 1, -12, -20, -20, 0);
		private var rect:Rectangle = buffer.rect;
		private var aRect:Rectangle = new Rectangle(0, 0, 22, 22);
		private function loop( e:Event ):void {

			var arrow:Arrow;
			var co:int;
			
			buffer.lock();
			buffer.colorTransform(rect, cTrans);
			particleList.sortOn("speed", Array.NUMERIC);
			for (var i:int = 0; i < NUM_PARTICLE; i++) {
				arrow = particleList[i];
				co = (arrow.x >> 1) + (arrow.y >> 1)*233;
				arrow.step(mapData[co]);
				p.x = arrow.x -11;
				p.y = arrow.y -11;
				buffer.copyPixels(arrow.bmd, aRect, p);
			}
			buffer.unlock();
		}
		
		private var mapData:Vector.<uint>;
		private var mapRect:Rectangle = forceMap.rect;
		private function resetFunc(e:Event = null):void {
			forceMap.perlinNoise(80, 80, 3, seed, false, true, 6, false, offset);
			
			offset[0].x += 1.5;
			offset[1].y += 1;
			seed = Math.random()*uint.MAX_VALUE;
			mapData = forceMap.getVector(mapRect);
			mapData.fixed = true;
		}
			
		private function setText():TextField
		{
			var tf:TextField = new TextField()
			var format:TextFormat = new TextFormat("arial black, tahoma", 20, 0x404040);
			tf.defaultTextFormat = format;
			tf.text = NUM_PARTICLE + " Particles";
			tf.autoSize = "center";
			tf.x = (465 - tf.textWidth)*.5
			tf.y = 465 - tf.textHeight - 5;
			tf.blendMode = "add";
			return tf;
		}
	}
}

import flash.display.*;
import flash.geom.*;

const NUM_PARTICLE:int = 5000;
const ROT_STEPS:int = 128;
const ALPHA_STEPS:int = 20;
var rotArr:Vector.<BitmapData> = new Vector.<BitmapData>(ROT_STEPS * ALPHA_STEPS, true);
const multiplyConst:Number = 64 / Math.PI;
const RAD:Number = ( 360 / ROT_STEPS ) * Math.PI / 180;
class Arrow {

	public var x:Number, y:Number;
	public var vx:Number = 0, vy:Number = 0, ax:Number = 0, ay:Number = 0;
	public var rot:int = 0, speed:int = 0;
	public var bmd:BitmapData;
	
	function Arrow(x:int, y:int) {
		this.x = x;
		this.y = y;
	}
	
	public function step(col:uint):void {
		ax += ( (col      & 0xff) - 0x80 ) * .0005;
		ay += ( (col >> 8 & 0xff) - 0x80 ) * .0005;
		vx += ax;
		vy += ay;
		x += vx;
		y += vy;
		
		var dir:Number = Math.atan2( vy, vx );
		rot = (128 + dir * multiplyConst) & 127;
		//rot = dir*multiplyConst|0;
		var sp1:int= (vx*vx + vy*vy )>> 1;
		//var sp2:int = ALPHA_STEPS-1;
		//speed = Math.min(ALPHA_STEPS-1, (vx*vx + vy*vy) >> 1);
		speed = (sp1 > ALPHA_STEPS-1) ? ALPHA_STEPS-1 : sp1;
		var idx:int = rot + ROT_STEPS * speed;
		bmd = rotArr[idx];
		
		ax *= .96;
		ay *= .96;
		vx *= .92;
		vy *= .92;
		
		//( x > 465 ) ? x = 0 : ( x < 0 ) ? x = 465 : 0;
		//( y > 465 ) ? y = 0 : ( y < 0 ) ? y = 465 : 0;

		if( x<0 || x>465) x = (x+465) % 465;
		if( y<0 || y>465) y = (y+465) % 465;
	}
}

internal class Pattern extends Shape
{
	private var pat:BitmapData;
	public function Pattern($w:Number, $h:Number, $co:uint=0x80000000):void
	{
		super();
		pat = new BitmapData(1, 2, true, 0x0);
		pat.fillRect(new Rectangle(0, 0, 1, 1), $co);
		
		this.graphics.beginBitmapFill(pat);
		this.graphics.drawRect(0, 0, $w, $h);
		this.graphics.endFill();
		this.blendMode = "overlay";
	}
	
	public function setColor($val:uint):void
	{
		pat.fillRect(new Rectangle(0, 0, 1, 1), $val);	
	}
}