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: YAM55 ぐにょーん

こんなっ
Get Adobe Flash player
by 2state 27 Apr 2009
// forked from 2state's YAM55 ぐにょーん
// forked from 2state's YAM55 (Yet Another matrix 5*5)
// こんなっ
package
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	[SWF(backgroundColor="#000000",frameRate="30")]
	
	public class YAM55 extends Sprite
	{
		public static const MAX_X:int = 10;
		public static const MAX_Y:int = 10;
		public static const ITEM_SIZE:int = 25;
		public static const SMALL_SIZE:Number = 0.3;
		public static const BIG_SIZE:Number = 5.5;
		public static const AREA:int = 100;
		public static const CH_SPEED:int = 5;
		
		public var ic:Array = new Array(MAX_X);
		public var canv_width:int = MAX_X * ITEM_SIZE;
		public var canv_height:int = MAX_Y * ITEM_SIZE;
		
		public function YAM55():void{
				for(var x:int = 0; x < MAX_X; x++){
				ic[x] = new Array(MAX_Y);
				for(var y:int = 0; y < MAX_Y; y++){
					ic[x][y] = new Sprite();
					ic[x][y].graphics.beginFill(0xFF0000);
					ic[x][y].graphics.drawCircle(0,0,ITEM_SIZE/2);
					ic[x][y].graphics.endFill();
					addChild(ic[x][y]);
					ic[x][y].x = (x+1) * ITEM_SIZE;
					ic[x][y].y = (y+1) * ITEM_SIZE;
				}
			}
			addEventListener(Event.ENTER_FRAME,reDraw);
		}
		public function reDraw(e:Event):void{
			var inX:int = stage.mouseX;
			var inY:int = stage.mouseY;
			var s:Number;
			for(var x:int = 0; x < MAX_X; x++){
				for(var y:int = 0; y < MAX_Y; y++){
					var sp:Number = pointSpan(
						(x+1)*ITEM_SIZE,
						(y+1)*ITEM_SIZE,
						inX,inY);
					s = getScale(sp,ic[x][y].scaleX);
					ic[x][y].scaleX = s;
					ic[x][y].scaleY = s;
					if(canv_width + ITEM_SIZE > inX &&
					   canv_height+ ITEM_SIZE > inY &&
					   inX > ITEM_SIZE && inY > ITEM_SIZE){
						ic[x][y].x = getPos((x+1)*ITEM_SIZE,inX,ic[x][y].x);
						ic[x][y].y = getPos((y+1)*ITEM_SIZE,inY,ic[x][y].y);
					}else{
						ic[x][y].x = getPos((x+1)*ITEM_SIZE, (x+1)*ITEM_SIZE,ic[x][y].x);
						ic[x][y].y = getPos((y+1)*ITEM_SIZE, (y+1)*ITEM_SIZE,ic[x][y].y);
					}
				}
			}
		}
		public function getScale(sp:Number,nS:Number):Number{
			var rS:Number;
			var size_s:Number = BIG_SIZE - SMALL_SIZE;
			if(sp < AREA){
				rS = SMALL_SIZE + (size_s * ((AREA - sp) / AREA) );
			}else{
				rS = SMALL_SIZE;
			}
			return nS + (rS - nS) / CH_SPEED
		}
		public function getPos(opos:int,mpos:int,rpos:int):Number{
			var npos:int;
			if(opos > mpos+10 || opos < mpos-10){
					npos = opos + (opos - mpos);
			}else{
				npos = opos;
			}
			return rpos + (npos - rpos) / CH_SPEED
		}
		public function pointSpan(sx:int, sy:int, ex:int, ey:int):Number{
			var xs:int = ex-sx;
			var ys:int = ey-sy;
			return Math.sqrt(xs*xs+ys*ys);
		}
	}
}