public Range InitializeNucleons(Range tempRange, InitNucleons nucleons)
        {
            // randomize nucleon states
            for (int i = 0; i < nucleons.NucleonsStates.Length; i++)
            {
                NucleonsStates[i] = Color.FromArgb(Random.Next(50, 200), 0, 0);
            }

            // anywhere
            if (PositionDistribiution == PositionDistribiution.Anywhere)
            {
                Point coordinates;
                for (int i = 0; i < nucleons.AmountOfNucleons; i++)
                {
                    do
                    {
                        coordinates = RandomCoordinates.Get(tempRange.Width, tempRange.Height, Random);
                    }while (tempRange.GrainsArray[coordinates.X, coordinates.Y].Id <= 0);

                    tempRange.GrainsArray[coordinates.X, coordinates.Y].Id    = (int)SpecialId.Id.Nucleon;
                    tempRange.GrainsArray[coordinates.X, coordinates.Y].Color = NucleonsStates[Random.Next(nucleons.NucleonsStates.Length)];
                }
            }
            // on grain boundaries
            else
            {
                Point coordinates;
                for (int i = 0; i < nucleons.AmountOfNucleons; i++)
                {
                    do
                    {
                        coordinates = RandomCoordinates.Get(tempRange.Width, tempRange.Height, Random);
                    }while (!InitBoundaries.IsOnGrainBoundaries(tempRange, coordinates) && !SpecialId.IsIdSpecial(tempRange.GrainsArray[coordinates.X, coordinates.Y].Id));

                    tempRange.GrainsArray[coordinates.X, coordinates.Y].Id    = (int)SpecialId.Id.Nucleon;
                    tempRange.GrainsArray[coordinates.X, coordinates.Y].Color = NucleonsStates[Random.Next(nucleons.NucleonsStates.Length)];
                }
            }

            tempRange.IsFull = false;
            return(tempRange);
        }
        public Range UpdateSubstructuresCA(Range tempRange, MainProperties properties)
        {
            bool change;

            for (int i = 1; i < tempRange.Width - 1; i++)
            {
                for (int j = 1; j < tempRange.Height - 1; j++)
                {
                    change = false;
                    foreach (var point in SubStrucrtuePointsList)
                    {
                        if (tempRange.GrainsArray[i, j].Color == tempRange.StructureBitmap.GetPixel(point.X, point.Y))
                        {
                            if (properties.SubstructuresType == SubstructuresType.Substructure)
                            {
                                tempRange.GrainsArray[i, j] = new Grain
                                {
                                    Id    = (int)SpecialId.Id.Substructure,
                                    Color = tempRange.GrainsArray[i, j].Color
                                };
                            }
                            else
                            {
                                tempRange.GrainsArray[i, j] = new Grain
                                {
                                    Id    = (int)SpecialId.Id.DualPhase,
                                    Color = Color.Pink
                                };
                            }

                            change = true;
                        }
                    }
                    if (tempRange.GrainsArray[i, j].Id == -2)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Inclusion,
                            Color = Color.Black
                        };
                        change = true;
                    }
                    if (change == false)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Empty,
                            Color = Color.White
                        };
                    }
                }
            }

            Point coordinates;

            for (int i = 1; i <= properties.AmountOfGrains; i++)
            {
                while (true)
                {
                    coordinates = RandomCoordinates.Get(tempRange.Width, tempRange.Height, Random);

                    if (tempRange.GrainsArray[coordinates.X, coordinates.Y].Id == 0)
                    {
                        tempRange.GrainsArray[coordinates.X, coordinates.Y].Color = Color.FromArgb(Random.Next(10, 240), Random.Next(10, 240), Random.Next(10, 240));
                        tempRange.GrainsArray[coordinates.X, coordinates.Y].Id    = Random.Next(1, 1000000);
                        break;
                    }
                }
            }

            tempRange.IsFull = false;
            return(tempRange);
        }
        public Range UpdateSubstructuresSRX(Range tempRange, MainProperties properties)
        {
            for (int i = 1; i < tempRange.Width - 1; i++)
            {
                for (int j = 1; j < tempRange.Height - 1; j++)
                {
                    if (tempRange.GrainsArray[i, j].Id == (int)SpecialId.Id.Nucleon)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Empty,
                            Color = Color.White
                        };
                    }
                    else if (tempRange.GrainsArray[i, j].Id > 0)
                    {
                        tempRange.GrainsArray[i, j] = new Grain
                        {
                            Id    = (int)SpecialId.Id.Substructure,
                            Color = tempRange.GrainsArray[i, j].Color
                        };
                    }
                }
            }

            if (properties.MethodType == MethodType.CellularAutomata)
            {
                Point coordinates;
                for (int grainNumber = 1; grainNumber <= properties.AmountOfGrains; grainNumber++)
                {
                    do
                    {
                        coordinates = RandomCoordinates.Get(tempRange.Width, tempRange.Height, Random);
                    }while (tempRange.GrainsArray[coordinates.X, coordinates.Y].Id != 0);

                    tempRange.GrainsArray[coordinates.X, coordinates.Y].Color = InitStructures.AllGrainsTypes[grainNumber - 1].Color;
                    tempRange.GrainsArray[coordinates.X, coordinates.Y].Id    = InitStructures.AllGrainsTypes[grainNumber - 1].Id;
                }
            }
            else
            {
                InitStructures.AllGrainsTypes = new Grain[properties.AmountOfGrains];

                // set random starting coordinates [x,y] and color for grains
                for (int grainNumber = 1; grainNumber <= properties.AmountOfGrains; grainNumber++)
                {
                    InitStructures.AllGrainsTypes[grainNumber - 1] = new Grain()
                    {
                        Color = Color.FromArgb(Random.Next(10, 240), Random.Next(10, 240), Random.Next(10, 240)),
                        Id    = grainNumber
                    };
                }
                for (int i = 1; i < tempRange.Width - 1; i++)
                {
                    for (int j = 1; j < tempRange.Height - 1; j++)
                    {
                        if (tempRange.GrainsArray[i, j].Id == 0)
                        {
                            int r = Random.Next(InitStructures.AllGrainsTypes.Length);
                            tempRange.GrainsArray[i, j] = new Grain()
                            {
                                Id    = InitStructures.AllGrainsTypes[r].Id,
                                Color = InitStructures.AllGrainsTypes[r].Color
                            };
                        }
                    }
                }
            }


            return(tempRange);
        }