Ejemplo n.º 1
0
        public static bool IsOnGrainBoundaries(Range range, Point point)
        {
            var centerId      = range.GrainsArray[point.X, point.Y].Id;
            var neighboursIds = new List <int>
            {
                range.GrainsArray[point.X - 1, point.Y].Id,
                range.GrainsArray[point.X + 1, point.Y].Id,
                range.GrainsArray[point.X, point.Y - 1].Id,
                range.GrainsArray[point.X, point.Y + 1].Id,
                range.GrainsArray[point.X - 1, point.Y - 1].Id,
                range.GrainsArray[point.X - 1, point.Y + 1].Id,
                range.GrainsArray[point.X + 1, point.Y - 1].Id,
                range.GrainsArray[point.X + 1, point.Y + 1].Id
            };

            foreach (var neighbourId in neighboursIds)
            {
                if (centerId != neighbourId && !SpecialId.IsIdSpecial(neighbourId))
                {
                    return(true);
                }
            }
            return(false);
        }
        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);
        }