コード例 #1
0
ファイル: WndSample.cs プロジェクト: yoonian/muparsersse
      private void CalculateMultiThread(object s)
      {
        CalcState cs = s as CalcState;
        float mult = 2 * (float)Math.PI / (float)256.0;
        int index = 0;

        // Set up parser variables
        Parser p = cs.Parser;
        ParserVariable x = new ParserVariable(0);
        ParserVariable y = new ParserVariable(0);
        p.DefineVar("x", x);
        p.DefineVar("y", y);

        Parser.CompiledFunDelegate fun = p.Compile();

        // Do the actual looping for a single colorplane
        float v;
        for (int yi = 0; yi < pbImage.Height; ++yi)
        {
          y.Value = (yi - 128) * mult;
          for (int xi = 0; xi < pbImage.Width; ++xi)
          {
            x.Value = (xi - 128) * mult;

            //v = GetColorComponent(p.Eval());
            v = GetColorComponent(fun());
            m_data[index + cs.Offset] = (byte)(v * 255);
            index += 3;
          }
        }

        cs.Reset.Set();
      }
コード例 #2
0
ファイル: WndSample.cs プロジェクト: yoonian/muparsersse
      private void Calc(String expr)
      {
        try
        {
          m_history.Add(expr);

          meHistory.SelectionColor = System.Drawing.Color.Blue;
          meHistory.AppendText(expr);
          meHistory.AppendText("\r\n");
          meHistory.SelectionColor = System.Drawing.Color.Black;

          m_parser.SetDecSep(cbDec.Text.ToCharArray()[0]); // default: "."
          m_parser.SetArgSep(cbArg.Text.ToCharArray()[0]); // default: ","
          m_parser.SetExpr(expr);

          Parser.CompiledFunDelegate fun = m_parser.Compile();
          m_ans.Value = fun();
          //m_ans.Value = m_parser.Eval();

          string result = Convert.ToString(m_ans.Value);
          meHistory.AppendText(String.Format("{0} = ", m_parser.GetExpr()));
          meHistory.AppendText(result);
          meHistory.AppendText("\r\n");
        }
        catch (ParserException exc)
        {
          DumpException(exc);
        }
      }