Example #1
0
        private void btnEvaluate3_Click(object sender, EventArgs e)
        {
            try
            {
                // throw new NotImplementedException();
                // if (FormulaHandler != null) mFormula3.ValueChanged -= FormulaHandler;
                //if (formula3subscription != null) formula3subscription.Dispose();
                using (mFormula3 = ev.Parse(tbExpression3.Text))
                {
                    string v = ev.ConvertToString(mFormula3.ObjectValue);
                    lblResults3.Text = v;
                    LogBox3.AppendText(System.DateTime.Now.ToLongTimeString() + ": " + v + "\r\n");
                }

                //FormulaHandler = new Eval4.Core.ValueChangedEventHandler(mFormula3_ValueChanged);
                // mFormula3.ValueChanged += FormulaHandler;
                // mFormula3_ValueChanged(null, null);
            }
            catch (Exception ex)
            {
                lblResults3.Text = ex.Message;
            }
        }
Example #2
0
        private void btnEvaluate3_Click(object sender, EventArgs e)
        {
            try
            {
                // throw new NotImplementedException();
                // if (FormulaHandler != null) mFormula3.ValueChanged -= FormulaHandler;
                //if (formula3subscription != null) formula3subscription.Dispose();
                using (mFormula3 = ev.Parse(tbExpression3.Text))
                {
                    string v = ev.ConvertToString(mFormula3.ObjectValue);
                    lblResults3.Text = v;
                    LogBox3.AppendText(System.DateTime.Now.ToLongTimeString() + ": " + v + "\r\n");
                }


                //FormulaHandler = new Eval4.Core.ValueChangedEventHandler(mFormula3_ValueChanged);
                // mFormula3.ValueChanged += FormulaHandler;
                // mFormula3_ValueChanged(null, null);
            }
            catch (Exception ex)
            {
                lblResults3.Text = ex.Message;
            }
        }
Example #3
0
        private void btnEvaluate2_Click(object sender, EventArgs e)
        {
            Eval4.Core.IParsedExpr lCodeR = null;
            Eval4.Core.IParsedExpr lCodeG = null;
            Eval4.Core.IParsedExpr lCodeB = null;
            ev.AddEnvironmentFunctions(typeof(Math));
            ev.AddEnvironmentFunctions(new EvalFunctions());
            var        vX      = ev.SetVariable("X", 0.0);
            var        vY      = ev.SetVariable("Y", 0.0);
            var        vZ      = ev.SetVariable("Z", ((double)trackBar1.Value) / trackBar1.Maximum);
            BitmapData bmpData = null;

            try
            {
                lCodeR = ev.Parse(tbExpressionRed.Text);
                errorProvider1.SetError(tbExpressionRed, lCodeR.Error);
                lCodeG = ev.Parse(tbExpressionGreen.Text);
                errorProvider1.SetError(tbExpressionGreen, lCodeG.Error);
                lCodeB = ev.Parse(tbExpressionBlue.Text);
                errorProvider1.SetError(tbExpressionBlue, lCodeB.Error);

                PictureBox1.Image = null;
                //PictureBox1.Refresh();
                //Bitmap bm = (Bitmap)PictureBox1.Image;
                if ((bm == null))
                {
                    bm = new Bitmap(256, 256, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    PictureBox1.Image = bm;
                }
                double mult = (2
                               * (System.Math.PI / 256));
                //double r = 0;
                //double g = 0;
                //double b = 0;
                bmpData = bm.LockBits(new Rectangle(0, 0, 256, 256), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                IntPtr ptr = bmpData.Scan0;
                // Get the address of the first line.


                int bytes = Math.Abs(bmpData.Stride) * bm.Height;
                if (rgbValues == null)
                {
                    rgbValues = new byte[bytes];
                }

                int       rgbValuesIndex = 0;
                Stopwatch sw             = Stopwatch.StartNew();

                for (int Xi = 0; Xi <= 255; Xi++)
                {
                    vX.SetValue((Xi - 128) * mult);
                    for (int Yi = 0; Yi <= 255; Yi++)
                    {
                        vY.SetValue((Yi - 128) * mult);

                        rgbValues[rgbValuesIndex++] = ZeroTo255(lCodeR.ObjectValue);
                        rgbValues[rgbValuesIndex++] = ZeroTo255(lCodeG.ObjectValue);
                        rgbValues[rgbValuesIndex++] = ZeroTo255(lCodeB.ObjectValue);
                    }
                }

                Label1.Text = ("196,608 evaluations run in " + (sw.ElapsedMilliseconds + " ms"));

                // Copy the RGB values back to the bitmap
                System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
            }
            catch (Exception ex)
            {
                Label1.Text = ex.Message;
            }
            finally
            {
                if (bmpData != null)
                {
                    bm.UnlockBits(bmpData);
                }
                if (lCodeR != null)
                {
                    lCodeR.Dispose();
                }
                if (lCodeG != null)
                {
                    lCodeG.Dispose();
                }
                if (lCodeB != null)
                {
                    lCodeB.Dispose();
                }
                PictureBox1.Image = bm;
                using (var gr = PictureBox1.CreateGraphics())
                {
                    gr.DrawImageUnscaled(bm, 0, 0);
                }
            }
        }