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); }
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]); } }
public void Reviev(Grain aliveNeighbour) { this.Alive = true; this.PenColor = aliveNeighbour.PenColor; }
private void SaveGrainInArrays(int xPosition, int yPosition, Grain grain) { GrainsInPreviousStep[xPosition, yPosition] = grain; GrainsInCurrentStep[xPosition, yPosition] = grain; }