Untitled
unknown
plain_text
2 years ago
2.9 kB
4
Indexable
package python; public class AshCloud { int size = 7; double f = 0.8; double[][] world = null; public AshCloud (int n, double f) { double function = f; // f is the forward factor int size = n; // n is the size of the grid double[][] world = new double[size][size]; // creates a new world world[size/2][size/2] = 1; // sets the middle of the world to 1 } public double [][] runSimulation1 (char dir , int steps ) { double[][] world = new double[size][size]; // creates a new world world[size/2][size/2] = 1; // sets the middle of the world to 1 int size = world.length; // gets the size of the world double[][] newWorld = new double[size][size]; // creates a new world int row = 0; // sets the row to 0 int col = 0; // sets the column to 0 int row2 = 0; // sets the row to 0 int col2 = 0; // sets the column to 0 double function = f; // f is the forward factor int noOfSteps = steps; // steps is the number of steps char direction = dir; // dir is the direction for (int i = 0; i < noOfSteps; i++) { // for loop that runs the number of steps for (row = 0; row < size; row++) { // for loop that runs the number of rows for (col = 0; col < size; col++) { // for loop that runs the number of columns if (world[row][col] > 0) { // if the cell is greater than 0 if (direction == 'N') { // if the direction is north row2 = row - 1; // sets the row to the row above col2 = col; // sets the column to the same column if (row2 < 0) { // if the row is less than 0 row2 = size - 1; // sets the row to the last row } } if (direction == 'S') { // if the direction is south row2 = row + 1; // sets the row to the row below col2 = col; // sets the column to the same column if (row2 > size - 1) { // if the row is greater than the last row row2 = 0; // sets the row to 0 } } if (direction == 'E') { // if the direction is east row2 = row; // sets the row to the same row col2 = col + 1; // sets the column to the column to the right if (col2 > size - 1) { // if the column is greater than the last column col2 = 0; // sets the column to 0 } } } } } } return newWorld; } }
Editor is loading...