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

重力シミュレータ?

重力シミュレータ?
一個衝突すると大変なことになる
Get Adobe Flash player
by Susisu 20 Mar 2010
    Embed
//重力シミュレータ?
//一個衝突すると大変なことになる
package {
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.filters.*;
	import flash.geom.Point;
	import flash.events.Event;
	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="60")]
	public class spin extends Sprite{
		private var stg:Sprite=new Sprite();
		private var bmpData:BitmapData=new BitmapData(465,465,true,0x00000000);
		private var stgBmp:Bitmap=new Bitmap(bmpData,PixelSnapping.AUTO,true);
		private var obj:Array;
		private var n:uint=2047;
		private var counter:uint=0;
		private var index:Array;
		private var onum:uint=0;
		private var filterObj:BlurFilter;
		private var i:uint;
		private var t:Number;
		private var gr:Number,gx:Number,gy:Number,gl:Number,ga:Number;
		public function spin(){
			obj=new Array(n)
			for(var i:uint=0;i<n;i++){
				obj[i]=new Array(5);
			}
			index=[0,0];
			addChild(stg);
			stg.addChild(stgBmp);
			
			stg.addEventListener("enterFrame", loop);
			filterObj=new BlurFilter();
			with(filterObj){
				blurX=2;
				blurY=2;
				quality=1;
			}
			gr=0.5;
			for(i=0;i<10;i++){
				onum=counter%n;
				obj[onum][0]=Math.floor(Math.random()*465);
				obj[onum][1]=Math.floor(Math.random()*465);
				obj[onum][2]=Math.random()*2-1;
				obj[onum][3]=Math.random()*2-1;
				obj[onum][4]=true;
				index[1]=counter;
				counter++;
			}
		}
		private function loop(e:Event):void{
			bmpData.applyFilter(bmpData,bmpData.rect, new Point(0, 0),filterObj);
			graphics.clear();
			onum=counter%n;
			t=Math.random()*360;
			obj[onum][0]=Math.cos(t/180*Math.PI)*329+232.5;
			obj[onum][1]=Math.sin(t/180*Math.PI)*329+232.5;
			obj[onum][2]=Math.random()*2-1;
			obj[onum][3]=Math.random()*2-1;
			obj[onum][4]=true;
			index[1]=counter;
			counter++;
			for(i=index[0];i<=index[1];i++){
				onum=i%n;
				if(obj[onum][4]){
					obj[onum][0]+=obj[onum][2];
					obj[onum][1]+=obj[onum][3];
					bmpData.setPixel32(obj[onum][0],obj[onum][1],0xffffffff|obj[onum][4]);
				}
			}
			for(i=index[0];i<=index[1];i++){
				onum=i%n;
				if(obj[onum][4]){
					gx=232.5-obj[onum][0];
					gy=232.5-obj[onum][1];
					gl=Math.sqrt(gx*gx+gy*gy);
					ga=Math.atan2(gx,gy);
					if(gl<gr+1){
						obj[onum][0]=232.5;
						obj[onum][1]=232.5;
						obj[onum][2]=0;
						obj[onum][3]=0;
						obj[onum][4]=false;
						gr+=0.1;
					}
					obj[onum][2]+=gr*gx/(gl*gl);
					obj[onum][3]+=gr*gy/(gl*gl);
				}
			}
			graphics.lineStyle(gr,0xff0000|((255/gr)<<8)|(255/(gr*gr)),100);
			graphics.moveTo(232,232);
			graphics.lineTo(232.5,232.5);
		}
	}
}