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.
// 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;
I'm afraid I no longer use this forum due to the new point allocation system.
Member
130 Points
229 Posts
Valid Blend
Jan 18, 2014 06:37 AM|IranianCuriousBoy|LINK
Hi
I wrote a method to generate random 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
All-Star
37441 Points
9076 Posts
Re: Valid Blend
Jan 18, 2014 12:06 PM|AidyF|LINK
Member
130 Points
229 Posts
Re: Valid Blend
Jan 20, 2014 06:31 AM|IranianCuriousBoy|LINK
Hi
Actually only Position needs these assignments.
Thanks
All-Star
37441 Points
9076 Posts
Re: Valid Blend
Jan 20, 2014 06:43 AM|AidyF|LINK
That's what I thought, but I occasionally got errors still...they only stopped when Factors had proper stat/end points too.