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 HaraMakoto 26 Mar 2009
package {
	import __AS3__.vec.Vector;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="60")]

	public class Mosaic_ver1 extends Sprite
	{
		
		private var W:Number = 465;
		private var H:Number = 465;
		//private var W:Number = 900;
		//private var H:Number = 450;
		private var tileArray:Vector.<mosTile> = new Vector.<mosTile>(100);
		private var mosNum:uint = 100;
		private var unitNumW:Number; //1タイル分の幅
		private var unitNumH:Number; //1タイル分の高さ
		private var m:Meander;
		
		public function Mosaic_ver1()
		{
			makeMosaic(); //モザイクタイル作成
			m = new Meander(); //目標の子
			m.makePoint();
			addChild( m );
			addEventListener(Event.ENTER_FRAME, handleEnterFrame);
		}
		
		private function makeMosaic():void
		{
			unitNumW = ( W - 10 ) / 10;
			unitNumH = ( H - 10 ) / 10;
			for(var i:uint=0; i<mosNum; i++) {
				var mos:mosTile = new mosTile();
				addChild(mos);
				tileArray[i] = mos;
				mos.x = int( i / 10 ) * unitNumW + 30;
				mos.y = int( i % 10 ) * unitNumH + 30;
			}
		}
		
		private function handleEnterFrame(e:Event):void
		{
			m.HandleEnterFrame();
			for(var i:uint=0; i<mosNum; i++) {
				tileArray[i].handleEnterFrame(m.x - tileArray[i].x, m.y - tileArray[i].y);
			}
		}
		
		
	}
}
	import flash.display.Sprite;
	


class mosTile extends Sprite
{
	private var Layer_a:Sprite = new Sprite();
	private var Layer_b:Sprite = new Sprite();
	private var distance:Number;
	private var dx:Number, dy:Number;
	// ばね係数
	private var SPRING_CONST:Number = 0.11;
	// 慣性
	private var FRICTION:Number = 0.89;
	private var v:Number = 0;
	private var myScale:Number;
	
	public function mosTile()
	{
		setImg();
		addChild(Layer_a);
		addChild(Layer_b);
	}
	
	private function setImg():void
	{
		Layer_a.graphics.beginFill(0xffffff);
		Layer_a.graphics.drawCircle(0,0,5);
		Layer_a.graphics.endFill();
	}
	
	public function handleEnterFrame(px:Number, py:Number):void
	{
		dx = px;
		dy = py;
		distance = Math.sqrt(dx*dx + dy*dy);
		if( distance < 100 ) {
			myScale = 1 + ( 10 / (distance/10+1) );
		} else {
			myScale = 1;
		}
		
		applyScale();
		
		/*Layer_b.graphics.clear();
		Layer_b.graphics.lineStyle(1,0xffffff);
		Layer_b.graphics.moveTo(0,0);
		Layer_b.graphics.lineTo(px, py);
		*/
	}
	
	private function applyScale():void
	{
		var scaledis:Number = myScale - Layer_a.scaleX;
		var a:Number = SPRING_CONST * scaledis; //加速度
		var ay:Number = SPRING_CONST * dy;
		v += a; //加速度を速度に加算
		v *= FRICTION;
		
		Layer_a.scaleX += v;
		Layer_a.scaleY += v;
	}
}

class Meander extends Sprite
{
	public var left:Number = 0;
	public var right:Number = 465;
	//public var right:Number = 900;
	public var bottom:Number = 0;
	public var top:Number = 465;
	//public var top:Number = 450;
	//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 makePoint():void
	{
		/*this.graphics.beginFill(0xff0000);
		this.graphics.drawCircle(0,0,10);
		this.graphics.endFill();*/
	}
	
	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 = 15 * Math.cos(cnt * Math.PI/  180);
		ySpeed = 15 * 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();
		}
		
		this.x = xPos;
		this.y = yPos;
		
		fcounter++;
	}
}