|
int sx, sy;
float density =0.1;
int[][][] world;
int d=10;
void setup() {
size(1000, 600, P2D);
frameRate(10);
sx = width;
sy = height;
world = new int[sx][sy][2];
// Set random cells to 'on'
for (int i = 0; i < sx * sy * density; i+=d) {
world[d*int(random(sx/d))][d*int(random(sy/d))][1] = 1;
}
}
void draw()
{
background(0);
for(int a=5;a 3) && world[x][y][0] == 1)
{
world[x][y][1] = -1;
}
}
}
}
// Count the number of adjacent cells 'on'
int neighbors(int x, int y)
{
return world[(x + d) % sx][y][0] +
world[x][(y + d) % sy][0] +
world[(x + sx - d) % sx][y][0] +
world[x][(y + sy - d) % sy][0] +
world[(x + d) % sx][(y + d) % sy][0] +
world[(x + sx - d) % sx][(y + d) % sy][0] +
world[(x + sx - d) % sx][(y + sy - d) % sy][0] +
world[(x + d) % sx][(y + sy - d) % sy][0];
}
void mouseClicked() {
int a=int(mouseX);
int b=int(mouseY);
if (a%10<=5 && b%10<=5 ){
world[a-a%10][b-b%10][0]=1;
}
if (a%10<=5 && b%10>5 ){
world[a-a%10][b-b%10+10][0]=1;
}
if (a%10>5 && b%10<=5 ){
world[a-a%10+10][b-b%10][0]=1;
}
if (a%10>5 && b%10>5 ){
world[a-a%10+10][b-b%10+10][0]=1;
}
}
[local]1[/local][local]1[/local] |
评分
-
查看全部评分
|