flash on 2011-5-30
/**
* Copyright amdmamdma ( http://wonderfl.net/user/amdmamdma )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1VkS
*/
package {
import flash.geom.Point;
import flash.events.Event;
import flash.display.Graphics;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private const MAX_CNT:uint = 64;
private const COL_CNT:uint = 8;
public function FlashTest() {
//元画像生成
var ar01:Vector.<Sprite> = new Vector.<Sprite>();
for(var i:uint = 0; i < MAX_CNT; i ++){
var sp01:Sprite = new Sprite();
var gr01:Graphics = sp01.graphics;
gr01.beginFill(Math.random() * 0xffffff);
gr01.drawRect(-25, -25, 50,50);
gr01.endFill();
addChild(sp01);
ar01.push(sp01);
//目標座標
var ar02:Vector.<Point> = new Vector.<Point>();
ar02.push( new Point(sp01.width * 0.5, sp01.height * 0.5) );
}
//フレーム監視開始
addEventListener(Event.ENTER_FRAME, xFrame);
//フレーム監視関数
function xFrame(e:Event):void{
//整列
var nLen:uint = ar01.length;
for(i = 0; i < nLen; i ++){
//マウスを近づけて
var nDef:Number = Math.sqrt( Math.pow(ar01[i].x - mouseX, 2) + Math.pow(ar01[i].y - mouseY, 2) );
//100px以内に近づいたら
var nRatio:Number;
if(nDef < 100){
//距離100pxで等倍
nRatio = 100 / nDef;
//最大2倍
if(nRatio > 2){
nRatio = 2;
}
}else{
//100px以上なら
nRatio = 1;
}
//スケール適用(減速接近)
ar01[i].scaleX += (nRatio - ar01[i].scaleX) / 10;
ar01[i].scaleY += (nRatio - ar01[i].scaleY) / 10;
//x座標等間隔(1行に?列)
if(i % COL_CNT == 0){
//1列目
ar01[i].x = ar01[i].width * 0.5;
}else{
//2列目以降
ar01[i].x = ar01[i - 1].x + ar01[i - 1].width * 0.5 + ar01[i].width * 0.5 + 10;
//かつ2行目以降
if(i >= COL_CNT){
//左上かぶり防止
//x座標がかぶってる
if(ar01[i].x <= ar01[i - COL_CNT - 1].x + ar01[i - COL_CNT -1].width * 0.5 + 10 + ar01[i].width * 0.5){
//右によける
ar01[i].x = ar01[i - COL_CNT - 1].x + ar01[i - COL_CNT -1].width * 0.5 + 10 + ar01[i].width * 0.5;
}
}
}
//y座標
if(i < COL_CNT){
//1行目
ar01[i].y = ar01[i].height * 0.5;
}else{
//2行目以降
ar01[i].y = ar01[i - COL_CNT].y + ar01[i - COL_CNT].height * 0.5 + ar01[i].height * 0.5 + 10;
//かつ右端でない
if(i % COL_CNT != (COL_CNT - 1)){
//右上かぶり防止
if(ar01[i].y <= ar01[i - COL_CNT + 1].y + ar01[i - COL_CNT + 1].height * 0.5 + 10 + ar01[i].height * 0.5){
//ar01[i - COL_CNT].x = ar01[i].x + ar01[i].width * 0.5 + 10 + ar01[i - COL_CNT - 1].width * 0.5;
ar01[i].y = ar01[i - COL_CNT + 1].y + ar01[i - COL_CNT + 1].height * 0.5 + 10 + ar01[i].height * 0.5;
}
}
}
}
}
}
}
}