public static GloColor operator *(double a, GloColor c)
        {
            int r = (int)Math.Round(a * c.r);
            int g = (int)Math.Round(a * c.g);
            int b = (int)Math.Round(a * c.b);

            return(GloColor.FromRGB(r, g, b));
        }
        private IEnumerable <TimeSpan> RunSequence(IEnumerable <GloCommand> seq)
        {
            foreach (GloCommand cmd in seq)
            {
                if (cmd is GloLoop)
                {
                    GloLoop loop = (GloLoop)cmd;
                    for (int i = 0; i < loop.Repetitions; i++)
                    {
                        foreach (var elem in RunSequence(loop.Commands))
                        {
                            yield return(elem);
                        }
                    }
                }

                else if (cmd is GloDelayCommand)
                {
                    yield return(((GloDelayCommand)cmd).Delay);
                }

                else if (cmd is GloRampCommand)
                {
                    GloRampCommand ramp     = (GloRampCommand)cmd;
                    GloColor       startCol = currentColor;


                    ColorAnimation animation = new ColorAnimation();
                    animation.To       = c2c(ramp.TargetColor);
                    animation.Duration = new Duration(ramp.Duration);
                    colorPanel.Background.BeginAnimation(SolidColorBrush.ColorProperty, animation);

                    currentColor = ramp.TargetColor;

                    /*double duration = ramp.Duration.TotalMilliseconds;
                     * for (double t = 0; t < duration; t += 10)
                     * {
                     *  CurrentColor = GloColor.Blend(startCol, ((GloRampCommand)cmd).TargetColor, t / duration);
                     *  yield return TimeSpan.FromMilliseconds(10);
                     * }*/
                    yield return(ramp.Duration);
                }

                else if (cmd is GloColorCommand)
                {
                    colorPanel.Background.SetCurrentValue(SolidColorBrush.ColorProperty, c2c(((GloColorCommand)cmd).Color));
                    //CurrentColor = ((GloColorCommand)cmd).Color;
                    yield return(TimeSpan.Zero);
                }

                else
                {
                    MessageBox.Show("Unknown command: " + cmd.GetType().Name);
                }
            }
        }
        private static GloColor GetColorArg(string[] tokens, int i)
        {
            GloColor col = new GloColor();

            col.r = GetIntArg(tokens, i + 0);
            col.g = GetIntArg(tokens, i + 1);
            col.b = GetIntArg(tokens, i + 2);

            return(col);
        }
        public static GloColor Blend(GloColor c1, GloColor c2, double pct)
        {
            if (pct <= 0)
            {
                return(c1);
            }
            if (pct >= 1)
            {
                return(c2);
            }

            return((1 - pct) * c1 + pct * c2);
        }
 public void Tick(TimeSpan progress)
 {
     //while (nextExecutionTime < DateTime.Now)
     while (cursor <= progress)
     {
         if (programQueue.MoveNext())
         {
             nextExecutionTime += programQueue.Current;
             cursor            += programQueue.Current;
         }
         else
         {
             Running      = false;
             currentColor = GloColor.FromRGB(0, 0, 0);
             break;
         }
     }
 }
 private Color c2c(GloColor _col)
 {
     return(Color.FromRgb((byte)_col.r, (byte)_col.g, (byte)_col.b));
 }
 public static GloColor operator+(GloColor c1, GloColor c2)
 {
     return(GloColor.FromRGB(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b));
 }
 public GloRampCommand(GloColor color, TimeSpan duration) : base("RAMP")
 {
     TargetColor = color;
     Duration    = duration;
 }
 public GloColorCommand(GloColor color) : base("C")
 {
     Color = color;
 }