Exemplo n.º 1
0
        private void DrawGraph()
        {
            LinkedList <Point> pointList = new LinkedList <Point>();
            var script = Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.Create <double>(TextBox.Text, Microsoft.CodeAnalysis.Scripting.ScriptOptions.Default.WithImports("System.Math").WithReferences(typeof(parameters).AssemblyQualifiedName), typeof(parameters));

            Microsoft.CodeAnalysis.Scripting.ScriptRunner <double> fun = script.CreateDelegate();
            for (int i = 0; i < DrawGrid.ActualWidth; i += 4)
            {
                double ax = (double)i / factor;
                var    y  = DrawGrid.ActualHeight / (2 * factor) - (fun.Invoke(new parameters()
                {
                    x = ax
                }).Result);
                pointList.AddLast(new Point(i, (int)(y * factor)));
            }

            var myPath = new Path
            {
                Stroke          = Brushes.Black,
                StrokeThickness = 4,
                Data            = Linearize(pointList)
            };

            DrawGrid.Children.Clear();
            DrawGrid.Children.Add(myPath);
            drawAxis();
        }
Exemplo n.º 2
0
        public void ParseExpression(string s, int h, int w, int factor)
        {
            pointList.Clear();
            var script = Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.Create <double>(s, Microsoft.CodeAnalysis.Scripting.ScriptOptions.Default.WithImports("System.Math").WithReferences(typeof(parameters).AssemblyQualifiedName), typeof(parameters));

            Microsoft.CodeAnalysis.Scripting.ScriptRunner <double> fun = script.CreateDelegate();
            for (int i = 0; i < w; i += 4)
            {
                double ax = (double)i / factor;
                //var st = $"x = {ax}";
                // st = st.Replace(",", ".");

                // Argument x = new Argument(st);
                // exp = new Expression(s, x);
                var y = h / 2 - (int)(fun.Invoke(new parameters()
                {
                    x = ax
                }).Result *factor);
                //var z = exp.calculate();
                AddPoint(new Point(i, y));
            }
        }