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

koduchi :: forked from: particle test

shake it!
Get Adobe Flash player
by iong 30 Sep 2009
    Embed
/**
 * Copyright iong ( http://wonderfl.net/user/iong )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/duXq
 */

// forked from iong's particle test
package
{
    /* shake it! */
	import flash.display.Sprite;

	[SWF(width="465", height="465", backgroundColor="#000000", frameRate="30")]

	public class Ptest extends Sprite
	{
		import flash.display.Bitmap;
		import flash.display.BitmapData;
		import flash.display.BlendMode;
		import flash.filters.BlurFilter;
		import flash.geom.Point;
		import flash.ui.Mouse;

		import flash.events.Event;

		import flash.display.StageAlign;
		import flash.display.StageQuality;
		import flash.display.StageScaleMode;

		public var spMaker:Sprite;
		public var objMaker:Object;
		// 生成する距離
		public var iMakeNum:uint = 40;

		public var aryP:Array = new Array();

		public var spR:Sprite;
		public var cv:BitmapData;

		public function Ptest():void
		{
			stage.quality   = StageQuality.LOW;
			stage.scaleMode = StageScaleMode.NO_SCALE;

			init();
			
			addEventListener(Event.ENTER_FRAME, onEF);
		}

		private function init():void
		{
			spR = new Sprite();
			spR.cacheAsBitmap= true;

			cv = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x0);

			spMaker  = new BMMaker();
			objMaker = new moveS(spMaker, 2, 0.3);

			Mouse.hide();

			addChild(new Bitmap(cv));
			addChild(spR);
			addChild(spMaker);
		}

		private function onEF(e:Event):void
		{
			var aryMaker:Array = objMaker.act(mouseX, mouseY);
		    if(Math.abs(aryMaker[0])>iMakeNum || Math.abs(aryMaker[1])>iMakeNum)
		        make();
		    moveAll();
		}

		private function make():void
		{
		    
			var tB:Sprite = new BPPiece(retC(70));
			tB.x = spMaker.x;
			tB.y = spMaker.y;
			var aX:Number = (mouseX-spMaker.x)/15;
			var aY:Number = (mouseY-spMaker.y)/15;
			var aR:uint   = retRandom(5);
			spR.addChild(tB);
			aryP.push(new Array(tB, aX, aY, aR));
		}
		private function moveAll():void
		{
			for(var i:int=0; i<aryP.length; i++){
				var target:Sprite = aryP[i][0];
				target.x         -= aryP[i][1];
				target.y         -= aryP[i][2];
				target.rotation  += aryP[i][3];
				target.alpha     -= 0.01;
				if (target.x+target.width<0 || target.x-target.width>stage.stageWidth
				 || target.y+target.height<0 || target.y-target.height>stage.stageHeight
				 || target.alpha<=0){
					spR.removeChildAt(i);
					aryP.splice(i,1);
				}
			}
            cv.draw(spR, null, null, BlendMode.LIGHTEN);
            cv.applyFilter(cv, cv.rect, new Point(), new BlurFilter(16,16));
		}

		private function retC(n:uint):int
		{
			var ofR:int = n+retRandom(255-n);
			var ofG:int = n+retRandom(255-n);
			var ofB:int = n+retRandom(255-n);
			return parseInt("0xff"+ ofR.toString(16)+ ofG.toString(16) + ofB.toString(16));
		}
		private function retRandom(n:int):uint
		{
			return Math.round(Math.random()*n);
		}
	}
}


import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.BlurFilter;
class moveS
{
	public var sp:Sprite;
	public var intPlus:int;
	public var intDev:Number;
	public var _addX:int;
	public var _addY:int;
	public var dX:int;
	public var dY:int;
	public var tX:int;
	public var tY:int;
	public var addX:int;
	public var addY:int;

	public function moveS(_sp:Sprite, iA:int, iB:Number):void
	{
		sp      = _sp;
		intPlus = iA;
		intDev  = iB;
	}
	public function act(ax:int, ay:int):Array
	{
		addX    = _addX*intPlus;
		addY    = _addY*intPlus;
		_addX   = tX;
		_addY   = tY;
		dX      = (ax - sp.x);
		dY      = (ay - sp.y);
		tX      = dX*intDev;
		tY      = dY*intDev;
		sp.x   += tX + addX;
		sp.y   += tY + addY;
		sp.filters = [new BlurFilter(Math.round(Math.abs(dX/2)), Math.abs(Math.round(dY/2)))];
		return new Array(dX, dY);
	}
}
class BMMaker extends Sprite
{
	public function BMMaker():void
	{
		var ary:Array = BluePrint();
		var tBD:BitmapData = new BitmapData(ary[0].length, ary.length, true, 0x0);
		for(var i:int=0; i<ary.length; i++){
			for(var k:int=0; k<ary[i].length; k++){
				if(ary[i].charAt(k)=="1") tBD.setPixel32(k,i,0xffffffff);
			}
		}
		var tB:Bitmap = new Bitmap(tBD);
		tB.x -= tB.width/2;
		tB.y -= tB.height/2;
		tB.scaleX= tB.scaleY= 4;
		addChild(tB);
	}
	private function BluePrint():Array
	{
		var tp:String  = "0001000"
		          +"\n"+ "1111111"
		          +"\n"+ "1111111"
		          +"\n"+ "1111111"
		          +"\n"+ "0001000"
		          +"\n"+ "0001000"
		          +"\n"+ "0001000";
		return tp.split("\n");
	}
}

class BPPiece extends Sprite
{
	function BPPiece(iC:int):void
	{
		var ary:Array = retAry();
		var tBD:BitmapData= new BitmapData(ary[0].length, ary.length, true, 0);
		for(var bpi:int=0; bpi<ary.length; bpi++){
			for(var bpm:int=0; bpm<ary[bpi].length; bpm++){
				if(ary[bpi].charAt(bpm)=="1") tBD.setPixel32(bpm, bpi, iC);
			}
		}
		var tB:Bitmap= new Bitmap(tBD);
		addChild(tB);
	}
	private function retAry():Array
	{
		var retVal:String= "";
		retVal= '00011111111000'+"\n"
		      + '00111111111100'+"\n"
		      + '01101100110110'+"\n"
		      + '11001100110011'+"\n"
		      + '11110011001111'+"\n"
		      + '11110011001111'+"\n"
		      + '11001111110011'+"\n"
		      + '11001111110011'+"\n"
		      + '11110011001111'+"\n"
		      + '11110011001111'+"\n"
		      + '11001100110011'+"\n"
		      + '01101100110110'+"\n"
		      + '00111111111100'+"\n"
		      + '00011111111000';
		return retVal.split("\n");
	}
}