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: forked from: forked from: forked from: forked from: flash on 2010-2-21

どっか間違えてるけど、これはこれでよし
Get Adobe Flash player
by mhayashi 21 Feb 2010
    Embed
/**
 * Copyright mhayashi ( http://wonderfl.net/user/mhayashi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/e8Wt
 */

// forked from mhayashi's forked from: forked from: forked from: forked from: flash on 2010-2-21
// forked from mhayashi's forked from: forked from: forked from: flash on 2010-2-21
// forked from mhayashi's forked from: forked from: flash on 2010-2-21
// forked from mhayashi's forked from: flash on 2010-2-21
// forked from mhayashi's flash on 2010-2-21

// どっか間違えてるけど、これはこれでよし

package {
    import flash.display.Sprite;
	import flash.display.Bitmap;
    import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.filters.BlurFilter;
	
	[SWF(width=465, height=465, backgroundColor=0, framerate=30)]
    public class BitmapDataSample extends Sprite {

		private var bmpdata:BitmapData;
		private var colortrans:ColorTransform;
		private var filter:BlurFilter;
		private var vectormap:BitmapData;
		private var particles:Array;
		private var particle_number:uint = 25000;
		private var size:Number = 465;

        public function BitmapDataSample() {
			bmpdata = new BitmapData( size, size, false, 0 );
			addChild( new Bitmap(bmpdata) );

			colortrans = new ColorTransform(0.95, 0.99, 0.99);
			filter = new BlurFilter(2,2,1);

			vectormap = new BitmapData(size, size, false, 0);
			reset();

			addEventListener(Event.ENTER_FRAME, enterframe);
			stage.addEventListener(MouseEvent.CLICK, reset);
        }

		private function reset(e:MouseEvent = null):void{
			var randomSeed:int = Math.random()*0xFFFFFFFF;
			var colors:uint = BitmapDataChannel.RED | BitmapDataChannel.GREEN;
			vectormap.perlinNoise( size/2, size/2, 4, randomSeed, false, true, colors);

			particles = new Array(particle_number);
			for (var i:int = 0; i < particle_number; i++){
				particles[i] = new Particle(Math.random()*size, Math.random()*size);
			}
		}
		
		// ENTER_FRAME のイベントリスナー
		private function enterframe(e:Event):void {
			bmpdata.applyFilter(bmpdata, bmpdata.rect, bmpdata.rect.topLeft, filter);
			bmpdata.colorTransform(bmpdata.rect, colortrans);

			bmpdata.lock();
			for (var i:int = 0; i < particle_number; i++){
				var p:Particle = particles[i];

				var col:uint = vectormap.getPixel(p.x, p.y);
				p.ax += ((col >> 16 & 0xff) - 128)*0.0005;
				p.ay += ((col >> 16 & 0xff) - 128)*0.0005;

				p.x += p.vx += p.ax;
				p.y += p.vy += p.ay;
				if (p.x > size) { p.x -= size; }
				else if (p.x < 0) { p.x += size; }
				if (p.y > size) { p.y -= size; }
				else if (p.y < 0) { p.y += size; }

				bmpdata.setPixel(p.x, p.y, 0xffffff);

				p.ax *= 0.96; p.ay *= 0.96;
				p.vx *= 0.92; p.vy *= 0.92;
			}
			bmpdata.unlock();
		}
    }

}
class Particle {
	public var x:Number;
	public var y:Number;

	public var ax:Number = 0;
	public var ay:Number = 0;

	public var vx:Number = 0;
	public var vy:Number = 0;

	function Particle( px:Number, py:Number){
		x = px;
		y = py;
	}
}