コード例 #1
0
            public ColorHSV GetRandomColor(FlagColorCategory category, double?hue = null)
            {
                Random rand = StaticRandom.GetRandomForThread();

                double hueActual = hue ?? rand.NextDouble(360);

                ColorHSV retVal;

                if (category == FlagColorCategory.Other)
                {
                    // This category is under other category rectangles, so do a brute force repeat until match
                    FlagColorCategory cat;
                    do
                    {
                        retVal = new ColorHSV(hueActual, rand.NextDouble(100), rand.NextDouble(100));
                        cat    = Categorize(retVal);
                    } while (cat != category);
                }
                else
                {
                    // The color range is stored as a rectangle (X is saturation, Y is value)
                    Rect catRect = this.Categories.First(o => o.Item2 == category).Item1;
                    retVal = new ColorHSV(hueActual, rand.NextDouble(catRect.Left, catRect.Right), rand.NextDouble(catRect.Top, catRect.Bottom));
                }

                return(retVal);
            }
コード例 #2
0
            private Tuple <ColorHSV, FlagColorCategory> GetRandomFlagColors_Next(List <Tuple <ColorHSV, FlagColorCategory> > existing)
            {
                // Figure out which category group to use
                var group = GetRandomFlagColors_Group(existing);

                // Pick a category out of this group
                FlagColorCategory category = GetRandomFlagColors_Category(this.MaxPerFlag[group.Item1].Item1, group.Item2);

                // Get a color from this category
                ColorHSV color = GetRandomFlagColors_Color(category, existing);

                return(Tuple.Create(color, category));
            }
コード例 #3
0
            private ColorHSV GetRandomFlagColors_Color(FlagColorCategory category, List <Tuple <ColorHSV, FlagColorCategory> > existing)
            {
                if (_ignoreHues.Contains(category))
                {
                    return(GetRandomColor(category));        // don't worry about hue
                }

                double[] existingHues = existing.
                                        Where(o => !_ignoreHues.Contains(o.Item2)).
                                        Select(o => o.Item1.H).
                                        ToArray();


                //TODO: Use the existing hues to try to influence the next one:
                //      only allow 30 degree increments
                //      give a higher chance to the slots farthest away from existing


                double hue = GetRandomFlagColors_Hue(existingHues);

                return(GetRandomColor(category, hue));
            }
コード例 #4
0
ファイル: Flag.cs プロジェクト: charlierix/AsteroidMiner
            private ColorHSV GetRandomFlagColors_Color(FlagColorCategory category, List<Tuple<ColorHSV, FlagColorCategory>> existing)
            {
                if (_ignoreHues.Contains(category))
                {
                    return GetRandomColor(category);        // don't worry about hue
                }

                double[] existingHues = existing.
                    Where(o => !_ignoreHues.Contains(o.Item2)).
                    Select(o => o.Item1.H).
                    ToArray();


                //TODO: Use the existing hues to try to influence the next one:
                //      only allow 30 degree increments
                //      give a higher chance to the slots farthest away from existing


                double hue = GetRandomFlagColors_Hue(existingHues);

                return GetRandomColor(category, hue);
            }
コード例 #5
0
ファイル: Flag.cs プロジェクト: charlierix/AsteroidMiner
            private static FlagColorCategory GetRandomFlagColors_Category(FlagColorCategory[] chooseFrom, Tuple<ColorHSV, FlagColorCategory>[] existing)
            {
                if (chooseFrom.Length == 1)
                {
                    return chooseFrom[0];
                }

                Random rand = StaticRandom.GetRandomForThread();
                int infiniteLoopDetector = 0;

                // There are more than one to choose from.  Pick one that hasn't been picked before
                // For example { Black, White }, and White is used.  Need to return Black
                int index = -1;
                while (true)
                {
                    index = rand.Next(chooseFrom.Length);

                    if (!existing.Any(o => o.Item2 == chooseFrom[index]))
                    {
                        return chooseFrom[index];
                    }

                    infiniteLoopDetector++;
                    if (infiniteLoopDetector > 1000)
                    {
                        throw new ApplicationException("Infinite loop detected");
                    }
                }
            }
コード例 #6
0
ファイル: Flag.cs プロジェクト: charlierix/AsteroidMiner
            public ColorHSV GetRandomColor(FlagColorCategory category, double? hue = null)
            {
                Random rand = StaticRandom.GetRandomForThread();

                double hueActual = hue ?? rand.NextDouble(360);

                ColorHSV retVal;

                if (category == FlagColorCategory.Other)
                {
                    // This category is under other category rectangles, so do a brute force repeat until match
                    FlagColorCategory cat;
                    do
                    {
                        retVal = new ColorHSV(hueActual, rand.NextDouble(100), rand.NextDouble(100));
                        cat = Categorize(retVal);
                    } while (cat != category);
                }
                else
                {
                    // The color range is stored as a rectangle (X is saturation, Y is value)
                    Rect catRect = this.Categories.First(o => o.Item2 == category).Item1;
                    retVal = new ColorHSV(hueActual, rand.NextDouble(catRect.Left, catRect.Right), rand.NextDouble(catRect.Top, catRect.Bottom));
                }

                return retVal;
            }