Ejemplo n.º 1
0
        public static void Mandelbrot(PlotControl plot)
        {
            // Here we add the Mandelbrot set to the plot.

            Function2DItem m = new Function2DItem(
                // The source represents the body of the following function:
                // double[] p, dfdp;
                // double f(double x, double y) {
                //   ...
                // }
                @"
					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 -1;
				"                );

            plot.Model.FixXtoY = true;             // We fix the x-plotrange to the y-plotrange, so the
            // proportions of the plot will be correct.
            plot.SetRange(plot.x0, plot.x1, plot.y0, plot.y1, 0, 20);
            // We set the view range of the plot, so the Mandelbrot set will be
            // fully visible. We set the z-plotrange from 0 to 20.
            plot.Model.Add(m);
        }
Ejemplo n.º 2
0
    void CreateMandelbrot()
    {
        Function2DItem mandelbrot = new Function2DItem();         // create a new 2D function

        //The source below represents the body of the following function:
        //double[] p, dfdp;
        //double f(double x, double y) {
        //  ...
        //}
        //The array p is an array of function parameters (that can be fitted for).
        //dfdp is an array of the derivatives of the function
        //(this array is also used for fitting).

        mandelbrot.Source = @"
			double xn = 0, yn = 0, x2 = 0, y2 = 0;
			for (int n = 0; n < p[0]; n++) {
				yn = 2*xn*yn + y;
				xn = x2 - y2 + x;
				x2 = xn*xn; y2 = yn*yn;
				if (x2 + y2 > 4) return n;
			}
			return -1;
		"        ;
        mandelbrot.Compile();                              // compile the function
        mandelbrot.p[0]     = 500;                         // set the maximum of iterations value to 500
        mandelbrot.Gradient = new RainbowGradient();       // sets the color gradient used to plot the function to a rainbow gradient.

        plot2.Model.SetRange(-2.3, 1.3, -1.3, 1.3, 0, 20); // sets the plot range.
        plot2.Model.FixXtoY = true;                        // set FixXtoY to true, so x- and y-scale will be proportional.
        plot2.Model.Add(mandelbrot);
    }
Ejemplo n.º 3
0
 public void Reset()
 {
     if (oldItem == null)
     {
         dimensions   = Dimensions.One;
         fSource.Text = "return 0;";
     }
     else
     {
         if (oldItem is Function1DItem)
         {
             SetDimensions(Dimensions.One);
         }
         else if (oldItem is Function2DItem)
         {
             SetDimensions(Dimensions.Two);
         }
         else if (oldItem is FunctionColorItem)
         {
             SetDimensions(Dimensions.TwoColor);
         }
         else
         {
             throw new System.ApplicationException("invalid item-type");
         }
         name.Text = oldItem.Name;
         this.Text = oldItem.Name;
         if (oldItem is Function1DItem)
         {
             Function1DItem f1 = (Function1DItem)oldItem;
             fSource.Text    = f1.Source;
             style.Color     = f1.Color;
             style.LineWidth = f1.LineWidth;
             style.LineStyle = f1.LineStyle;
         }
         else if (oldItem is Function2DItem)
         {
             Function2DItem f1 = (Function2DItem)oldItem;
             fSource.Text = f1.Source;
             Gradient     = f1.Gradient;
         }
         else if (oldItem is FunctionColorItem)
         {
             FunctionColorItem f1 = (FunctionColorItem)oldItem;
             fSource.Text = f1.Source;
         }
     }
 }
Ejemplo n.º 4
0
        private void CreateF()
        {
            float lw;

            if (!float.TryParse(lineWidth.Text, out lw))
            {
                lw = 1;
            }
            if (dimensions == Dimensions.One)
            {
                Function1DItem f1 = new Function1DItem();
                f1.Source    = fSource.Text;
                f1.LineStyle = style.LineStyle;
                f1.LineWidth = style.LineWidth;
                f1.Color     = style.Color;
                f            = f1;
            }
            else if (dimensions == Dimensions.Two)
            {
                Function2DItem f1 = new Function2DItem();
                f1.Source   = fSource.Text;
                f1.Gradient = Gradient;
                f           = f1;
            }
            else
            {
                FunctionColorItem f1 = new FunctionColorItem();
                f1.Source = fSource.Text;
                f         = f1;
            }
            f.Name    = name.Text;
            this.Text = name.Text;
            if (oldItem != null)
            {
                f.p = oldItem.p.Clone();
            }
        }