locked
Valid Blend RRS feed

  • Question

  • User539648229 posted

    Hi

    I wrote a method to generate random Blend:

            private Blend GetRandomBlend()
            {
                Random rnd = new Random();
                int count = rnd.Next(11);
                Blend blend = new Blend();
    
                if (count > 0) 
                {
                    float[] f = new float[count];
                    float[] p = new float[count];
                    for (int i = 0; i < f.Length; i++)
                    {
                        f[i] = Convert.ToSingle(rnd.NextDouble());
                        p[i] = Convert.ToSingle(rnd.NextDouble());
                    }
    
                    blend.Factors = f.OrderBy(e => e).ToArray();
                    blend.Positions = p.OrderBy(e => e).ToArray();
                }
    
                return blend;
            }

    But when I assign this Blend to LinearGradientBrush there is an exeption that says: "Parameter is not valid". What is wrong with it? How can I find criteria like this? There is nothing in the documentation about these types of criteria for Blend and some other classes.

    Thanks

    Saturday, January 18, 2014 6:37 AM

Answers

  • User-760709272 posted
    // Make your positions and factors start with 0 and end with 1
    blend.Positions[0] = 0;
    blend.Positions[blend.Positions.Length - 1] = 1;
    blend.Factors[0] = 0;
    blend.Factors[blend.Factors.Length - 1] = 1;
    
    return blend;
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 18, 2014 12:06 PM

All replies

  • User-760709272 posted
    // Make your positions and factors start with 0 and end with 1
    blend.Positions[0] = 0;
    blend.Positions[blend.Positions.Length - 1] = 1;
    blend.Factors[0] = 0;
    blend.Factors[blend.Factors.Length - 1] = 1;
    
    return blend;
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 18, 2014 12:06 PM
  • User539648229 posted

    Hi

    Actually only Position needs these assignments.

    Thanks

    Monday, January 20, 2014 6:31 AM
  • User-760709272 posted

    That's what I thought, but I occasionally got errors still...they only stopped when Factors had proper stat/end points too.

    Monday, January 20, 2014 6:43 AM