うじゃうじゃ ライフゲーム
150*150
bitmap使えばもっと早くなるんですかねぇ
/**
* Copyright tester00001 ( http://wonderfl.net/user/tester00001 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/l4Lu
*/
package {
import flash.display.*;
import flash.events.*;
public class FlashTest extends Sprite {
private const numIn:int=150;
private const randomIn:int=8;
private var nowAr:Array;
private var nextAr:Array;
private var dotAr:Array;
public function FlashTest() {
iniF();
positF();
addEventListener(Event.ENTER_FRAME,calcF);
}
private function iniF():void{
nowAr=new Array(numIn);
nextAr=new Array(numIn);
dotAr=new Array(numIn);
for(var i:int=0;i<numIn;i++){
nowAr[i]=new Array(numIn);
nextAr[i]=new Array(numIn);
dotAr[i]=new Array(numIn);
for(var j:int=0;j<numIn;j++){
var tempIn:int=Math.floor(Math.random()*randomIn);
nowAr[i][j]=(tempIn==0)?1:0;
nextAr[i][j]=0;
dotAr[i][j]=new Shape();
dotAr[i][j].graphics.beginFill(0x000000,1);
dotAr[i][j].graphics.drawRect(i,j,1,1);
addChild(dotAr[i][j]);
}
}
}
private function dispF():void{
for(var i:int=0;i<numIn;i++){
for(var j:int=0;j<numIn;j++){
dotAr[i][j].visible=(nowAr[i][j]==1)?true:false;
}
}
}
private function calcF(e:Event):void{
var upIn:int;
var downIn:int;
var rightIn:int;
var leftIn:int;
var countIn:int;
for(var i:int=0;i<numIn;i++){
for(var j:int=0;j<numIn;j++){
upIn=i-1;
downIn=i+1;
rightIn=j+1;
leftIn=j-1;
if(upIn==(-1)){
upIn=numIn-1;
}
else if(downIn==numIn){
downIn=0;
}
if(rightIn==numIn){
rightIn=0;
}
else if(leftIn==(-1)){
leftIn=numIn-1;
}
countIn=nowAr[upIn][leftIn]+nowAr[upIn][j]+nowAr[upIn][rightIn]+nowAr[i][leftIn]+nowAr[i][rightIn]+nowAr[downIn][leftIn]+nowAr[downIn][j]+nowAr[downIn][rightIn];
if(nowAr[i][j]==1&&(countIn==2||countIn==3)){
nextAr[i][j]=1;
}
else if(nowAr[i][j]==0&&countIn==3){
nextAr[i][j]=1;
}
else{
nextAr[i][j]=0;
}
}
}
for(var ii:int=0;ii<numIn;ii++){
for(var jj:int=0;jj<numIn;jj++){
nowAr[ii][jj]=nextAr[ii][jj];
}
}
dispF();
}
private function positF():void{
this.x=(stage.stageWidth-numIn)/2;
this.y=(stage.stageHeight-numIn)/2;
stage.quality=StageQuality.LOW;
}
}
}