コード例 #1
0
        private getneighbours getNeighboursDelegate(neigbhourhoodType type)
        {
            switch (type)
            {
            case neigbhourhoodType.MoorePeriodic:
                return(new getneighbours(getNeighboursMoorePeriodic));

            case neigbhourhoodType.VonNoyman:
                return(new getneighbours(getNeigboursVonNoyman));

            case neigbhourhoodType.VonNoymanPeriodic:
                return(new getneighbours(getNeigboursVonNoymanPeriodic));

            case neigbhourhoodType.Moore:
                return(new getneighbours(getNeighboursMoore));

            case neigbhourhoodType.HexagonalRandom:
                return(new getneighbours(getNeighboursRandomHexagonal));

            case neigbhourhoodType.HexagonalRandomPeriodic:
                return(new getneighbours(getNeighboursRandomHexagonalPeriodic));

            case neigbhourhoodType.PentagonalRandom:
                return(new getneighbours(getNeighboursRandomPentagonal));

            case neigbhourhoodType.PentagonalRandomPeriodic:
                return(new getneighbours(getNeighboursRandomPentagonalPeriodic));
            }
            return(null);
        }
コード例 #2
0
 public virtual void Iterate(Action oniterate, neigbhourhoodType neigbhourhoodType)
 {
     getneighbours = getNeighboursDelegate(neigbhourhoodType);
     work          = true;
     while (work)
     {
         ComputeNextIterationCells();
         oniterate();
     }
 }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            {
                if (worker.IsBusy)
                {
                    seedgtowth?.stop();
                }


                simulationDisplayer?.Dispose();
                width  = Convert.ToInt32(textBox1.Text == "" ? "300" : textBox1.Text);
                height = Convert.ToInt32(textBox2.Text == "" ? "300" : textBox2.Text);
                int seeds = Convert.ToInt32(textBox3.Text == "" ? "3" : textBox3.Text);

                seedgtowth = new SeedGrowth(width, height);


                simulationDisplayer                        = new Form2();
                simulationDisplayer.Size                   = new Size(width + 20, height + 45);
                simulationDisplayer.pictureBox.Size        = new Size(width, height);
                simulationDisplayer.Disposed              += Form2_Disposed;
                simulationDisplayer.pictureBox.MouseClick += PictureBox1_MouseClick1;
                switch ((String)comboBox3.SelectedItem)
                {
                case "Random":

                    seedgtowth.setSeedsRandomly(seeds);
                    break;

                case "Evenly":
                    int xasisseeds = Convert.ToInt32(textBox4.Text == "" ? "3" : textBox4.Text);
                    int yaxisseeds = Convert.ToInt32(textBox5.Text == "" ? "3" : textBox5.Text);
                    seedgtowth.setSeedsEvenly(xasisseeds, yaxisseeds);
                    break;

                case "RandomWithRadius":
                    int radius = Convert.ToInt32(textBox6.Text == "" ? "3" : textBox6.Text);
                    seedgtowth.setSeedswithRadius(seeds, radius);
                    break;

                case "ByClick":
                    simulationDisplayer.pictureBox.MouseClick += PictureBox1_MouseClick1;
                    break;
                }


                switch ((string)comboBox1.SelectedValue)
                {
                case "Normal":
                    switch ((string)comboBox2.SelectedValue)
                    {
                    case "Moore":
                        neigbhourhoodType = neigbhourhoodType.Moore;
                        break;

                    case "VonNoyman":
                        neigbhourhoodType = neigbhourhoodType.VonNoyman;
                        break;

                    case "RandomPentagonal":
                        neigbhourhoodType = neigbhourhoodType.PentagonalRandom;
                        break;

                    case "RandomHexagonal":
                        neigbhourhoodType = neigbhourhoodType.HexagonalRandom;
                        break;
                    }
                    break;

                case "Periodic":
                    switch ((string)comboBox2.SelectedValue)
                    {
                    case "Moore":
                        neigbhourhoodType = neigbhourhoodType.MoorePeriodic;
                        break;

                    case "VonNoyman":
                        neigbhourhoodType = neigbhourhoodType.VonNoymanPeriodic;
                        break;

                    case "RandomPentagonal":
                        neigbhourhoodType = neigbhourhoodType.PentagonalRandomPeriodic;
                        break;

                    case "RandomHexagonal":
                        neigbhourhoodType = neigbhourhoodType.HexagonalRandomPeriodic;
                        break;
                    }
                    break;
                }

                button6.Text = "Stop";
                simulationDisplayer.Show();



                worker         = new BackgroundWorker();
                worker.DoWork += Worker_DoWork;
                worker.WorkerSupportsCancellation = true;
                worker.RunWorkerAsync();
            }
        }