List shuffle
8*58 = 464 = 1 pixel less than wonderfl's dimensions
This means a 8x8 grid of 58x58 squares
/**
* Copyright aobyrne ( http://wonderfl.net/user/aobyrne )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nCou
*/
// forked from komatsu's RandomNumber on 2010-01-26
package {
import flash.text.TextField;
import flash.display.Sprite;
import caurina.transitions.Tweener;
[SWF(backgroundColor="#000000", frameRate=30)]
public class RamdomRectangle extends Sprite {
public function RamdomRectangle() {
var rndAry:Array = new Array();
const MAX_CNT:uint = 64;
var i:uint;
for(i=1;i<=MAX_CNT;i++){
rndAry.push(i);
}
rndAry = Shuffle.setRandom(rndAry);
var columns:int = 8;
var squareSize:int = 58;
for(i=0;i<MAX_CNT;i++){
var sp:Sprite = new Sprite();
sp.graphics.beginFill(Math.random()*0xFFFFFF);
sp.graphics.drawRect(0,0,squareSize,squareSize);
sp.x = sp.width*(i%columns);
sp.y = sp.height*(Math.floor(i/columns));
var tf:TextField = new TextField();
tf.text = String(rndAry[i])+"\n"+stage.stageWidth+"\n"+int(columns*squareSize);
sp.addChild(tf);
sp.alpha = 0;
Tweener.addTween(sp , {alpha:1 , delay:(i+1)/20,time:5});
addChild(sp);
}
}
}
}
class Shuffle{
/*配列のシャッフルをする関数*/
static public function setRandom(ary:Array):Array{
var baseAry:Array = ary;
var returnAry:Array = new Array();
var rndCnt:uint = ary.length;
for(var i:uint=0;i<rndCnt;i++){
var rnd:uint = Math.floor(Math.random()*baseAry.length);
returnAry.push(baseAry[rnd]);
baseAry.splice(rnd,1);
}
return returnAry;
}
}