Author Topic: Observations of Cellular Automata simulating particles  (Read 12174 times)

0 Members and 2 Guests are viewing this topic.

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Observations of Cellular Automata simulating particles
« Reply #30 on: December 02, 2012, 09:11:15 pm »
Sorry I forgot to mention it, move up and down with E and SHIFT.

Here's the relevant code
Code: [Select]
int[][][] cells = new int[size][size][size];
cells[10][10][10] = 1;
cells[10][10][11] = 1;
cells[10][10][12] = 1;
cells[11][11][10] = 1;
cells[10][11][11] = 1;
cells[10][11][12] = 1;
cells[11][4][10] = 3;
cells[11][4][11] = 3;
cells[11][4][12] = 3;
cells[12][4][10] = 3;
cells[12][4][11] = 3;
cells[12][4][12] = 3;
cells[10][4][10] = 3;
cells[10][4][11] = 3;
cells[10][4][12] = 3;
while (f.isVisible()) {
    int[][][] tempcells = new int[size][size][size];
    for (int x = 1; x < size - 1; x++) {
        for (int y = 1; y < size - 1; y++) {
            System.arraycopy(cells[x][y], 0, tempcells[x][y], 0, tempcells[x][y].length);
        }
    }
    for (int x = 1; x < size - 1; x++) {
        for (int y = 1; y < size - 1; y++) {
            for (int z = 1; z < size - 1; z++) {
                if (simtype == 0) {
                    tempcells[x][y][z] = rule3DGOL(x, y, z, sumCells(cells, x, y, z), cells);
                } else if (simtype == 1) {
                    tempcells[x][y][z] = ruleFlow(x, y, z, sumCells(cells, x, y, z), cells);
                }
            }
        }
    }
    cells = tempcells;
    DisplayList dl = new DisplayList();
    int cubes = 0;
    for (int x = 1; x < size - 1; x++) {
        for (int y = 1; y < size - 1; y++) {
            for (int z = 1; z < size - 1; z++) {
                if (cells[x][y][z] > 0) {
                    cubes++;
                    Cube c = new Cube(new Point3D(x, y, -z), new Point3D(.45, .45, .45), dl);
                    c.setMaterial(new Material(new Color(cells[x][y][z] * 50, 255 - cells[x][y][z] * 50, 0), Color.white, Color.black, 63, null), dl);
                }
            }
        }
    }
    totalc = cubes;
    displist = dl;
    try {
        Thread.sleep(10 * delay);
    } catch (Exception e) {

    }
}

static public int sumCells(int[][][] i, int x, int y, int z) {
    return  i[++x][y][z] + i[x][++y][z] + i[x][y][z + 1] + i[x][--y][z + 1] + i[x][--y][z + 1] + i[x][y][z] + i[x][y][z - 1] + i[x][++y][z - 1] + i[x][++y][z - 1] +
                         i[--x][y][z] + i[x][y][z + 1] + i[x][--y][z + 1] + i[x][--y][z + 1] + i[x][y][z] + i[x][y][z - 1] + i[x][++y][z - 1] + i[x][++y][z - 1] +
            i[--x][y][z] + i[x][y][z] + i[x][y][z + 1] + i[x][--y][z + 1] + i[x][--y][z + 1] + i[x][y][z] + i[x][y][z - 1] + i[x][++y][z - 1] + i[x][++y][z - 1];
}

static public int rule3DGOL(int x, int y, int z, int sum, int[][][] i) {
    if (sum == 2 || sum == 3 && i[x][y][z] == 1) {
        return 1;
    } else if (sum == 3 && i[x][y][z] == 0) {
        return 1;
    } else if (sum == 4 || sum == 5 && i[x][y][z] == 2) {
        return 2;
    } else if (sum == 5 && i[x][y][z] == 1) {
        return 2;
    } else if (sum == 6 || sum == 7 && i[x][y][z] == 3) {
        return 3;
    } else if (sum == 7 && i[x][y][z] == 2) {
        return 3;
    } else if (sum == 8 || sum == 9 && i[x][y][z] == 4) {
        return 4;
    } else if (sum == 9 && i[x][y][z] == 3) {
        return 4;
    } else if (sum < 2 || sum > 9 && i[x][y][z] == 1) {
        return 0;
    } else {
        return 0;
    }
}

static public int ruleFlow(int x, int y, int z, int sum, int[][][] i) {
    if (i[x][y][z] == 0 && i[x][y + 1][z] == 1) {
        return 1;
    } else if ((i[x + 1][y][z] == 1 || i[x][y][z + 1] == 1 || i[x - 1][y][z] == 1 || i[x][y][z - 1] == 1) && i[x][y - 1][z] == 3 && i[x][y][z] == 0) {
        return 1;
    } else if (((i[x + 1][y][z] == 1 && i[x + 1][y - 1][z] == 3)
            || (i[x][y][z + 1] == 1 && i[x][y - 1][z + 1] == 3)
            || (i[x - 1][y][z] == 1 && i[x - 1][y - 1][z] == 3)
            || (i[x][y][z - 1] == 1 && i[x][y - 1][z - 1] == 3))
            && i[x][y - 1][z] == 0 && i[x][y][z] == 0) {
        return 1;
    } else if (((i[x + 1][y - 1][z] == 0)
            || (i[x][y - 1][z + 1] == 0)
            || (i[x - 1][y - 1][z] == 0)
            || (i[x][y - 1][z - 1] == 0))
            && i[x][y - 1][z] == 3 && i[x][y][z] == 1) {
        return 0;
    } else if (i[x][y][z] == 1 && i[x][y + 1][z] == 0) {
        return 0;
    } else {

        return i[x][y][z];
    }
}
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Observations of Cellular Automata simulating particles
« Reply #31 on: December 02, 2012, 10:41:30 pm »
Wow, that is looking pretty epic, great work there! :D

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!