public SimulationEngine(SimulationConfig config)
        {
            this.config = config;
            rnd         = new Random();

            //stwórz przestrzen automatu
            board = new Cell[config.boardSizeX, config.boardSizeY];
            for (int i = 0; i < config.boardSizeX; i++)
            {
                for (int j = 0; j < config.boardSizeY; j++)
                {
                    board[i, j] = new Cell();
                }
            }

            //stwórz listę ziaren
            grainList = new List <Grain>();
            for (int i = 0; i < config.grainsCount; i++)
            {
                grainList.Add(new Grain(i, config.grainsCount));
            }

            //rozmieść zarodki
            switch (config.seedPlacement)
            {
            case 0:
                //losowe
                GenerateRandomSeeds();
                break;

            case 1:
                //równomierne
                GenerateEqualSeeds();
                break;

            case 2:
                //losowe z promieniem
                GenerateRandomSeedsWithDistance();
                break;
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //GENEROWANIE PLANSZY
            timer1.Enabled = false;

            //Wstawiam wartości do konfiguracji dla symulacji
            config                       = new SimulationConfig();
            config.boardSizeX            = Int32.Parse(textBox1.Text);
            config.boardSizeY            = Int32.Parse(textBox2.Text);
            config.grainsCount           = Int32.Parse(textBox3.Text);
            config.grainXsize            = pictureBox1.Size.Width / config.boardSizeX;
            config.grainYsize            = pictureBox1.Size.Height / config.boardSizeY;
            config.minimalGrainsDistance = 0;
            if (!textBox4.ReadOnly)
            {
                config.minimalGrainsDistance = Int32.Parse(textBox4.Text);
            }
            config.simulationType = comboBox3.SelectedIndex;
            config.seedPlacement  = comboBox2.SelectedIndex;
            config.pbc            = false;
            if (comboBox1.SelectedIndex == 0)
            {
                config.pbc = true;
            }

            //Inicjalizuje silnik symulacji
            engine = new SimulationEngine(config);          //chyba wszystko

            //Inicjalizuj generator bitmap
            bitmapGenerator = new BitmapGenerator(config.boardSizeX, config.boardSizeY, pictureBox1.Size.Width, pictureBox1.Size.Height);

            //Narysuj przestrzeń
            bitmapGenerator.GenerateBitmap(engine.board, engine.grainList);

            pictureBox1.Image = bitmapGenerator.bmp;
        }