Example #1
0
 public List <QuantizedColor> GeneratePalette()
 {
     return(_palette ?? (_palette = (from vBox in _vboxes
                                     let rgb = vBox.Avg(false)
                                               let color = ColorExtensions.FromRgb(rgb[0], rgb[1], rgb[2])
                                                           select new QuantizedColor(color, vBox.Count(false))).ToList()));
 }
Example #2
0
            public VBox FindColor(double targetLuma, double minLuma, double maxLuma,
                                  double targetSaturation, double minSaturation, double maxSaturation)
            {
                VBox   max               = null;
                double maxValue          = 0;
                var    highestPopulation = _vboxes.Select(p => p.Count(false)).Max();

                foreach (var swatch in _vboxes)
                {
                    var avg  = swatch.Avg(false);
                    var hsl  = ColorExtensions.FromRgb(avg[0], avg[1], avg[2]).ToHsl();
                    var sat  = hsl.S;
                    var luma = hsl.L;

                    if (sat >= minSaturation && sat <= maxSaturation &&
                        luma >= minLuma && luma <= maxLuma)
                    {
                        var thisValue = CreateComparisonValue(sat, targetSaturation, luma, targetLuma,
                                                              swatch.Count(false), highestPopulation);
                        if (max == null || thisValue > maxValue)
                        {
                            max      = swatch;
                            maxValue = thisValue;
                        }
                    }
                }

                return(max);
            }
Example #3
0
        public CustomizableVisualizer()
        {
            try
            {
                var pluginDir  = Path.Combine(Directory.GetCurrentDirectory(), "plugins");
                var configFile = Path.Combine(pluginDir, "customvisual.cfg");
                if (!File.Exists(configFile))
                {
                    throw new FileNotFoundException();
                }
                var config = File.ReadAllLines(configFile);
                foreach (var line in config)
                {
                    var split = line.Split(' ');
                    var key   = split[0].ToLower();
                    var value = split[1].ToLower();
                    switch (key)
                    {
                    case "foreground":
                        if (value == "rainbow")
                        {
                            foreground = ChromaEffect.Shared.SharedColors.RainbowColor;
                        }
                        else
                        {
                            var rgb = value.Split(',').Select(x => x.Trim()).ToArray();
                            var r   = rgb[0];
                            var g   = rgb[1];
                            var b   = rgb[2];
                            foreground = (new AutoshiftCirculaQueue <Color>(Enumerable.Range(0, 64).Select(_ => ColorExtensions.FromRgb(byte.Parse(r), byte.Parse(g), byte.Parse(b))), 500)).AsReadOnly();
                        }
                        break;

                    case "background":
                        if (value == "rainbow")
                        {
                            background = Listener.Plugin.ChromaEffect.Shared.SharedColors.RainbowColor;
                        }
                        else
                        {
                            var rgb = value.Split(',').Select(x => x.Trim()).ToArray();
                            var r   = rgb[0];
                            var g   = rgb[1];
                            var b   = rgb[2];
                            background = (new AutoshiftCirculaQueue <Color>(Enumerable.Range(0, 64).Select(_ => ColorExtensions.FromRgb(byte.Parse(r), byte.Parse(g), byte.Parse(b))), 500)).AsReadOnly();
                        }
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }
            }
            catch (Exception)
            {
                foreground = (new AutoshiftCirculaQueue <Color>(Enumerable.Range(0, 64).Select(_ => Color.White), 500)).AsReadOnly();
                background = (new AutoshiftCirculaQueue <Color>(Enumerable.Range(0, 64).Select(_ => Color.Black), 500)).AsReadOnly();
            }
        }