コード例 #1
0
        public IList<PatternStart> RandomizeColoring()
        {
            //original color
            Dictionary<PatternStart, IList<Color>> startToColor = new Dictionary<PatternStart, IList<Color>>();
            //keep track of the active patterns. Will contain new color
            List<PatternStart> active = new List<PatternStart>();

            foreach (var start in _patternStarts)
            {
                IList<Color> colors = EffectsToColors(start.SampleEffect.ColorEffects);
                startToColor[start] = colors;
                OrderedSet<Color> distinct = new OrderedSet<Color>();
                distinct.AddAll(colors);
                IDictionary<Color, Color> oldToNew = OldToNew(startToColor, active);
                Color randBase = distinct.FirstOrDefault(oldToNew.ContainsKey);
                IList<Color> newColors = randBase == default(Color)
                                            ? ColorPicker.PickColors(distinct.Count)
                                            : ColorPicker.PickColors(randBase, distinct.Count);
                IEnumerator<Color> newEnum = newColors.GetEnumerator();
                IEnumerator<Color> oldEnum = distinct.GetEnumerator();
                while(oldEnum.MoveNext())
                {
                    newEnum.MoveNext();
                    if (!oldToNew.ContainsKey(oldEnum.Current))
                    {
                        oldToNew[oldEnum.Current] = newEnum.Current;
                    }
                }
                start.ApplyColors(colors.Select(c=>oldToNew[c]).ToList());
                active.RemoveAll(s => s.EndTime <= start.StartTime);
                active.Add(start);
            }
            return _patternStarts;
        }