/* * RunSimulation is used to setup the variables and call the various method to setup the simulation. * When the setup is complete it runs a for loop for the amount of Cycles calling the method RunCycle() in each iteration. */ public void RunSimulation(int Width, int Height, int Cycles, double FeedRate_A, double KillRate_B, ELaplacianFunctions laplacianEnum, EShadingAlgorthims shadingEnum, bool displayGrid) { this.Width = Width; this.Height = Height; this.Cycles = Cycles; this.FeedRate_A = FeedRate_A; this.KillRate_B = KillRate_B; this.laplacianEnum = laplacianEnum; //Data Fields are being set this.shadingEnum = shadingEnum; this.displayGrid = displayGrid; CurrentCycle = 0; progressbar.Maximum = Cycles; progressbar.Value = 0; SeedValue = 0.25; gridDrawer = new GridDrawer(canvas, Width, Height, shadingEnum); //Instance of GridDrawer is created which is later used to draw or save the grid. LapFactory = new LaplacianFactory(); LapFunction = LapFactory.CreateNewLaplacian(laplacianEnum); //LapFunction instance is created using the CreateNewLaplacian method from LapFactory. Diffusion_A = LapFunction.GetDiffusion_A(); //The Diffusion A and B differ depending upon what Lapacian function is used. Diffusion_B = LapFunction.GetDiffusion_B(); SetCellGrid(); //The CellGrid is set and filled up with a seed; SetCellNeighbours(); //In the entre grid all the cells are passed the Cells neighbouring them. Stop(); //Called so the canvas is cleared for (int cycleNum = 0; cycleNum < Cycles; cycleNum++) //Loops through the cycles calling RunCycle each time. { RunCycle(); } }
/* * GridDrawer constructer takes in various parameters then sets them to setup the GridDrawer. */ public GridDrawer(Graphics canvas, int Width, int Height, EShadingAlgorthims shadingEnum) { this.canvas = canvas; this.Width = Width; this.Height = Height; shadingFactory = new ShadingFactory(); //Creates an instance of ShadingFactory ShadingAlgorithm = shadingFactory.CreateNewShadeing(shadingEnum); //calls the CreateNewShadeing method of ShadingFactory to return the ShadingAlgorithm requested. }
/* * CreateNewShadeing takes in a enum representing the ShadingAlgorthim which is wanted. * The switch then creates that ShadingAlgorthim and returns it so the GridDrawer class does not need to know how its created. */ public IShading CreateNewShadeing(EShadingAlgorthims shade) { IShading newShade = null; switch (shade) { case EShadingAlgorthims.GRAYSCALE: newShade = new GrayScale(); break; case EShadingAlgorthims.SHORT_RAINBOW: newShade = new ShortRainbow(); break; case EShadingAlgorthims.LONG_RAINBOW: newShade = new LongRainbow(); break; case EShadingAlgorthims.YELLOW_TO_RED: newShade = new YellowToRed(); break; } return(newShade); }