Пример #1
0
        public override IElement Evaluate(IElement[] Arguments, Variables Variables)
        {
            long N;
            int  dimx, dimy;
            int  i, c;
            int  Seed;

            i = 0;
            c = Arguments.Length;
            N = (long)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            if (N <= 0)
            {
                throw new ScriptRuntimeException("N in calls to EstimateFlameSize() must be a positive integer.", this);
            }

            object Obj = Arguments[i].AssociatedObjectValue;
            string FunctionsExpression = this.Arguments[i++].SubExpression;

            if (!(Obj is Array FlameArray))
            {
                throw new ScriptRuntimeException("the second parameter to EstimateFlameSize must be an array, containing flame definitions.", this);
            }

            List <FlameFunction> FlameFunctions = new List <FlameFunction>();
            DoubleMatrix         M;
            double        Weight;
            FlameFunction CurrentFunction = null;

            foreach (object FlameItem in FlameArray)
            {
                if (FlameItem is DoubleMatrix)
                {
                    M = (DoubleMatrix)FlameItem;
                    CurrentFunction = new FlameFunction(M, this);
                    FlameFunctions.Add(CurrentFunction);
                }
                else if (FlameItem is SKColor || FlameItem is string)
                {
                    if (CurrentFunction is null)
                    {
                        M = new DoubleMatrix(new double[, ] {
                            { 1, 0 }, { 0, 1 }
                        });
                        CurrentFunction = new FlameFunction(M, this);
                        FlameFunctions.Add(CurrentFunction);
                    }

                    SKColor cl = Graph.ToColor(FlameItem);
                    cl.ToHsl(out float H, out float S, out float L);

                    CurrentFunction.SetColorHsl(H, S, L);
                }
                else if (FlameItem is IFlameVariation)
                {
                    if (CurrentFunction is null)
                    {
                        M = new DoubleMatrix(new double[, ] {
                            { 1, 0 }, { 0, 1 }
                        });
                        CurrentFunction = new FlameFunction(M, this);
                        FlameFunctions.Add(CurrentFunction);
                    }

                    CurrentFunction.Add((IFlameVariation)FlameItem);
                }
                else if (FlameItem is ILambdaExpression)
                {
                    if (CurrentFunction is null)
                    {
                        M = new DoubleMatrix(new double[, ] {
                            { 1, 0 }, { 0, 1 }
                        });
                        CurrentFunction = new FlameFunction(M, this);
                        FlameFunctions.Add(CurrentFunction);
                    }

                    CurrentFunction.Add((ILambdaExpression)FlameItem);
                }
                else
                {
                    try
                    {
                        Weight = Expression.ToDouble(FlameItem);

                        if (CurrentFunction is null)
                        {
                            M = new DoubleMatrix(new double[, ] {
                                { 1, 0 }, { 0, 1 }
                            });
                            CurrentFunction = new FlameFunction(M, this);
                            FlameFunctions.Add(CurrentFunction);
                        }

                        CurrentFunction.SetWeight(Weight);
                    }
                    catch (Exception)
                    {
                        throw new ScriptRuntimeException("Invalid flame variation definition.", this);
                    }
                }
            }

            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)
            {
                Seed = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                lock (gen)
                {
                    Seed = gen.Next();
                }

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

            if (i < c)
            {
                throw new ScriptRuntimeException("Parameter mismatch in call to EstimateFlameSize(N,FlameFunctions[dimx[,dimy[,Seed]]]).",
                                                 this);
            }

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

            FlameFunction[] Functions = FlameFunctions.ToArray();

            FlameFractalRgba.EstimateSize(out double xc, out double yc, out double dr, Functions, dimx, dimy, Seed, N, Variables, this);

            return(new DoubleVector(xc, yc, dr));
        }
Пример #2
0
        public override IElement Evaluate(IElement[] Arguments, Variables Variables)
        {
            double xc, yc;
            double dr;
            long   N;
            int    dimx, dimy;
            int    i, c;
            int    Seed;
            bool   Preview;
            bool   Parallel;

            i  = 0;
            c  = Arguments.Length;
            xc = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            yc = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            dr = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            N  = (long)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            if (N <= 0)
            {
                throw new ScriptRuntimeException("N in calls to FlameFractalHsl() must be a positive integer.", this);
            }

            object Obj = Arguments[i].AssociatedObjectValue;
            string FunctionsExpression = this.Arguments[i++].SubExpression;

            if (!(Obj is Array FlameArray))
            {
                throw new ScriptRuntimeException("the fifth parameter to FlameFractal must be an array, containing flame definitions.", this);
            }

            List <FlameFunction> FlameFunctions = new List <FlameFunction>();
            DoubleMatrix         M;
            double        Weight;
            double        Gamma;
            double        LightFactor;
            int           SuperSampling;
            FlameFunction CurrentFunction = null;

            foreach (object FlameItem in FlameArray)
            {
                if (FlameItem is DoubleMatrix)
                {
                    M = (DoubleMatrix)FlameItem;
                    CurrentFunction = new FlameFunction(M, this);
                    FlameFunctions.Add(CurrentFunction);
                }
                else if (FlameItem is SKColor || FlameItem is string)
                {
                    if (CurrentFunction == null)
                    {
                        M = new DoubleMatrix(new double[, ] {
                            { 1, 0 }, { 0, 1 }
                        });
                        CurrentFunction = new FlameFunction(M, this);
                        FlameFunctions.Add(CurrentFunction);
                    }

                    SKColor cl = Graph.ToColor(FlameItem);
                    cl.ToHsl(out float H, out float S, out float L);

                    CurrentFunction.SetColorHsl(H, S, L);
                }
                else if (FlameItem is IFlameVariation)
                {
                    if (CurrentFunction == null)
                    {
                        M = new DoubleMatrix(new double[, ] {
                            { 1, 0 }, { 0, 1 }
                        });
                        CurrentFunction = new FlameFunction(M, this);
                        FlameFunctions.Add(CurrentFunction);
                    }

                    CurrentFunction.Add((IFlameVariation)FlameItem);
                }
                else if (FlameItem is ILambdaExpression)
                {
                    if (CurrentFunction == null)
                    {
                        M = new DoubleMatrix(new double[, ] {
                            { 1, 0 }, { 0, 1 }
                        });
                        CurrentFunction = new FlameFunction(M, this);
                        FlameFunctions.Add(CurrentFunction);
                    }

                    CurrentFunction.Add((ILambdaExpression)FlameItem);
                }
                else
                {
                    try
                    {
                        Weight = Expression.ToDouble(FlameItem);

                        if (CurrentFunction == null)
                        {
                            M = new DoubleMatrix(new double[, ] {
                                { 1, 0 }, { 0, 1 }
                            });
                            CurrentFunction = new FlameFunction(M, this);
                            FlameFunctions.Add(CurrentFunction);
                        }

                        CurrentFunction.SetWeight(Weight);
                    }
                    catch (Exception)
                    {
                        throw new ScriptRuntimeException("Invalid flame variation definition.", this);
                    }
                }
            }

            if (i < c && Arguments[i] is BooleanValue)
            {
                Preview = (bool)Arguments[i++].AssociatedObjectValue;
            }
            else
            {
                Preview = false;
            }

            if (i < c && Arguments[i] is BooleanValue)
            {
                Parallel = (bool)Arguments[i++].AssociatedObjectValue;
            }
            else
            {
                Parallel = false;
            }

            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)
            {
                SuperSampling = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                SuperSampling = 2;
            }

            if (i < c)
            {
                Gamma = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                Gamma = 2.2;
            }

            if (i < c)
            {
                LightFactor = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                LightFactor = 1.0;
            }

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

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

            if (i < c)
            {
                throw new ScriptRuntimeException("Parameter mismatch in call to FlameFractalHsl(xc,yc,dr,N,FlameFunctions[,Preview[,Parallel[,dimx[,dimy[,SuperSampling[,Gamma[,LightFactor[,Seed]]]]]]]]).",
                                                 this);
            }

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

            FlameFunction[] Functions = FlameFunctions.ToArray();

            if (dr <= 0)
            {
                FlameFractalRgba.EstimateSize(out xc, out yc, out dr, Functions, dimx, dimy, Seed, 5000, Variables, this);

                Variables.ConsoleOut.WriteLine("X-center: " + Expression.ToString(xc), Variables);
                Variables.ConsoleOut.WriteLine("Y-center: " + Expression.ToString(yc), Variables);
                Variables.ConsoleOut.WriteLine("Width: " + Expression.ToString(dr), Variables);
            }

            return(CalcFlame(xc, yc, dr, N, Functions, dimx, dimy, Seed, SuperSampling, Gamma, LightFactor, Preview, Parallel, Variables, this,
                             this.FractalZoomScript, new object[] { dimx, dimy, N, FunctionsExpression, Seed, SuperSampling, Gamma, LightFactor, Preview, Parallel }));
        }