Exemplo n.º 1
0
        /// <summary>
        /// Evaluates the function.
        /// </summary>
        /// <param name="Arguments">Function arguments.</param>
        /// <param name="Variables">Variables collection.</param>
        /// <returns>Function result.</returns>
        public override IElement Evaluate(IElement[] Arguments, Variables Variables)
        {
            SKColor[] Colors;
            int       i = 0;
            int       c = Arguments.Length;
            int       N;
            int       BandSize;

            if (i < c)
            {
                object Obj = Arguments[i++].AssociatedObjectValue;

                Colors = Obj as SKColor[];
                if (Colors is null)
                {
                    Array a = Obj as Array;
                    if (a is null)
                    {
                        throw new ScriptRuntimeException("A fixed set of colors needs to be provided in calls to LinearColors().", this);
                    }

                    int d = a.GetLength(0);
                    int j;

                    Colors = new SKColor[d];
                    for (j = 0; j < d; j++)
                    {
                        Obj       = a.GetValue(j);
                        Colors[j] = Graph.ToColor(Obj);
                    }
                }
            }
            else
            {
                throw new ScriptRuntimeException("A fixed set of colors needs to be provided in calls to LinearColors().", this);
            }

            if (i < c)
            {
                N = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                N = 1024;
                Variables.ConsoleOut.WriteLine("N = " + N.ToString(), Variables);
            }

            if (i < c)
            {
                BandSize = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                BandSize = 16;
                Variables.ConsoleOut.WriteLine("BandSize = " + BandSize.ToString(), Variables);
            }

            return(new ObjectVector(CreatePalette(N, BandSize, Colors, this)));
        }
        /// <summary>
        /// Evaluates the function.
        /// </summary>
        /// <param name="Arguments">Function arguments.</param>
        /// <param name="Variables">Variables collection.</param>
        /// <returns>Function result.</returns>
        public override IElement Evaluate(IElement[] Arguments, Variables Variables)
        {
            int i = 0;
            int c = Arguments.Length;
            int N;
            int BandSize;
            int Seed;

            if (i < c)
            {
                N = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                N = 1024;
                Variables.ConsoleOut.WriteLine("N = " + N.ToString(), Variables);
            }

            if (i < c)
            {
                BandSize = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                BandSize = 16;
                Variables.ConsoleOut.WriteLine("BandSize = " + BandSize.ToString(), Variables);
            }

            if (i < c)
            {
                Seed = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                lock (gen)
                {
                    Seed = gen.Next();
                }

                Variables.ConsoleOut.WriteLine("Seed = " + Seed.ToString(), Variables);
            }

            return(new ObjectVector(CreatePalette(N, BandSize, Seed, this)));
        }