//transform sin into Math.sin, rand()=R.NextDouble()
 protected string getUserExpression(string s)
 {
     CodedomEvaluator.CodedomEvaluator cb = new CodedomEvaluator.CodedomEvaluator();
     s = cb.addMathMethods(s);
     //s = Regex.Replace(s, "\\brand\\(\\)\\b", "R.NextDouble()");
     s = Regex.Replace(s, "\\brand\\b", "R.NextDouble");
     s = Regex.Replace(s, "\\brandneg\\(\\)", "((R.NextDouble()-0.5)*2)");
     return s;
 }
Example #2
0
 //transform sin into Math.sin, rand()=R.NextDouble()
 protected string getUserExpression(string s)
 {
     CodedomEvaluator.CodedomEvaluator cb = new CodedomEvaluator.CodedomEvaluator();
     s = cb.addMathMethods(s);
     //s = Regex.Replace(s, "\\brand\\(\\)\\b", "R.NextDouble()");
     s = Regex.Replace(s, "\\brand\\b", "R.NextDouble");
     s = Regex.Replace(s, "\\brandneg\\(\\)", "((R.NextDouble()-0.5)*2)");
     return(s);
 }
Example #3
0
 //transform sin into Math.sin, rand()=R.NextDouble()
 protected string getUserExpression(string s)
 {
     CodedomEvaluator.CodedomEvaluator cb = new CodedomEvaluator.CodedomEvaluator();
     s = cb.addMathMethods(s);
     //s = Regex.Replace(s, "\\brand\\(\\)\\b", "R.NextDouble()");
     s = Regex.Replace(s, "\\brand\\b", "R.NextDouble");
     s = Regex.Replace(s, "\\brandneg\\(\\)", "((R.NextDouble()-0.5)*2)");
     s = Regex.Replace(s, "\\balert\\b", "System.Windows.Forms.MessageBox.Show");
     s = Regex.Replace(s, "\\bclipboardset\\b", "System.Windows.Forms.Clipboard.SetText");
     return s;
 }
 //transform sin into Math.sin, rand()=R.NextDouble()
 protected string getUserExpression(string s)
 {
     CodedomEvaluator.CodedomEvaluator cb = new CodedomEvaluator.CodedomEvaluator();
     s = cb.addMathMethods(s);
     //s = Regex.Replace(s, "\\brand\\(\\)\\b", "R.NextDouble()");
     s = Regex.Replace(s, "\\brand\\b", "R.NextDouble");
     s = Regex.Replace(s, "\\brandneg\\(\\)", "((R.NextDouble()-0.5)*2)");
     s = Regex.Replace(s, "\\balert\\b", "System.Windows.Forms.MessageBox.Show");
     s = Regex.Replace(s, "\\bclipboardset\\b", "System.Windows.Forms.Clipboard.SetText");
     return(s);
 }
Example #5
0
        public override void getPlotPoints(int width, int height, ref double[] data1, ref double[] data2)
        {
            /*
             * Create this code:
             * double x = X0, xinc=(X1-X0)/width;
             * for (int i=0; i<width; i++)
             * {
             *  dbPlotData1[i] = x;
             *  dbPlotData2[i] = x;
             *  x+=xinc;
             * }*/

            StringBuilder sbCode = new StringBuilder();

            sbCode.AppendLine("double y;");
            sbCode.AppendLine("double x = X0, xinc=(X1-X0)/width;");
            sbCode.AppendLine(strInit);
            sbCode.AppendLine("for (int i=0; i<width; i++) {");
            sbCode.AppendLine("$$code$$");
            sbCode.AppendLine("arrAns[i] = y;");
            sbCode.AppendLine("x+=xinc;");
            sbCode.AppendLine("}");

            Dictionary <string, double> d = new Dictionary <string, double>();

            d["X0"]    = X0; d["X1"] = X1; d["Y0"] = Y0; d["Y1"] = Y1;
            d["width"] = width; d["height"] = height;

            string strErr = "";

            CodedomEvaluator.CodedomEvaluator cde = new CodedomEvaluator.CodedomEvaluator();
            double[] out1 = cde.mathEvalArray(sbCode.ToString().Replace("$$code$$", strExp1), d, width, out strErr);
            if (strErr != "")
            {
                System.Windows.Forms.MessageBox.Show(strErr); return;
            }

            //because of ref counting, apparently ok to just set reference like this.
            //for (int i=0; i<out1.Length; i++)
            //    this.dbPlotData1[i] = out1[i];
            System.Diagnostics.Debug.Assert(this.dbPlotData1.Length == out1.Length);
            this.dbPlotData1 = out1;

            if (bDrawSecond)
            {
                cde = new CodedomEvaluator.CodedomEvaluator();
                double[] out2 = cde.mathEvalArray(sbCode.ToString().Replace("$$code$$", strExp2), d, width, out strErr);
                if (strErr != "")
                {
                    System.Windows.Forms.MessageBox.Show(strErr); return;
                }
                this.dbPlotData2 = out2;
            }
        }
        public override void getPlotPoints(int width, int height, ref double[] data1, ref double[] data2)
        {
            /*
             * Create this code:
            double x = X0, xinc=(X1-X0)/width;
            for (int i=0; i<width; i++)
            {
                dbPlotData1[i] = x;
                dbPlotData2[i] = x;
                x+=xinc;
            }*/

            StringBuilder sbCode = new StringBuilder();
            sbCode.AppendLine("double y;");
            sbCode.AppendLine("double x = X0, xinc=(X1-X0)/width;");
            sbCode.AppendLine(strInit);
            sbCode.AppendLine("for (int i=0; i<width; i++) {");
            sbCode.AppendLine("$$code$$");
            sbCode.AppendLine("arrAns[i] = y;");
            sbCode.AppendLine("x+=xinc;");
            sbCode.AppendLine("}");

            Dictionary<string, double> d = new Dictionary<string, double>();
            d["X0"] = X0; d["X1"] = X1; d["Y0"] = Y0; d["Y1"] = Y1;
            d["width"] = width; d["height"] = height;

            string strErr = "";
            CodedomEvaluator.CodedomEvaluator cde = new CodedomEvaluator.CodedomEvaluator();
            double[] out1 = cde.mathEvalArray(sbCode.ToString().Replace("$$code$$", strExp1), d, width, out strErr);
            if (strErr != "")
                { System.Windows.Forms.MessageBox.Show(strErr); return; }

            //because of ref counting, apparently ok to just set reference like this.
            //for (int i=0; i<out1.Length; i++)
            //    this.dbPlotData1[i] = out1[i];
            System.Diagnostics.Debug.Assert(this.dbPlotData1.Length == out1.Length);
            this.dbPlotData1 = out1;

            if (bDrawSecond)
            {
                cde = new CodedomEvaluator.CodedomEvaluator();
                double[] out2 = cde.mathEvalArray(sbCode.ToString().Replace("$$code$$", strExp2), d, width, out strErr);
                if (strErr != "")
                { System.Windows.Forms.MessageBox.Show(strErr); return; }
                this.dbPlotData2 = out2;
            }
        }
        public override void getData(int width, int height, ref double[] elems)
        {
            if (paramP0.Trim() == "")
            {
                paramP0 = "0.5";
            }
            //Pass in: X0,X1,Y0,Y1,WIDTH,HEIGHT,paramShading,paramSettle
            Dictionary <string, double> d = new Dictionary <string, double>();

            d["X0"]                   = X0; d["X1"] = X1; d["Y0"] = Y0; d["Y1"] = Y1;
            d["fWIDTH"]               = width; d["fHEIGHT"] = height;
            d["paramShading"]         = paramShading; d["paramSettle"] = paramSettle;
            d["c1"]                   = param1; d["c2"] = param2; d["c3"] = param3; d["c4"] = param4;
            d["paramAdditionalIters"] = paramAdditionalIters; //can't be set by code or cfg, use additionalShading

            string sTemplate       = @"
            double additionalShading=1.0; //can be set by code
            double shadingAmount = paramShading*0.2 + 0.8;
            int nPointsDrawn = (int)(paramShading * 40)+1;
            int nSettletime = (int)paramSettle;
            int width=(int)fWIDTH, height=(int)fHEIGHT;
            for (int i = 0; i < arrAns.Length; i++) arrAns[i] = 1.0; //set all white

            Random R = new Random();
            double _dx = (X1 - X0) / width;
            double fx = X0;
            int _y;
            double p;
            $$INITCODE$$
            int nIterations = (int) (paramAdditionalIters*additionalShading*10000);
            for (int _x = 0; _x < width; _x++)
            {
                double r = fx;
                p = $$PNAUGHTEXPRESSION$$;
                for (int _i = 0; _i < nSettletime; _i++)
                {
                   $$CODE$$
                }

                for (int _i = 0; _i < $$NITERS$$; _i++)
                {
                    $$CODE$$

                    _y = (int)(height - height * ((p - Y0) / (Y1 - Y0)));
                    if (_y >= 0 && _y < height)
                        arrAns[_y + _x * height] $$SHADEOPERATION$$
                }
                fx += _dx;
            }";
            string sItersPer       = (bShading)?"nIterations" : "nPointsDrawn";
            string sShadeOperation = (bShading)?"*= shadingAmount;" : "= 0.2;";

            //string sShadeOperation = (bShading)?"-= shadingAmount;" : "= 0.2;";
            //string sShadeOperation = (bShading)?"= (arrAns[y + x * HEIGHT]>shadingAmount)?(arrAns[y + x * HEIGHT]-shadingAmount):shadingAmount;" : "= 0.2;";

            sTemplate = sTemplate.Replace("$$NITERS$$", sItersPer);
            sTemplate = sTemplate.Replace("$$CODE$$", paramExpression);
            sTemplate = sTemplate.Replace("$$INITCODE$$", paramInit);
            sTemplate = sTemplate.Replace("$$PNAUGHTEXPRESSION$$", paramP0);
            sTemplate = sTemplate.Replace("$$SHADEOPERATION$$", sShadeOperation);

            //System.Windows.Forms.Clipboard.SetText(sTemplate);
            string strErr = "";

            CodedomEvaluator.CodedomEvaluator cde = new CodedomEvaluator.CodedomEvaluator();
            double[] out1 = cde.mathEvalArray(sTemplate, d, width * height, out strErr);
            if (strErr != "")
            {
                System.Windows.Forms.MessageBox.Show(strErr); return;
            }
            //because of ref counting, apparently ok to set reference like this instead of copying elements.

            System.Diagnostics.Debug.Assert(out1.Length == width * height);
            elems = out1;


            /*if (!bShading) //redistribute ink?
             * {
             *  double totalInkGoal = WIDTH * HEIGHT * 0.05;
             *  double total = 0.0;
             *  foreach (double dd in this.dbData) total+=(1-dd);
             *  //System.Windows.Forms.MessageBox.Show("" + total);
             *  double scale = totalInkGoal / total ;
             *  System.Windows.Forms.MessageBox.Show(": " + total + "   "+totalInkGoal + "   "+scale);
             *  for (int i =0; i<this.dbData.Length; i++) this.dbData[i] = (1-(1-this.dbData[i]) * scale);
             * }*/
        }
Example #8
0
        public override void getData(int width, int height, ref double[] elems) //template
        {
            //getDataTemplate(width, height, ref elems);
            // return;
            Dictionary <string, double> d = new Dictionary <string, double>();

            d["X0"]                   = X0; d["X1"] = X1; d["Y0"] = Y0; d["Y1"] = Y1;
            d["fWIDTH"]               = width; d["fHEIGHT"] = height;
            d["paramSettle"]          = paramSettle;
            d["paramTotalIters"]      = paramTotalIters;
            d["paramAdditionalIters"] = paramAdditionalIters;
            d["c1"]                   = param1; d["c2"] = param2; d["c3"] = param3; d["c4"] = param4;


            string sTemplate = @"
            double RED = double.NegativeInfinity;
            double BLUE = double.MinValue;
            int width=(int)fWIDTH, height=(int)fHEIGHT;
            double x, y, x_, y_;
            for (int i = 0; i < arrAns.Length; i++) 
                arrAns[i] = 1.0; //set all white
            Random R = new Random();

            //can be changed in init:
            int nXpoints = 80, nYpoints = 80;
            double sx0= -2, sx1=2, sy0= -2, sy1=2;
            double additionalDarkening = 1.0;
            int nPeriod=0; double dCloseness=0.01; //draw fixed pts
            bool bOnlyStable = false;

            $$INITCODE$$

            // iters represents total iters. we divide by how many points. 
            // In this way, if nXpoints changed, density remains roughly constant.
            int nItersPerPoint = (int)Math.Round(((paramTotalIters*1000.0*paramAdditionalIters) / ((double)nXpoints * nYpoints)));
            double sxinc = (nXpoints==1) ? double.MaxValue : (sx1-sx0)/(nXpoints-1);
            double syinc = (nYpoints==1) ? double.MaxValue : (sy1-sy0)/(nYpoints-1);

            System.Diagnostics.Debug.Assert(sx1>sx0 && sy1>sy0 && sxinc>0 && syinc>0 && nXpoints>0 && nYpoints>0);
            double shadeAmount = 0.9 * additionalDarkening;
            for (double sx=sx0; sx<=sx1; sx+=sxinc)
            {
                for (double sy=sy0; sy<=sy1; sy+=syinc)
                {
                    x = sx; y=sy;

                    for (int ii=0; ii<paramSettle; ii++)
                    {
                        $$CODE$$
                        x=x_; 
                        y=y_;
                    }
                    for (int ii=0; ii<nItersPerPoint; ii++)
                    {
                        $$CODE$$
                        x=x_;
                        y=y_;

                        int px = (int)(width * ((x - X0) / (X1 - X0)));
                        int py = (int)(height - height * ((y - Y0) / (Y1 - Y0)));
                        if (py >= 0 && py < height && px>=0 && px<width)
                            arrAns[py + px * height] *= shadeAmount;
                    }
                }
            }

            if (nPeriod!=0)
            {
                double dx = (X1 - X0) / width, dy = (Y1 - Y0) / height;
                double fx = X0, fy = Y1; //y counts downwards
                for (int px = 0; px < width; px+=1)
                {
                    fy = Y1;
                    for (int py=0; py<height; py+=1)
                    {
                        x = fx; y=fy;

                        for (int ii=0; ii<nPeriod; ii++)
                        {
                            $$CODE$$
                            x=x_;
                            y=y_;
                        }

                        if ((x-fx)*(x-fx)+(y-fy)*(y-fy)<dCloseness)
                        {
                            if (!bOnlyStable)
                                arrAns[py+px*height] = RED;
                            else
                            {
                                //test stability
                                x = fx+(R.NextDouble()-0.5)/1000; y=fy+(R.NextDouble()-0.5)/1000;
                                for (int ii=0; ii<nPeriod*800; ii++)
                                {
                                    $$CODE$$
                                    x=x_;
                                    y=y_;
                                }
                                if ((x-fx)*(x-fx)+(y-fy)*(y-fy)<dCloseness)
                                    arrAns[py+px*height] = RED;
                            }
                        }

                        fy -= dy;
                    }
                    fx += dx;
                }
            }

";

            sTemplate = sTemplate.Replace("$$CODE$$", paramExpression);
            sTemplate = sTemplate.Replace("$$INITCODE$$", paramInit);
            //System.Windows.Forms.Clipboard.SetText(sTemplate);///
            string strErr = "";

            CodedomEvaluator.CodedomEvaluator cde = new CodedomEvaluator.CodedomEvaluator();
            double[] out1 = cde.mathEvalArray(sTemplate, d, width * height, out strErr);
            if (strErr != "")
            {
                System.Windows.Forms.MessageBox.Show(strErr); return;
            }

            //because of ref counting, apparently ok to set reference like this instead of copying elements.
            elems = out1;
            System.Diagnostics.Debug.Assert(out1.Length == width * height);
        }
        public override void getData(int width, int height, ref double[] elems)
        {
            if (paramP0.Trim()=="") paramP0 = "0.5";
            //Pass in: X0,X1,Y0,Y1,WIDTH,HEIGHT,paramShading,paramSettle
            Dictionary<string, double> d = new Dictionary<string, double>();
            d["X0"] = X0; d["X1"] = X1; d["Y0"] = Y0; d["Y1"] = Y1;
            d["fWIDTH"] = width; d["fHEIGHT"] = height;
            d["paramShading"] = paramShading; d["paramSettle"] = paramSettle;
            d["c1"] = param1; d["c2"] = param2; d["c3"] = param3; d["c4"] = param4;
            d["paramAdditionalIters"] = paramAdditionalIters; //can't be set by code or cfg, use additionalShading

            string sTemplate = @"
            double additionalShading=1.0; //can be set by code
            double shadingAmount = paramShading*0.2 + 0.8;
            int nPointsDrawn = (int)(paramShading * 40)+1;
            int nSettletime = (int)paramSettle;
            int width=(int)fWIDTH, height=(int)fHEIGHT;
            for (int i = 0; i < arrAns.Length; i++) arrAns[i] = 1.0; //set all white

            Random R = new Random();
            double _dx = (X1 - X0) / width;
            double fx = X0;
            int _y;
            double p;
            $$INITCODE$$
            int nIterations = (int) (paramAdditionalIters*additionalShading*10000);
            for (int _x = 0; _x < width; _x++)
            {
                double r = fx;
                p = $$PNAUGHTEXPRESSION$$;
                for (int _i = 0; _i < nSettletime; _i++)
                {
                   $$CODE$$
                }

                for (int _i = 0; _i < $$NITERS$$; _i++)
                {
                    $$CODE$$

                    _y = (int)(height - height * ((p - Y0) / (Y1 - Y0)));
                    if (_y >= 0 && _y < height)
                        arrAns[_y + _x * height] $$SHADEOPERATION$$
                }
                fx += _dx;
            }";
            string sItersPer = (bShading)?"nIterations" : "nPointsDrawn";
            string sShadeOperation = (bShading)?"*= shadingAmount;" : "= 0.2;";
            //string sShadeOperation = (bShading)?"-= shadingAmount;" : "= 0.2;";
            //string sShadeOperation = (bShading)?"= (arrAns[y + x * HEIGHT]>shadingAmount)?(arrAns[y + x * HEIGHT]-shadingAmount):shadingAmount;" : "= 0.2;";

            sTemplate = sTemplate.Replace("$$NITERS$$", sItersPer);
            sTemplate = sTemplate.Replace("$$CODE$$", paramExpression);
            sTemplate = sTemplate.Replace("$$INITCODE$$", paramInit);
            sTemplate = sTemplate.Replace("$$PNAUGHTEXPRESSION$$", paramP0);
            sTemplate = sTemplate.Replace("$$SHADEOPERATION$$", sShadeOperation);

            //System.Windows.Forms.Clipboard.SetText(sTemplate);
            string strErr = "";
            CodedomEvaluator.CodedomEvaluator cde = new CodedomEvaluator.CodedomEvaluator();
            double[] out1 = cde.mathEvalArray(sTemplate, d, width*height, out strErr);
            if (strErr != "")
            { System.Windows.Forms.MessageBox.Show(strErr); return; }
            //because of ref counting, apparently ok to set reference like this instead of copying elements.

            System.Diagnostics.Debug.Assert(out1.Length == width*height);
            elems = out1;
            

            /*if (!bShading) //redistribute ink? 
            {
                double totalInkGoal = WIDTH * HEIGHT * 0.05;
                double total = 0.0;
                foreach (double dd in this.dbData) total+=(1-dd);
                //System.Windows.Forms.MessageBox.Show("" + total);
                double scale = totalInkGoal / total ;
                System.Windows.Forms.MessageBox.Show(": " + total + "   "+totalInkGoal + "   "+scale);
                for (int i =0; i<this.dbData.Length; i++) this.dbData[i] = (1-(1-this.dbData[i]) * scale);
            }*/

        }
        public override void getData(int width, int height, ref double[] elems) //template
        {
            //getDataTemplate(width, height, ref elems);
           // return;
            Dictionary<string, double> d = new Dictionary<string, double>();
            d["X0"] = X0; d["X1"] = X1; d["Y0"] = Y0; d["Y1"] = Y1;
            d["fWIDTH"] = width; d["fHEIGHT"] = height;
            d["paramSettle"] = paramSettle;
            d["paramTotalIters"] = paramTotalIters;
            d["paramAdditionalIters"] = paramAdditionalIters;
            d["c1"] = param1; d["c2"] = param2; d["c3"] = param3; d["c4"] = param4;

            
            string sTemplate = @"
            double RED = double.NegativeInfinity;
            double BLUE = double.MinValue;
            int width=(int)fWIDTH, height=(int)fHEIGHT;
            double x, y, x_, y_;
            for (int i = 0; i < arrAns.Length; i++) 
                arrAns[i] = 1.0; //set all white
            Random R = new Random();

            //can be changed in init:
            int nXpoints = 80, nYpoints = 80;
            double sx0= -2, sx1=2, sy0= -2, sy1=2;
            double additionalDarkening = 1.0;
            int nPeriod=0; double dCloseness=0.01; //draw fixed pts
            bool bOnlyStable = false;

            $$INITCODE$$

            // iters represents total iters. we divide by how many points. 
            // In this way, if nXpoints changed, density remains roughly constant.
            int nItersPerPoint = (int)Math.Round(((paramTotalIters*1000.0*paramAdditionalIters) / ((double)nXpoints * nYpoints)));
            double sxinc = (nXpoints==1) ? double.MaxValue : (sx1-sx0)/(nXpoints-1);
            double syinc = (nYpoints==1) ? double.MaxValue : (sy1-sy0)/(nYpoints-1);

            System.Diagnostics.Debug.Assert(sx1>sx0 && sy1>sy0 && sxinc>0 && syinc>0 && nXpoints>0 && nYpoints>0);
            double shadeAmount = 0.9 * additionalDarkening;
            for (double sx=sx0; sx<=sx1; sx+=sxinc)
            {
                for (double sy=sy0; sy<=sy1; sy+=syinc)
                {
                    x = sx; y=sy;

                    for (int ii=0; ii<paramSettle; ii++)
                    {
                        $$CODE$$
                        x=x_; 
                        y=y_;
                    }
                    for (int ii=0; ii<nItersPerPoint; ii++)
                    {
                        $$CODE$$
                        x=x_;
                        y=y_;

                        int px = (int)(width * ((x - X0) / (X1 - X0)));
                        int py = (int)(height - height * ((y - Y0) / (Y1 - Y0)));
                        if (py >= 0 && py < height && px>=0 && px<width)
                            arrAns[py + px * height] *= shadeAmount;
                    }
                }
            }

            if (nPeriod!=0)
            {
                double dx = (X1 - X0) / width, dy = (Y1 - Y0) / height;
                double fx = X0, fy = Y1; //y counts downwards
                for (int px = 0; px < width; px+=1)
                {
                    fy = Y1;
                    for (int py=0; py<height; py+=1)
                    {
                        x = fx; y=fy;

                        for (int ii=0; ii<nPeriod; ii++)
                        {
                            $$CODE$$
                            x=x_;
                            y=y_;
                        }

                        if ((x-fx)*(x-fx)+(y-fy)*(y-fy)<dCloseness)
                        {
                            if (!bOnlyStable)
                                arrAns[py+px*height] = RED;
                            else
                            {
                                //test stability
                                x = fx+(R.NextDouble()-0.5)/1000; y=fy+(R.NextDouble()-0.5)/1000;
                                for (int ii=0; ii<nPeriod*800; ii++)
                                {
                                    $$CODE$$
                                    x=x_;
                                    y=y_;
                                }
                                if ((x-fx)*(x-fx)+(y-fy)*(y-fy)<dCloseness)
                                    arrAns[py+px*height] = RED;
                            }
                        }

                        fy -= dy;
                    }
                    fx += dx;
                }
            }

";
            sTemplate = sTemplate.Replace("$$CODE$$", paramExpression);
            sTemplate = sTemplate.Replace("$$INITCODE$$", paramInit);
            //System.Windows.Forms.Clipboard.SetText(sTemplate);///
            string strErr = "";
            CodedomEvaluator.CodedomEvaluator cde = new CodedomEvaluator.CodedomEvaluator();
            double[] out1 = cde.mathEvalArray(sTemplate, d, width*height, out strErr);
            if (strErr != "")
            { System.Windows.Forms.MessageBox.Show(strErr); return; }

            //because of ref counting, apparently ok to set reference like this instead of copying elements.
            elems = out1;
            System.Diagnostics.Debug.Assert(out1.Length == width*height);
        }