Esempio n. 1
0
 private void drawB_Click(object sender, EventArgs e) // WORKING
 {
     double[] x_tmp = getX(x1, x2, mapa.Width / 4 + 1);
     decimal[,] y_tmp = calculateY(x_tmp, functions, selF.ToArray());
     Point[,] p_tmp   = getPoints(x_tmp, y_tmp);
     ThreadHelperClass.SetText(this, integralLabel, "Integral: " + Integrate(x_tmp, y_tmp).ToString("0.#####E+000").TrimEnd('0').TrimEnd('-').TrimEnd('+').TrimEnd('E'));
     draw(false, p_tmp, y_tmp);
 }
Esempio n. 2
0
        private void calculations_DoWork(object sender, DoWorkEventArgs e)
        {
            //double integral = 0;
            for (int i = 0; i < asyncLength; ++i)
            {
                if (calculations.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                double[] x_tmp = getX(x1, x2, 2 << i + 1);
                decimal[,] y_tmp = calculateY(x_tmp, functions, selF.ToArray());

                Point[,] p_tmp = getPoints(x_tmp, y_tmp);

                ThreadHelperClass.SetText(this, integralLabel, "Integral: " + Integrate(x_tmp, y_tmp).ToString("0.#####E+000").TrimEnd('0').TrimEnd('-').TrimEnd('+').TrimEnd('E'));
                draw(true, p_tmp, y_tmp);

                calculations.ReportProgress((i + 1) * 10);

                Thread.Sleep(1000);
            }
        }
Esempio n. 3
0
        private void draw(bool async, Point[,] p, Decimal[,] y)
        {
            Pen pTmp = new Pen(Color.Red, (float)2);
            //Brush bTmp = new Brush();
            Brush    brush = new SolidBrush(Color.Red);
            Pen      rect  = new Pen(Color.Red, (float)1);
            Bitmap   bmp   = new Bitmap(mapa.Width, mapa.Height);
            Graphics gr    = mapa.CreateGraphics();
            Graphics rg    = Graphics.FromImage(bmp);

            rg.SmoothingMode     = SmoothingMode.AntiAlias;
            rg.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            rg.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

            if (y.GetLength(0) < 1)
            {
                ThreadHelperClass.SetText(this, maxLabel, "Max Y : ");
                ThreadHelperClass.SetText(this, minLabel, "Min Y : ");
                mapa.Image = null;
                return;
            }
            ThreadHelperClass.SetText(this, maxLabel, "Max Y : " + MAXY.ToString("0.###E+00").TrimEnd('0').TrimEnd('.').TrimEnd('-').TrimEnd('+').TrimEnd('E'));
            ThreadHelperClass.SetText(this, minLabel, "Min Y : " + MINY.ToString("0.###E+00").TrimEnd('0').TrimEnd('.').TrimEnd('-').TrimEnd('+').TrimEnd('E'));
            bool draw = false;

            for (int i = 0; i < selF.Count; ++i)
            {
                if (selF[i])
                {
                    draw = true;
                }
            }

            if (async)
            {
                if (draw)
                {
                    Decimal y0 = (MAXY - MINY) / 2 + MINY;
                    rg.DrawLine(new Pen(Color.Black, (float)1), conv(x1, 0), conv(x2, 0));
                }
                else
                {
                    MINY = -1;
                    MAXY = 1;
                    Decimal y0 = (MAXY - MINY) / 2 + MINY;

                    rg.DrawLine(new Pen(Color.Black, (float)1), new Point(0, conv(0, 0).Y), new Point(mapa.Width - 1, conv(0, 0).Y));
                }
            }
            if (y.GetLength(0) >= 1)
            {
                int dx = p[0, 1].X - p[0, 0].X;
                for (int i = 0; i < p.GetLength(0); ++i)
                {
                    pTmp.Color = colors[i];
                    rect.Color = Color.FromArgb(100, colors[i % colors.Count]);
                    brush      = new SolidBrush(Color.FromArgb(100, colors[i % colors.Count]));
                    for (int j = 0; j < p.GetLength(1); ++j)
                    {
                        rg.DrawEllipse(pTmp, p[i, j].X, p[i, j].Y, (float)1, (float)1);
                        if (j > 0)
                        {
                            rg.DrawLine(pTmp, p[i, j - 1], p[i, j]);
                            if (async)
                            {
                                int       x  = p[i, j - 1].X;
                                Decimal   yy = (y[i, j - 1] + y[i, j]) / 2;
                                Rectangle r  = new Rectangle();
                                r.X = x;

                                r.Width = dx;
                                if (r.Width == 0)
                                {
                                    r.Width = 1;
                                }
                                if (yy > 0)
                                {
                                    r.Y      = conv(0, yy).Y;
                                    r.Height = -conv(0, yy).Y + conv(0, 0).Y;
                                }
                                else
                                {
                                    r.Y      = conv(0, 0).Y;
                                    r.Height = -conv(0, 0).Y + conv(0, yy).Y;
                                }
                                rg.FillRectangle(brush, r);
                            }
                        }
                    }
                }
            }
            if (mapa.Image != null)
            {
                mapa.Image.Dispose();
            }
            mapa.Image = null;
            if (draw)
            {
                mapa.Image = (Image)bmp.Clone();
            }
            else
            {
                mapa.InitialImage = null;
            }

            pTmp.Dispose();
            rg.Dispose();
            bmp.Dispose();
            gr.Dispose();
        }