コード例 #1
0
        public override IElement Evaluate(IElement[] Arguments, Variables Variables)
        {
            string ColorExpression = null;

            SKColor[]         Palette;
            double[]          Coefficients = null;
            Complex[]         CoefficientsZ = null;
            ILambdaExpression f = null;
            ScriptNode        fDef = null;
            double            rc, ic;
            double            dr;
            Complex           R;
            int     dimx, dimy;
            int     c = Arguments.Length;
            int     i = 0;
            object  Obj;
            Complex z;

            Obj = Arguments[i++].AssociatedObjectValue;
            if (Obj is Complex)
            {
                z  = (Complex)Obj;
                rc = z.Real;
                ic = z.Imaginary;
            }
            else
            {
                rc = Expression.ToDouble(Obj);
                ic = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }

            if (i >= c)
            {
                throw new ScriptRuntimeException("Insufficient parameters in call to NewtonSmoothFractal().", this);
            }

            dr = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);

            if (i < c && (Arguments[i] is DoubleNumber || Arguments[i] is ComplexNumber))
            {
                R = Expression.ToComplex(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                R = Complex.One;

                if (i < c && this.Arguments[i] is null)
                {
                    i++;
                }
            }

            if (i < c)
            {
                if (Arguments[i] is DoubleVector)
                {
                    Coefficients = (double[])Arguments[i++].AssociatedObjectValue;
                }
                else if (Arguments[i] is ComplexVector)
                {
                    CoefficientsZ = (Complex[])Arguments[i++].AssociatedObjectValue;
                }

                /*else if (Parameters[i] is RealPolynomial)
                 *      Coefficients = ((RealPolynomial)Arguments[i++].AssociatedObjectValue).Coefficients;
                 * else if (Parameters[i] is ComplexPolynomial)
                 *      CoefficientsZ = ((ComplexPolynomial)Arguments[i++].AssociatedObjectValue).Coefficients;*/
                else if (Arguments[i] is IVector)
                {
                    IVector Vector = (IVector)Arguments[i++];
                    int     j, d = Vector.Dimension;

                    CoefficientsZ = new Complex[d];
                    for (j = 0; j < d; j++)
                    {
                        CoefficientsZ[j] = Expression.ToComplex(Vector.GetElement(j).AssociatedObjectValue);
                    }
                }
                else if (Arguments[i].AssociatedObjectValue is ILambdaExpression)
                {
                    f = (ILambdaExpression)Arguments[i];
                    if (f.NrArguments != 1)
                    {
                        throw new ScriptRuntimeException("Lambda expression in calls to NewtonSmoothFractal() must be of one variable.", this);
                    }

                    fDef = this.Arguments[i++];
                }
                else
                {
                    throw new ScriptRuntimeException("Parameter " + (i + 1).ToString() +
                                                     " in call to NewtonSmoothFractal has to be a vector of numbers, containing coefficients " +
                                                     "of the polynomial to use. Now it was of type " + Arguments[i].GetType().FullName,
                                                     this);
                }
            }
            else
            {
                throw new ScriptRuntimeException("Missing coefficients or lambda expression.", this);
            }

            if (i < c && this.Arguments[i] != null && Arguments[i] is ObjectVector)
            {
                ColorExpression = this.Arguments[i].SubExpression;
                Palette         = FractalGraph.ToPalette((ObjectVector)Arguments[i++]);
            }
            else
            {
                Palette         = ColorModels.RandomLinearAnalogousHSL.CreatePalette(128, 4, out int Seed, this, Variables);
                ColorExpression = "RandomLinearAnalogousHSL(128,4," + Seed.ToString() + ")";

                if (i < c && this.Arguments[i] is null)
                {
                    i++;
                }
            }

            if (i < c)
            {
                dimx = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimx = 320;
            }

            if (i < c)
            {
                dimy = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimy = 200;
            }

            if (i < c)
            {
                throw new ScriptRuntimeException("Parameter mismatch in call to NewtonSmoothFractal(r,c,dr,Coefficients[,Palette][,dimx[,dimy]]).",
                                                 this);
            }

            if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
            {
                throw new ScriptRuntimeException("Image size must be within 1x1 to 5000x5000", this);
            }

            if (!(f is null))
            {
                return(CalcNewtonSmooth(rc, ic, dr, R, f, fDef, Variables, Palette, dimx, dimy,
                                        this, this.FractalZoomScript,
                                        new object[] { Palette, dimx, dimy, R, fDef, ColorExpression }));
            }
コード例 #2
0
        public override IElement Evaluate(IElement[] Arguments, Variables Variables)
        {
            string ColorExpression = null;

            SKColor[] Palette;
            object    Obj;
            double    rc, ic;
            double    dr;
            double    Rr, Ri, pr, pi;
            int       dimx, dimy;
            int       i, c;

            rc = Expression.ToDouble(Arguments[0].AssociatedObjectValue);
            ic = Expression.ToDouble(Arguments[1].AssociatedObjectValue);
            dr = Expression.ToDouble(Arguments[2].AssociatedObjectValue);

            if ((Obj = Arguments[3].AssociatedObjectValue) is Complex)
            {
                Complex z = (Complex)Obj;
                Rr = z.Real;
                Ri = z.Imaginary;
            }
            else
            {
                Rr = Expression.ToDouble(Arguments[3].AssociatedObjectValue);
                Ri = 0;
            }

            if ((Obj = Arguments[4].AssociatedObjectValue) is Complex)
            {
                Complex z = (Complex)Obj;
                pr = z.Real;
                pi = z.Imaginary;
            }
            else
            {
                pr = Expression.ToDouble(Arguments[4].AssociatedObjectValue);
                pi = 0;
            }

            c = Arguments.Length;
            i = 5;

            if (i < c && this.Arguments[i] != null && Arguments[i] is ObjectVector)
            {
                ColorExpression = this.Arguments[i].SubExpression;
                Palette         = FractalGraph.ToPalette((ObjectVector)Arguments[i++]);
            }
            else
            {
                Palette         = ColorModels.RandomLinearAnalogousHSL.CreatePalette(128, 4, out int Seed, this, Variables);
                ColorExpression = "RandomLinearAnalogousHSL(128,4," + Seed.ToString() + ")";

                if (i < c && this.Arguments[i] is null)
                {
                    i++;
                }
            }

            if (i < c)
            {
                dimx = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimx = 320;
            }

            if (i < c)
            {
                dimy = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimy = 200;
            }

            if (i < c)
            {
                throw new ScriptRuntimeException("Parameter mismatch in call to NovaFractal(r,c,dr,Coefficients[,Palette][,dimx[,dimy]]).",
                                                 this);
            }

            if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
            {
                throw new ScriptRuntimeException("Image size must be within 1x1 to 5000x5000", this);
            }

            return(CalcNova(rc, ic, dr, Rr, Ri, pr, pi, Palette, dimx, dimy,
                            this, this.FractalZoomScript,
                            new object[] { Palette, dimx, dimy, Rr, Ri, pr, pi, ColorExpression }));
        }
コード例 #3
0
        public override IElement Evaluate(IElement[] Arguments, Variables Variables)
        {
            string ColorExpression = null;

            SKColor[]         Palette;
            double            rc, ic;
            double            dr;
            int               dimx, dimy;
            int               i, c;
            object            Obj;
            Complex           z;
            ILambdaExpression f;
            ScriptNode        fDef = null;

            c = Arguments.Length;
            i = 0;

            Obj = Arguments[i++].AssociatedObjectValue;
            if (Obj is Complex)
            {
                z  = (Complex)Obj;
                rc = z.Real;
                ic = z.Imaginary;
            }
            else
            {
                rc = Expression.ToDouble(Obj);
                ic = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }

            if (i >= c)
            {
                throw new ScriptRuntimeException("Insufficient parameters in call to MandelbrotFractal().", this);
            }

            Obj = Arguments[i].AssociatedObjectValue;
            if (Obj is ILambdaExpression)
            {
                f    = (ILambdaExpression)Obj;
                fDef = this.Arguments[i++];

                if (f.NrArguments != 2)
                {
                    throw new ScriptRuntimeException("Lambda expression in calls to MandelbrotFractal() must be of two variables (z,c).", this);
                }
            }
            else
            {
                f    = null;
                fDef = null;

                if (Obj == null)
                {
                    i++;
                }
            }

            if (i >= c)
            {
                throw new ScriptRuntimeException("Insufficient parameters in call to MandelbrotFractal().", this);
            }

            dr = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);

            if (i < c && this.Arguments[i] != null && Arguments[i] is ObjectVector)
            {
                ColorExpression = this.Arguments[i].SubExpression;
                Palette         = FractalGraph.ToPalette((ObjectVector)Arguments[i++]);
            }
            else
            {
                Palette         = ColorModels.RandomLinearAnalogousHSL.CreatePalette(1024, 16, out int Seed, this, Variables);
                ColorExpression = "RandomLinearAnalogousHSL(1024,16," + Seed.ToString() + ")";

                if (i < c && this.Arguments[i] == null)
                {
                    i++;
                }
            }

            if (i < c)
            {
                dimx = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimx = 320;
            }

            if (i < c)
            {
                dimy = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimy = 200;
            }

            if (i < c)
            {
                throw new ScriptRuntimeException("Parameter mismatch in call to MandelbrotFractal(r,c,dr[,Palette][,dimx[,dimy]]).",
                                                 this);
            }

            if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
            {
                throw new ScriptRuntimeException("Image size must be within 1x1 to 5000x5000", this);
            }

            if (f != null)
            {
                return(CalcMandelbrot(rc, ic, dr, f, Variables, Palette, dimx, dimy, this, this.FractalZoomScript,
                                      new object[] { Palette, dimx, dimy, ColorExpression, fDef }));
            }
            else
            {
                return(CalcMandelbrot(rc, ic, dr, Palette, dimx, dimy, this, this.FractalZoomScript,
                                      new object[] { Palette, dimx, dimy, ColorExpression, fDef }));
            }
        }
コード例 #4
0
        public override IElement Evaluate(IElement[] Arguments, Variables Variables)
        {
            string ColorExpression = null;

            SKColor[] Palette;
            double[]  Coefficients = null;
            Complex[] CoefficientsZ = null;
            double    rc, ic;
            double    dr;
            Complex   R;
            int       dimx, dimy;
            int       c = Arguments.Length;
            int       i = 0;
            object    Obj;
            Complex   z;

            Obj = Arguments[i++].AssociatedObjectValue;
            if (Obj is Complex)
            {
                z  = (Complex)Obj;
                rc = z.Real;
                ic = z.Imaginary;
            }
            else
            {
                rc = Expression.ToDouble(Obj);
                ic = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }

            if (i >= c)
            {
                throw new ScriptRuntimeException("Insufficient parameters in call to HalleyBuilderFractal().", this);
            }

            dr = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);

            if (i < c && (Arguments[i] is DoubleNumber || Arguments[i] is ComplexNumber))
            {
                R = Expression.ToComplex(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                R = Complex.One;

                if (i < c && this.Arguments[i] is null)
                {
                    i++;
                }
            }

            if (i < c && Arguments[i] is DoubleVector)
            {
                Coefficients = (double[])Arguments[i++].AssociatedObjectValue;

                int j, d = Coefficients.Length;

                CoefficientsZ = new Complex[d];
                for (j = 0; j < d; j++)
                {
                    CoefficientsZ[j] = new Complex(Coefficients[j], 0);
                }
            }
            else if (i < c && Arguments[i] is ComplexVector)
            {
                CoefficientsZ = (Complex[])Arguments[i++].AssociatedObjectValue;
            }

            /*else if (i < c && Parameters[i] is RealPolynomial)
             *  Coefficients = ((RealPolynomial)Arguments[i++].AssociatedObjectValue).Coefficients;
             * else if (i < c && Parameters[i] is ComplexPolynomial)
             *  CoefficientsZ = ((ComplexPolynomial)Arguments[i++].AssociatedObjectValue).Coefficients;*/
            else if (i < c && Arguments[i] is IVector)
            {
                IVector Vector = (IVector)Arguments[i++];
                int     j, d = Vector.Dimension;

                CoefficientsZ = new Complex[d];
                for (j = 0; j < d; j++)
                {
                    CoefficientsZ[j] = Expression.ToComplex(Vector.GetElement(j).AssociatedObjectValue);
                }
            }
            else
            {
                CoefficientsZ = new Complex[0];
            }

            if (i < c && this.Arguments[i] != null && Arguments[i] is ObjectVector)
            {
                ColorExpression = this.Arguments[i].SubExpression;
                Palette         = FractalGraph.ToPalette((ObjectVector)Arguments[i++]);
            }
            else
            {
                Palette         = ColorModels.RandomLinearAnalogousHSL.CreatePalette(128, 4, out int Seed, this, Variables);
                ColorExpression = "RandomLinearAnalogousHSL(128,4," + Seed.ToString() + ")";

                if (i < c && this.Arguments[i] is null)
                {
                    i++;
                }
            }

            if (i < c)
            {
                dimx = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimx = 320;
            }

            if (i < c)
            {
                dimy = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimy = 200;
            }

            if (i < c)
            {
                throw new ScriptRuntimeException("Parameter mismatch in call to HalleyBuilderFractal(z,dr[,R][,Coefficients][,Palette][,dimx[,dimy]]).",
                                                 this);
            }

            if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
            {
                throw new ScriptRuntimeException("Image size must be within 1x1 to 5000x5000", this);
            }

            return(HalleyFractal.CalcHalley(rc, ic, dr, R, CoefficientsZ, Palette, dimx, dimy,
                                            this, this.FractalZoomScript,
                                            new object[] { Palette, dimx, dimy, R, CoefficientsZ, ColorExpression, rc, ic }));
        }