public static Color[] GetColorsForStrategy(ColorStrategy strategy, Color baseColor)
    {
        switch (strategy)
        {
        case ColorStrategy.Analagous:
        {
            return(GetAnalogousColors(baseColor, 0f, 0f));
        }

        case ColorStrategy.Complementary:
        {
            return(GetComplementaryColors(baseColor, 0f, 0f));
        }

        case ColorStrategy.Inverted:
        {
            return(new Color[] { FlipColor(baseColor) });
        }

        case ColorStrategy.Triad:
        {
            return(GetTriadColors(baseColor, 0f, 0f));
        }
        }

        return(new Color[] { baseColor });
    }
    public static bool CanFetchColorForStrategy(ColorStrategy c)
    {
        switch (c)
        {
        case ColorStrategy.Brightness:
        case ColorStrategy.Hue:
        case ColorStrategy.Saturation:
        {
            return(false);
        }
        }

        return(true);
    }
Exemplo n.º 3
0
        private static IColorStrategy SetColorStrategy(ColorStrategy colorStrategy)
        {
            switch (colorStrategy)
            {
            case ColorStrategy.RandomHue:
                return(new RandomHueStrategy());

            case ColorStrategy.RandomColor:
                return(new RandomColorStrategy());

            default:
                Console.Error("unknown color strategy");
                return(new RandomHueStrategy());
            }
        }
Exemplo n.º 4
0
        public FileContentResult TagCloud()
        {
            const int  Width        = 214;
            const int  Height       = 500;
            var        weightedTags = Tags.WeightedList();
            FontFamily font;

            using (var service = new FontsService())
            {
                service.LoadFonts(Request.MapPath(@"~\Content\Fonts"));
                font = service.AvailableFonts["Kenyan Coffee"];
            }

            var tagCloudService = new TagCloudService(weightedTags, Width, Height)
            {
                MaximumFontSize = 52f,
                MinimumFontSize = 18f,
                Margin          = 10,
                SelectedFont    = font,
                DisplayChoice   =
                    DisplayStrategy.Get(TagDisplayStrategy.MoreHorizontalThanVertical),
                ColorChoice =
                    ColorStrategy.Get(
                        Theme.LightBgDarkFg,
                        Style.RandomVaried,
                        Color.FromArgb(0, Color.White),
                        Color.Black),
                VerticalTextRight = true,
                Crop = true
            };

            Dictionary <string, RectangleF> borders;
            var bitmap = tagCloudService.Construct(out borders);

            if (tagCloudService.WordsSkipped.Any())
            {
                var msg = "Need a bigger Image - these words skipped : " +
                          string.Join("; ", tagCloudService.WordsSkipped.Select(x => x.Key));
                ErrorSignal.FromCurrentContext().Raise(new Exception(msg));
            }

            TempData["TagCloudBorders"] = borders;
            var stream = new MemoryStream();

            bitmap.Save(stream, ImageFormat.Png);
            return(File(stream.ToArray(), Constants.PngContentType));
        }
Exemplo n.º 5
0
        private static IColorStrategy SetColorStrategy(ColorStrategy colorStrategy)
        {
            Logger.Message($"Color Strategy: {colorStrategy}");
            switch (colorStrategy)
            {
            case ColorStrategy.RandomHue:
                return(new RandomHueStrategy());

            case ColorStrategy.RandomColor:
                return(new RandomColorStrategy());

            case ColorStrategy.CategorisedColor:
                return(new CategorisedColorStrategy());

            case ColorStrategy.NamedColors:
                return(new NamedColorStrategy());

            default:
                Logger.Error("unknown color strategy");
                return(new RandomHueStrategy());
            }
        }
Exemplo n.º 6
0
 public override void onTouchPlayer(Collider co)
 {
     Debug.Log("发生");
     Player        player   = co.gameObject.GetComponent <Player>();
     ColorStrategy strategy = new ColorStrategy(co.gameObject, 0.6f, player);
 }
 private IColorStrategy SetColorStrategy(ColorStrategy colorStrategy)
 {
     logger.Message("Color Strategy: " + colorStrategy.ToString());
     switch (colorStrategy)
     {
         case ColorStrategy.RandomHue:
             return new RandomHueStrategy();
         case ColorStrategy.RandomColor:
             return new RandomColorStrategy();
         case ColorStrategy.CategorisedColor:
             return new CategorisedColorStrategy();
         default:
             logger.Error("unknown color strategy");
             return new RandomHueStrategy();
     }
 }
        public ActionResult Cloud(TinkerModel Model)
        {
            Model.Strategies.AddRange(Enum.GetNames(typeof(TagDisplayStrategy)));
            Model.Themes.AddRange(Enum.GetNames(typeof(Theme)));
            Model.Styles.AddRange(Enum.GetNames(typeof(Style)));
            Dictionary <string, int> tags;

            try
            {
                tags = Model.Dictionary();
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                return(File("~/Content/Images/404.png", "image/png"));
            }
            var tagCloudService = new TagCloudService(tags, int.Parse(Model.Width), int.Parse(Model.Height))
            {
                MaximumFontSize = float.Parse(Model.MaxFontSize),
                MinimumFontSize = float.Parse(Model.MinFontSize),
            };

            if (!String.IsNullOrEmpty(Model.Angle))
            {
                tagCloudService.Angle = int.Parse(Model.Angle);
            }
            if (!String.IsNullOrEmpty(Model.Margin))
            {
                tagCloudService.Margin = int.Parse(Model.Margin);
            }

            using (var Service = new FontsService())
            {
                Service.LoadFonts(Request.MapPath("~/Content/Fonts"));
                Model.Fonts.AddRange(Service.AvailableFonts.Keys.ToArray());
                if (!String.IsNullOrEmpty(Model.SelectedFont))
                {
                    tagCloudService.SelectedFont = Service.AvailableFonts[Model.SelectedFont];
                }
            }

            if (!String.IsNullOrEmpty(Model.SelectedStrategy))
            {
                tagCloudService.DisplayChoice = DisplayStrategy.Get(Model.SelectedStrategy.Enumize <TagDisplayStrategy>());
            }

            var BgfgScheme = !String.IsNullOrEmpty(Model.SelectedTheme)
                                 ? Model.SelectedTheme.Enumize <Theme>()
                                 : Theme.LightBgDarkFg;
            var FgScheme = !String.IsNullOrEmpty(Model.SelectedStyle)
                               ? Model.SelectedStyle.Enumize <Style>()
                               : Style.Varied;

            tagCloudService.ColorChoice = ColorStrategy.Get(BgfgScheme, FgScheme,
                                                            Model.GetBackgroundColor(), Model.GetForegroundColor());

            tagCloudService.VerticalTextRight  = Model.VerticalTextRight;
            tagCloudService.ShowWordBoundaries = Model.ShowBoundaries;
            tagCloudService.Crop       = Model.Crop;
            tagCloudService.SpiralRoom = Model.SpiralRoom;

            var watch = new Stopwatch();

            watch.Start();
            Dictionary <string, RectangleF> Borders;
            var Bitmap = tagCloudService.Construct(out Borders);

            watch.Stop();

            TempData["TinkerBorders"] = Borders;
            TempData["GenerateTime"]  = watch.ElapsedMilliseconds / (float)1000;
            TempData["Skipped"]       = string.Join("; ", tagCloudService.WordsSkipped.Select(x => x.Key));

            var stream = new MemoryStream();

            Bitmap.Save(stream, ImageFormat.Png);
            return(File(stream.ToArray(), "image/png"));
        }