Ejemplo n.º 1
0
        public List <Grain> InitializeBoard(int boardWidth, int boardHeight, int penColors)
        {
            Random random = new Random();

            for (int i = 0; i < penColors; i++)
            {
                Pen color = new Pen(Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 255)));
                PenColors.Add(color);
            }

            for (int i = 0; i < boardWidth; i++)
            {
                for (int j = 0; j < boardHeight; j++)
                {
                    Point position   = new Point(i, j);
                    int   colorIndex = random.Next(PenColors.Count);
                    Grain grain      = new Grain(position, PenColors[colorIndex]);
                    grain.SetGrainAlive();

                    Grains.Add(grain);
                }
            }
            return(Grains);
        }
Ejemplo n.º 2
0
        private void ChangeGrainEnergy(List <Grain> energies)
        {
            Random rand = new Random();

            for (int i = 0; i < Int32.Parse(textBox11.Text); i++)
            {
                int randIndex = rand.Next(0, energies.Count - 1);

                for (int j = 0; j < pictureBox1.Size.Width - 1; j++)
                {
                    for (int k = 0; k < pictureBox1.Size.Height - 1; k++)
                    {
                        if (j == energies[randIndex].Position.X && k == energies[randIndex].Position.Y)
                        {
                            Grain tempGrain = new Grain(new Point(j, k), new Pen(Color.FromArgb(rand.Next(0, 255), 0, 0)));
                            tempGrain.H = 0;

                            board.GrainsInPreviousStep[j, k] = tempGrain;
                        }
                    }
                }
                energies.Remove(energies[randIndex]);
            }
        }
Ejemplo n.º 3
0
 public void Reviev(Grain aliveNeighbour)
 {
     this.Alive    = true;
     this.PenColor = aliveNeighbour.PenColor;
 }
Ejemplo n.º 4
0
 private void SaveGrainInArrays(int xPosition, int yPosition, Grain grain)
 {
     GrainsInPreviousStep[xPosition, yPosition] = grain;
     GrainsInCurrentStep[xPosition, yPosition]  = grain;
 }