Exemplo n.º 1
0
        /// <summary>
        /// Creates a deep copy.
        /// </summary>
        public override PlotItem Clone()
        {
            Function2D item = new Function2D();

            item.CopyFrom(this);
            return(item);
        }
Exemplo n.º 2
0
        private bool GetZBitmap()
        {
            Function2D f = null;

            for (int i = 0; i < Model.Items.Count; i++)
            {
                if (Model.Items[i] is Function2D)
                {
                    f = (Function2D)Model.Items[i];
                }
            }
            if (f != null)
            {
                if (f.rgb && (zscale.img == null || !zscale.rgb || fd != zscale.w || fh != zscale.h))
                {
                    zscale.w   = fd; zscale.h = fh;
                    zscale.img = new Bitmap(zscale.w, zscale.h);
                    for (int y = 0; y < zscale.h; y++)
                    {
                        for (int x = 0; x < zscale.w; x++)
                        {
                            zscale.img.SetPixel(x, zscale.h - 1 - y, f.RGBColor(((double)y) / zscale.h));
                        }
                    }
                }
                else if (!f.rgb && (zscale.img == null || zscale.rgb || f.Color != zscale.color ||
                                    fd != zscale.w || fh != zscale.h))
                {
                    zscale.w   = fd; zscale.h = fh;
                    zscale.img = new Bitmap(zscale.w, zscale.h);
                    for (int y = 0; y < zscale.h; y++)
                    {
                        for (int x = 0; x < zscale.w; x++)
                        {
                            zscale.img.SetPixel(x, zscale.h - 1 - y, f.FColor(((double)y) / zscale.h));
                        }
                    }
                }
                zscale.color = f.Color;
                zscale.rgb   = f.rgb;
            }
            return(f != null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the bounds of the plotting area inside the control.
        /// </summary>
        /// <param name="g">A Graphics object.</param>
        /// <param name="bounds">The bounds of the entire control.</param>
        private void CalcFrame(Graphics g, Rectangle bounds)
        {
            int    w = 0, h = 0, ww, wz = 0, n, W, H;
            double y0 = Model.y0, y1 = Model.y1, x0 = Model.x0, x1 = Model.x1, z0 = Model.z0, z1 = Model.z1,
                   rx = Model.rx, ry = Model.ry, rz = Model.rz,
                   dy = (y1 - y0) / bounds.Height, dz = (z1 - z0) / bounds.Height, x, y, z;
            SizeF  size;
            string label;
            float  Y, Z;

            y    = 0.5;
            size = g.MeasureString(y.ToString(GraphModel.NumberFormat(Model.xDigits, Model.xNumberStyle)),
                                   Model.ScaleFont);
            fd = (int)(size.Height + 0.5F);

            if (Model.Border)
            {
                if (Model.yScale)
                {
                    y = Math.Floor(y0 / ry) * ry;
                    n = 1;
                    while ((y + n * ry) < y1)
                    {
                        Y = bounds.Height - 1 - (float)((y + n * ry - y0) / dy);
                        if ((int)(bounds.Height - 1 - (float)(-y0 / dy) + 0.5F) == (int)(Y + 0.5F))
                        {
                            label = "0";
                        }
                        else
                        {
                            label = (y + n * ry).ToString(GraphModel.NumberFormat(Model.yDigits, Model.yNumberStyle));
                        }
                        size = g.MeasureString(label, Model.ScaleFont);
                        w    = Math.Max(w, (int)(size.Width + 0.5));
                        n++;
                    }
                }
                else
                {
                    w = 0;
                }

                if (Model.xScale)
                {
                    h     = fd;
                    x     = Math.Floor(x1 / rx) * rx;
                    label = x.ToString(GraphModel.NumberFormat(Model.xDigits, Model.xNumberStyle));
                    size  = g.MeasureString(label, Model.ScaleFont);
                    ww    = (int)(size.Width / 2 + 1);
                }
                else
                {
                    ww = 0;
                }

                if (Model.zScale)
                {
                    Function2D f = null;
                    for (int i = 0; i < Model.Items.Count; i++)
                    {
                        if (Model.Items[i] is Function2D)
                        {
                            f = (Function2D)Model.Items[i];
                        }
                    }
                    if (f != null)
                    {
                        z = Math.Floor(z0 / rz) * rz;
                        n = 1;
                        while ((z + n * rz) < z1)
                        {
                            Z = bounds.Height - 1 - (float)((z + n * rz - z0) / dz);
                            if ((int)(bounds.Height - 1 - (float)(-z0 / dz) + 0.5F) == (int)(Z + 0.5F))
                            {
                                label = "0";
                            }
                            else
                            {
                                label = (z + n * rz).ToString(GraphModel.NumberFormat(Model.zDigits, Model.zNumberStyle));
                            }
                            size = g.MeasureString(label, Model.ScaleFont);
                            wz   = Math.Max(wz, (int)(size.Width + 0.5));
                            n++;
                        }
                        wz += 3 * fd + D;
                    }
                    else
                    {
                        wz = 0;
                    }
                }
                else
                {
                    wz = 0;
                }

                fx = w + D;
                fy = D / 2 + fd / 2;
                W  = bounds.Width - w - (3 * D) / 2 - ww - wz;
                H  = bounds.Height - h - fd / 2 - (3 * D) / 2;
                if (W != fw && FixYtoX)
                {
                    fw = W; fh = H;
                    Model.SetRange(x0, x1, y0, y1, fw, fh);
                }
                fw = W; fh = H;
            }
            else
            {
                fx = bounds.X; fy = bounds.Y; fw = bounds.Width - 1; fh = bounds.Height - 2;
            }
        }
Exemplo n.º 4
0
		/// <summary>
		/// Creates a deep copy.
		/// </summary>
		public override PlotItem Clone() {
			Function2D item = new Function2D();
			item.CopyFrom(this);
			return item;
		}
Exemplo n.º 5
0
 private void UpdateGraph()
 {
     var cFunction = new Function2D { source = _function};
     cFunction.Compile(true);
     cFunction.lineWidth = 0.001F;
     cFunction.Color = Color.DeepSkyBlue;
     graph.Model.Items.Add(cFunction);
 }
Exemplo n.º 6
0
		private void mandelbrotClick(object sender, System.EventArgs e) {
			Function2D m = new Function2D();
			//The source represents the body of the following function:
			//double[] p, dfdp;
			//double f(double x, double y) {
			//  ...
			//}
			m.source = "double xn = 0, yn = 0, x2 = 0, y2 = 0;" +
				"for (int n = 0; n < 500; n++) {" +
				"  yn = 2*xn*yn + y;" +
				"  xn = x2 - y2 + x;" +
				"  x2 = xn*xn; y2 = yn*yn;" + 
				"  if (x2 + y2 > 4) return n;" +
				"} return 0;";
				m.Compile(true);
			graph.SetRange(graph.x0, graph.x1, graph.y0, graph.y1, 0, 20);  
			graph.Model.Items.Add(m);
			graph.Invalidate();
		}