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

レーザー風 forked02: BouncerAS3

僕もFlight404でオープンになってたやつを微妙にAS3に移植してみました(完全再現ではないです)
ここにある http://www.flight404.com/p5/
「bouncer11」ってコードです
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
	
	/**
	 * 僕もFlight404でオープンになってたやつを微妙にAS3に移植してみました(完全再現ではないです)
	 * ここにある http://www.flight404.com/p5/
	 * 「bouncer11」ってコードです
	 */ 
	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="60")]  
    
	public class Bouncer_lazer extends Sprite
	{
		private var m1:Meander;
		private var bounceArray:Array;
		private var total:uint = 60;
		private var base:Sprite = new Sprite();
		private var bmp:Bitmap;
		private var bmpData:BitmapData;
		private var blur:BlurFilter = new BlurFilter(10,10);
		private var Mtx:Matrix;
		
		public function Bouncer_lazer()
		{
			m1 = new Meander;
			bmpData = new BitmapData(465/2,465/2,false,0x000000);
			bmp = new Bitmap(bmpData);
			base.blendMode = "add";
			addChild( bmp );
			addChild( base );
			bmp.scaleX = bmp.scaleY = 2;
			addEventListener(Event.ADDED_TO_STAGE, addStageHandler);
		}
		
		private function addStageHandler(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, addStageHandler);
			
			//meander
			//base.addChild(m1);
			m1.graphics.beginFill(0xFF0000);
			m1.graphics.drawCircle(0,0,5);
			m1.graphics.endFill();
			
			//bouncer
			bounceArray = new Array();
			for (var i:uint=0; i<total; i++){
			   bounceArray.push( new Bouncer(465/2 + -25+Math.random()+50, 465/2 + -15+Math.random()+30, 
			   	-20+Math.random()+40,-10+Math.random()+20, m1) );
			   base.addChild( bounceArray[i] );
			   bounceArray[i].setJoint();
			}
			
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		
		private function enterFrameHandler(e:Event):void
		{
			m1.HandleEnterFrame();
			
			//bouncer
			m1.HandleEnterFrame();
			m1.x = m1.xPos;
			m1.y = m1.yPos;
			for (var i:uint=0; i<total; i++){
				bounceArray[i].bounce();
			}
			
			Mtx = new Matrix();
			Mtx.scale(0.5,0.5);
			bmpData.draw(base,Mtx);
			bmpData.applyFilter(bmpData,bmpData.rect,new Point(0,0),blur);
		}
	}
}


	import flash.display.Sprite;
	import __AS3__.vec.Vector;
	import flash.display.Bitmap;
	import flash.display.BitmapData;


class Meander extends Sprite
{
	public var left:Number = 0;
	public var right:Number = 465;
	public var bottom:Number = 0;
	public var top:Number = 465;
	//param
	public var xMax:uint = 5;
	public var yMax:uint = 3;
	public var xPos:Number = 100;
	public var yPos:Number = 100;
	public var xSpeed:Number = 0;
	public var ySpeed:Number = 0;
	public var xDelta:Number, yDelta:Number;
	private var cnt:int = Math.round( 360 * Math.random() );
	private var fcounter:uint = 0;
	
	public function Meander()
	{
		//	
	}
	
	public function HandleEnterFrame():void
	{
		
		if(xPos < left) {
			cnt += 90;
		} else if(xPos > right) {
			cnt += 90;
		}
		if(yPos < bottom) {
			cnt += 90;
		} else if(yPos > top) {
			cnt += 90;
		}
		
		xSpeed = 2 * Math.cos(cnt * Math.PI/  180);
		ySpeed = 2 * Math.sin(cnt * Math.PI/  180);
		
		xPos = xPos + xSpeed;
		yPos = yPos + ySpeed;
		
		if(fcounter%360==0) {
			xPos = 100 + ( right - 200 ) * Math.random();
			yPos = 100 + ( top  - 200 ) * Math.random();
		}
		
		fcounter++;
	}
}

class Bouncer extends Sprite
{
	private var xPos:Number;
	private var yPos:Number;
/*	private var xOld:Number;
	private var yOld:Number;
	private var x2Old:Number;
	private var y2Old:Number;
	private var x3Old:Number;
	private var y3Old:Number;*/
	private var xBox:Vector.<Number>;
	private var yBox:Vector.<Number>;
	private var velBox:Vector.<Number>;
	private var arrLen:uint = 10;
	private var left:Number = 0;
	private var right:Number = 465;
	private var bottom:Number = 0;
	private var top:Number = 465;
	private var friction:Number;
	private var elastic:Number;
	private var gravity:Number;
	private var xd:Number, yd:Number;
	private var vx:Number, vy:Number;
	private var newVx:Number, newVy:Number;
	private var totalVel:Number;
	private var xDelta:Number, yDelta:Number, distance:Number;
	private var x2Delta:Number, y2Delta:Number, distance2:Number;
	private var randomXVar:Number;
	private var randomYVar:Number;
	private var m1:Meander;
	private var bmp:Bitmap;
	private var bmpArray:Vector.<Bitmap> = new Vector.<Bitmap>(10);
	private var jointArray:Vector.<Sprite> = new Vector.<Sprite>(10);
	
	/**
	 * コンストラクタ
	 */
	public function Bouncer(xp:Number, yp:Number, xv:Number, yv:Number, myM:Meander)
	{
		xPos = xp;
		yPos = yp;
		vx = xv;
		vy = yv;
		m1 = myM;
		friction = 0.1 + 0.1*Math.random();
		elastic = 0.1 + 0.8*Math.random();
		randomXVar = -120 + 240*Math.random();
		randomYVar = -120 + 240*Math.random();
		xBox = new Vector.<Number>(arrLen);
		yBox = new Vector.<Number>(arrLen);
		velBox = new Vector.<Number>(arrLen);
		
	}
	
	public function setJoint():void
	{
		for(var i:uint=0; i<10; i++) {
			var joint:Sprite = new Sprite();
			/*joint.graphics.beginFill(0x000000);
			joint.graphics.drawCircle(0,0,5);
			joint.graphics.endFill();*/
			addChild(joint);
			jointArray[i] = joint;
		}
	}
	
	public function bounce():void
	{
		
		for(var i:uint=0; i<arrLen; i++ )
		{
			var t:uint = arrLen-1-i;
			xBox[t+1] = xBox[t];
			yBox[t+1] = yBox[t];
			velBox[t+1] = velBox[t];
		}
		xBox[0] = xPos;
		yBox[0] = yPos;
		velBox[0] = totalVel;
		
		newVx = vx * elastic + (m1.xPos - xPos) * friction;
		newVy = vy * elastic + (m1.yPos - yPos) * friction;
		//newVx = vx * elastic + (mouseX - xPos) * friction;
		//newVy = vy * elastic + (mouseY - yPos) * friction;
		vx = vx + 0.01 * (newVx - vx);
		vy = vy + 0.01 * (newVy - vy);
		
		xPos = xPos + vx;
		yPos = yPos + vy;
		
		totalVel = (Math.abs(vx) + Math.abs(vy));
		
		if(vx < 0) {
			if(Math.random()*50<5) {
				
			} else {
				
			}
		} else {
			if(Math.random()*50<5) {
				
			} else {
				
			}
		}
		
		this.graphics.clear();
		//this.graphics.lineStyle(1,0xFFFFFF);
		this.graphics.moveTo(xPos, yPos);
		
		for(i=0; i<arrLen; i++)
		{
			if(i%4 == 0) {
				var r:uint = 255;
				var g:uint = 10 * velBox[i];
				var b:uint = 8 * velBox[i];

				var newColor:uint = r << 16 | g << 8 | b;
				this.graphics.lineStyle(1,newColor);
				this.graphics.lineTo(xBox[i], yBox[i]);
				jointArray[i/4].x = xBox[i];
				jointArray[i/4].y = yBox[i];
			}
		}
	}
}