На юнити не работает математика, а почему я не понимаю…
Вот GofL cамый живучий вариант.
Blitz3D
Graphics 640,480,16,2
Const UPS=60
Global x_grid
Global y_grid
x_grid=77
y_grid=77
Dim g1%(x_grid,y_grid)
Dim g2%(x_grid,y_grid)
Dim cube(x_grid,y_grid)
period=1000/UPS
time=MilliSecs()-period
For x=0 To x_grid
For y=0 To y_grid
g1%(x,y)=Rand(0,1)
Next
Next
Repeat
Repeat
elapsed=MilliSecs()-time
Until elapsed
ticks=elapsed/period
tween#=Float(elapsed Mod period)/Float(period)
For k=1 To ticks
time=time+period
If KeyHit(1) End
gen()
Next
Flip
Cls
Forever
Function gen()
For x=1 To x_grid-1
For y=1 To y_grid-1
c=0
For x1=-1 To 1
For y1=-1 To 1
If (x1)<>0 Or (y1)<>0
c=c+g1%((x1)+x,(y1)+y)
EndIf
Next
Next
If c<2 Or c>3 Then c=0
If c=2 Then c=g1%(x,y)
If c>2 Then c=1
g2%(x,y)=c
If g1%(x,y)=1
Plot x*2,y*2
EndIf
g1%(x-1,y-1)=g2%(x-1,y-1)
Next
Next
End Function
Порт ~ Unity
using UnityEngine;
using System.Collections;
public class LG : MonoBehaviour {
public int[,] g1 = new int[77,77];
public int[,] g2 = new int[77,77];
public GameObject[,] cube = new GameObject[77,77];
public int x_grid=77;
public int y_grid=77;
private int c=0;
void Start () {
for (int x = 0; x < x_grid; x++) {
for (int y = 0; y < y_grid; y++) {
cube[x,y] = GameObject.CreatePrimitive (PrimitiveType.Cube);
cube[x,y].transform.position = new Vector3 (x * 2, 0, y * 2);
cube[x,y].transform.localScale = new Vector3 (2, 2, 2);
cube[x,y].renderer.material.color = new Color(x *0.1f,0,y *0.1f);
g1[x,y]=Random.Range(0, 1);
}
}
}
void Update () {
//gen()
for (int x =1; x < x_grid-1; x++) {
for (int y = 1; y < y_grid-1; y++) {
c=0;
for (int x1 = -1; x1 < 1; x1++) {
for (int y1 = -1; y1 < 1; y1++) {
if (x1<0 || x1>0 || y1<0 || y1>0){c+=g1[x+x1,y+y1];}
}
}
if (c<2 || c>3){c=0;}
if (c>=2){c=g1[x,y];}
if (c>2) {c=1;}
g2[x,y]=c;
if (g1[x,y]>=1) {
cube[x,y].active= true;
}
else{
cube[x,y].active= false;
}
g1[x-1,y-1]=g2[x-1,y-1];
}
}
//gen()
}
}
Трансляция:
https://www.twitch.tv/foxymist