Exemplo n.º 1
0
 //initialises the properties
 private void Form1_Load(object sender, EventArgs e)
 {
     canvasBounds = new Rectangle(25, 25, GRIDSIZE*CELLSIZE, GRIDSIZE*CELLSIZE);
     pattern = new Bitmap((GRIDSIZE * (CELLSIZE * CELLSIZE)), (GRIDSIZE * (CELLSIZE * CELLSIZE)));
     canvas = Graphics.FromImage(pattern);
     formGraphics = CreateGraphics();
     lapFunc = null;
     iterationNum = 0;
 }
Exemplo n.º 2
0
 //initialises the properties
 private void Form1_Load(object sender, EventArgs e)
 {
     canvasBounds = new Rectangle(25, 25, GRIDSIZE * CELLSIZE, GRIDSIZE * CELLSIZE);
     pattern      = new Bitmap((GRIDSIZE * (CELLSIZE * CELLSIZE)), (GRIDSIZE * (CELLSIZE * CELLSIZE)));
     canvas       = Graphics.FromImage(pattern);
     formGraphics = CreateGraphics();
     lapFunc      = null;
     iterationNum = 0;
 }
Exemplo n.º 3
0
        //runs the batch simulation
        public void RunBatchSimulation()
        {
            feedA = 0.001;
            killB = 0.001;
            double        diffA        = 0;
            double        diffB        = 0;
            IColourPicker colourScheme = new GrayScaleColours();

            for (int i = 0; i < 3; i++)
            {
                //set laplacian function and related diffusion rates
                if (i == 0)
                {
                    lapFunc = LaplacianFunctions.PerpendicularLaplacian;
                    diffA   = perpDiffA;
                    diffB   = PerpDiffB;
                }
                else if (i == 1)
                {
                    lapFunc = LaplacianFunctions.ConvolutionLaplacian;
                    diffA   = convDeltDiffA;
                    diffB   = convDeltDiffB;
                }
                else if (i == 2)
                {
                    lapFunc = LaplacianFunctions.DeltaMeansLaplacian;
                    diffA   = convDeltDiffA;
                    diffB   = convDeltDiffB;
                }

                //changes feed A until it reaches 0.099
                while (feedA <= 0.099)
                {
                    //changes kill b untill it reaches 0.099
                    while (killB <= 0.099)
                    {
                        //makes a new grid with those numbers
                        grid = new Grid(canvas, bounds, lapFunc, colourScheme, cellSize, gridSize, diffA, diffB, feedA, killB);
                        //runs throught the simulation for 5000 iterations - enough to become stable
                        for (int j = 0; j < numOfIterations; j++)
                        {
                            grid.GetCellsNextValues();
                            grid.UpdateCellsValues();
                        }
                        //once it has become stable draws to screen then saves the image
                        grid.DrawGrid();
                        formGraphics.DrawImage(pattern, 0, 0);
                        SaveImage();

                        killB += 0.001;
                    }
                    feedA += 0.001;
                    killB  = 0.001;
                }
            }
        }
Exemplo n.º 4
0
 //second constructor used for user input simulation
 public SimulationManager(Bitmap pattern, Graphics canvas, Graphics formGraphics, Rectangle bounds, LaplacianDelegate lapFunc, IColourPicker colourScheme,
     int cellSize, int gridSize, double diffA, double diffB, double feedA, double killB)
 {
     this.pattern = pattern;
     this.canvas = canvas;
     this.formGraphics = formGraphics;
     this.cellSize = cellSize;
     this.gridSize = gridSize;
     this.feedA = feedA;
     this.killB = killB;
     grid = new Grid(canvas, bounds, lapFunc, colourScheme, cellSize, gridSize, diffA, diffB, feedA, killB);
 }
Exemplo n.º 5
0
 //grid constructor - passes in needed variables
 //initialises 2d array of cells and fills it
 public Grid(Graphics canvas, Rectangle gridBounds, LaplacianDelegate lapFunc, IColourPicker colourScheme, int cellSize, int gridSize,
     double diffA, double diffB, double feedA, double killB)
 {
     this.gridBounds = gridBounds;
     this.cellSize = cellSize;
     this.gridSize = gridSize;
     this.lapFunc = lapFunc;
     this.colourScheme = colourScheme;
     this.feedA = feedA;
     this.killB = killB;
     this.diffA = diffA;
     this.diffB = diffB;
     gridCanvas = canvas;
     grid = new Cell[gridSize,gridSize];
     InitialGrid();
     GiveEachCellItsNeighbours();
 }
Exemplo n.º 6
0
 //grid constructor - passes in needed variables
 //initialises 2d array of cells and fills it
 public Grid(Graphics canvas, Rectangle gridBounds, LaplacianDelegate lapFunc, IColourPicker colourScheme, int cellSize, int gridSize,
             double diffA, double diffB, double feedA, double killB)
 {
     this.gridBounds   = gridBounds;
     this.cellSize     = cellSize;
     this.gridSize     = gridSize;
     this.lapFunc      = lapFunc;
     this.colourScheme = colourScheme;
     this.feedA        = feedA;
     this.killB        = killB;
     this.diffA        = diffA;
     this.diffB        = diffB;
     gridCanvas        = canvas;
     grid = new Cell[gridSize, gridSize];
     InitialGrid();
     GiveEachCellItsNeighbours();
 }
Exemplo n.º 7
0
        //runs the batch simulation
        public void RunBatchSimulation()
        {
            feedA = 0.001;
            killB = 0.001;
            double diffA = 0;
            double diffB = 0;
            IColourPicker colourScheme = new GrayScaleColours();
            for(int i = 0; i < 3; i++)
            {
                //set laplacian function and related diffusion rates
                if(i == 0)
                {
                    lapFunc = LaplacianFunctions.PerpendicularLaplacian;
                    diffA = perpDiffA;
                    diffB = PerpDiffB;
                }
                else if (i == 1)
                {
                    lapFunc = LaplacianFunctions.ConvolutionLaplacian;
                    diffA = convDeltDiffA;
                    diffB = convDeltDiffB;
                }
                else if (i == 2)
                {
                    lapFunc = LaplacianFunctions.DeltaMeansLaplacian;
                    diffA = convDeltDiffA;
                    diffB = convDeltDiffB;
                }

                //changes feed A until it reaches 0.099
                while(feedA <= 0.099)
                {
                    //changes kill b untill it reaches 0.099
                    while (killB <= 0.099)
                    {
                        //makes a new grid with those numbers
                        grid = new Grid(canvas, bounds, lapFunc, colourScheme, cellSize, gridSize, diffA, diffB, feedA, killB);
                        //runs throught the simulation for 5000 iterations - enough to become stable
                        for (int j = 0; j < numOfIterations; j++)
                        {
                            grid.GetCellsNextValues();
                            grid.UpdateCellsValues();
                        }
                        //once it has become stable draws to screen then saves the image
                        grid.DrawGrid();
                        formGraphics.DrawImage(pattern, 0, 0);
                        SaveImage();

                        killB += 0.001;
                    }
                    feedA += 0.001;
                    killB = 0.001;

                }
            }
        }
Exemplo n.º 8
0
        //what happens when the user clicks the run simulation button
        private void runSimBtn_Click(object sender, EventArgs e)
        {
            iterationNum = 0;
            double        diffA = 0, diffB = 0, feedA, killB;
            ColourFactory colourFactory = new ColourFactory();
            IColourPicker colourScheme;

            //gets the selected colour scheme or defaults to grayscale
            if (grayScaleRbtn.Checked)
            {
                colourScheme = colourFactory.MakeColour(ColourChoices.GrayScale);
            }
            else if (blueRbtn.Checked)
            {
                colourScheme = colourFactory.MakeColour(ColourChoices.Colour1);
            }
            else if (redRbtn.Checked)
            {
                colourScheme = colourFactory.MakeColour(ColourChoices.Colour2);
            }
            else
            {
                colourScheme = colourFactory.MakeColour(0);
            }

            try
            {
                //gets the user specified values
                feedA = Convert.ToDouble(feedATxtBox.Text);
                killB = Convert.ToDouble(killBTxtBox.Text);
                if ((feedA > 1) || (killB < 0))
                {
                    MessageBox.Show("Please enter numbers between 0 and 1");
                    feedATxtBox.Text = "";
                    killBTxtBox.Text = "";
                    return;
                }

                //gets the user specified laplacian function to use
                if (perpendicularRbtn.Checked)
                {
                    lapFunc = LaplacianFunctions.PerpendicularLaplacian;
                    diffA   = PERPDIFFA;
                    diffB   = PERPDIFFB;
                }
                else if (convolutionRbtn.Checked)
                {
                    lapFunc = LaplacianFunctions.ConvolutionLaplacian;
                    diffA   = CONVDELTADIFFA;
                    diffB   = CONVDELTADIFFB;
                }
                else if (deltaRbtn.Checked)
                {
                    lapFunc = LaplacianFunctions.DeltaMeansLaplacian;
                    diffA   = CONVDELTADIFFA;
                    diffB   = CONVDELTADIFFB;
                }

                //if a laplacian function has been selected makes a simulation manger
                //then starts the timer
                if (lapFunc != null)
                {
                    manager        = new SimulationManager(pattern, canvas, formGraphics, canvasBounds, lapFunc, colourScheme, CELLSIZE, GRIDSIZE, diffA, diffB, feedA, killB);
                    timer1.Enabled = true;
                }
                else //if laplacian function hasnt been selected
                {
                    MessageBox.Show("Please select a Laplacian Function");
                }
            }
            catch (FormatException) //if user hasn't entered a and b values
            {
                MessageBox.Show("Please enter Values between 0 and 1 for Feed A and Kill B");
            }
        }
Exemplo n.º 9
0
 //second constructor used for user input simulation
 public SimulationManager(Bitmap pattern, Graphics canvas, Graphics formGraphics, Rectangle bounds, LaplacianDelegate lapFunc, IColourPicker colourScheme,
                          int cellSize, int gridSize, double diffA, double diffB, double feedA, double killB)
 {
     this.pattern      = pattern;
     this.canvas       = canvas;
     this.formGraphics = formGraphics;
     this.cellSize     = cellSize;
     this.gridSize     = gridSize;
     this.feedA        = feedA;
     this.killB        = killB;
     grid = new Grid(canvas, bounds, lapFunc, colourScheme, cellSize, gridSize, diffA, diffB, feedA, killB);
 }
Exemplo n.º 10
0
        //what happens when the user clicks the run simulation button
        private void runSimBtn_Click(object sender, EventArgs e)
        {
            iterationNum = 0;
            double diffA = 0, diffB = 0, feedA, killB;
            ColourFactory colourFactory = new ColourFactory();
            IColourPicker colourScheme;

            //gets the selected colour scheme or defaults to grayscale
            if(grayScaleRbtn.Checked)
            {
                colourScheme = colourFactory.MakeColour(ColourChoices.GrayScale);
            }
            else if (blueRbtn.Checked)
            {
                colourScheme = colourFactory.MakeColour(ColourChoices.Colour1);
            }
            else if (redRbtn.Checked)
            {
                colourScheme = colourFactory.MakeColour(ColourChoices.Colour2);
            }
            else
            {
                colourScheme = colourFactory.MakeColour(0);
            }

            try
            {
                //gets the user specified values
                feedA = Convert.ToDouble(feedATxtBox.Text);
                killB = Convert.ToDouble(killBTxtBox.Text);
                if((feedA > 1)||(killB < 0))
                {
                    MessageBox.Show("Please enter numbers between 0 and 1");
                    feedATxtBox.Text = "";
                    killBTxtBox.Text = "";
                    return;
                }

                //gets the user specified laplacian function to use
                if (perpendicularRbtn.Checked)
                {
                    lapFunc = LaplacianFunctions.PerpendicularLaplacian;
                    diffA = PERPDIFFA;
                    diffB = PERPDIFFB;
                }
                else if (convolutionRbtn.Checked)
                {
                    lapFunc = LaplacianFunctions.ConvolutionLaplacian;
                    diffA = CONVDELTADIFFA;
                    diffB = CONVDELTADIFFB;
                }
                else if (deltaRbtn.Checked)
                {
                    lapFunc = LaplacianFunctions.DeltaMeansLaplacian;
                    diffA = CONVDELTADIFFA;
                    diffB = CONVDELTADIFFB;
                }

                //if a laplacian function has been selected makes a simulation manger
                //then starts the timer
                if (lapFunc != null)
                {
                    manager = new SimulationManager(pattern, canvas, formGraphics, canvasBounds, lapFunc, colourScheme, CELLSIZE, GRIDSIZE, diffA, diffB, feedA, killB);
                    timer1.Enabled = true;
                }
                else //if laplacian function hasnt been selected
                {
                    MessageBox.Show("Please select a Laplacian Function");
                }
            }
            catch (FormatException) //if user hasn't entered a and b values
            {
                MessageBox.Show("Please enter Values between 0 and 1 for Feed A and Kill B");
            }
        }