/// <summary>
 /// Creates a new Gray-Scott Diffusion Reaction with the given parameters
 /// </summary>
 public GrayScottDiffusionReaction(Grid grid, double feedA, double killB, LaplacianFunction lap)
 {
     Grid = grid;
     FeedA = feedA;
     KillB = killB;
     Lap = lap;
     iterations = 0;
 }
Ejemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();

            Cell prefabCell = new Cell
            {
                { GrayScottDiffusionReaction.CHEMICAL_A, 0 },
                { GrayScottDiffusionReaction.CHEMICAL_B, 0 }
            };

            Grid grid = new Grid(GRID_SIZE, prefabCell);
            grid.Seed(grid.Size / 2, grid.Size / 2, 2, 2, GrayScottDiffusionReaction.CHEMICAL_B, 1);    // Seed central area with B = 1

            reaction = new GrayScottDiffusionReaction(grid, FEED_A, KILL_B, new PerpendicularNeighboursLaplacianFunction());

            renderer = new NETGridRenderer(grid, new GreyscaleShader())
            {
                CellWidth = 4,
                CellHeight = 4
            };
        }
 /// <summary>
 /// A grid renderer that draws each cell in the grid with the given dimensions
 /// </summary>
 public GridRenderer(Grid grid, IShader shader)
 {
     Grid = grid;
     Shader = shader;
 }
 /// <summary>
 /// Creates a renderer object that uses the .NET graphics library to renderer the given grid. A graphics object must be passed to 
 /// this renderer prior to any draw calls or a null reference exception will be raised.
 /// </summary>
 public NETGridRenderer(Grid grid, IShader shader)
     : base(grid, shader)
 {
     /* Nothing */
 }
        public void Update()
        {
            // Create new array of cells so as to not overwrite old values while still performing calculations
            Grid grid = new Grid(Grid.Size);

            // Iterate through entire grid of cells
            for (int column = 0; column < Grid.Size; column++)
            {
                for (int row = 0; row < Grid.Size; row++)
                {
                    // Calculate next iteration of A and B
                    double A = NextA(column, row);
                    double B = NextB(column, row);

                    // Create new cell containing new A and B concentrations
                    grid[column, row] = new Cell
                    {
                        { CHEMICAL_A, A },
                        { CHEMICAL_B, B }
                    };
                }
            }

            // Assign new array of cells to grid object, overwritting old array
            Grid.Overwrite(grid);

            // Keep track of the number of iterations this reaction has been running for
            iterations++;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Overwrites the concentrations stored in this grid's cells with the concentrations from the cells in the given grid.
 /// </summary>
 public void Overwrite(Grid grid)
 {
     Cells = grid.Cells;
 }
 public void GrayScottDiffusionReactionTest()
 {
     // New grid with concentrations set to 0
     Grid grid = new Grid(3);
 }