Exemplo n.º 1
0
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Create Fractal functions

    Texture2D createFractal()
    {
        Texture2D fractal = new Texture2D(width, height);

        float[] x_points = linspace(x_min, x_max, width), y_points = linspace(y_min, y_max, height);
        Complex z, c;
        float   count = 0, color_inside_value = 1f, r, g, b;

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                z     = new Complex(0, 0);
                c     = new Complex(x_points[i], y_points[j]);
                count = 0;

                for (int k = 0; k < max_iteration; k++)
                {
                    z = z * z + c;
                    // z =  (z + c) * Complex.Tan(z + c) * Complex.Sin(z + c);

                    if (Complex.Abs(z) > escape_radius)
                    {
                        break;
                    }

                    count++;
                }

                if (color_inside)
                {
                    color_inside_value = (float)Complex.Abs(z);
                }
                else
                {
                    color_inside_value = 1f;
                }

                if (modify_outside_color && Complex.Abs(z) > escape_radius)
                {
                    r = count / (float)max_iteration * color_inside_value * percentage_outside_r;
                    g = count / (float)max_iteration * color_inside_value * percentage_outside_g;
                    b = count / (float)max_iteration * color_inside_value * percentage_outside_b;
                }
                else
                {
                    r = count / (float)max_iteration * color_inside_value * percentage_r;
                    g = count / (float)max_iteration * color_inside_value * percentage_g;
                    b = count / (float)max_iteration * color_inside_value * percentage_b;
                }
                fractal.SetPixel(i, j, new Color(r, g, b));
            }
        }

        return(fractal);
    }
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Create Fractal functions

    void createFractal()
    {
        float[] x_points = linspace(x_min, x_max, width), y_points = linspace(y_min, y_max, height);
        Complex z, c;
        float   count = 0;

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                z     = new Complex(0, 0);
                c     = new Complex(x_points[i], y_points[j]);
                count = 0;

                // if(i < 10 && j < 10) print(c);

                for (int k = 0; k < max_iteration; k++)
                {
                    z = z * z + c;

                    if (Complex.Abs(z) > 4)
                    {
                        //print(count);
                        break;
                    }

                    count++;
                }
                //print(count);
                // fractal.SetPixel(i, j, new Color(count/255f, 0f, 0f));

                fractal.SetPixel(i, j, new Color(count / 255f * (float)Complex.Abs(z), count / 255f * (float)Complex.Abs(z), count / 255f * (float)Complex.Abs(z)));
                // fractal.SetPixel(i, j, new Color(count/255f * (float)Complex.Abs(z), (float)Complex.Abs(z), (float)Complex.Abs(z)));
            }
        }

        fractal.Apply();
    }
Exemplo n.º 3
0
 public static double Abs(this Complex self)
 {
     return(Complex.Abs(self));
 }
Exemplo n.º 4
0
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test methods

    Texture2D createFractalV2()
    {
        Texture2D fractal = new Texture2D(width, height);

        float[,] r = new float[width, height], g = new float[width, height], b = new float[width, height];

        float[] x_points = linspace(x_min, x_max, width), y_points = linspace(y_min, y_max, height);
        Complex z, c;
        float   count = 0, color_inside_value = 1f, tmp_r, tmp_g, tmp_b;

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                z     = new Complex(0, 0);
                c     = new Complex(x_points[i], y_points[j]);
                count = 0;

                for (int k = 0; k < max_iteration; k++)
                {
                    z = z * z + c;
                    // z =  (z + c) * Complex.Tan(z + c) * Complex.Sin(z + c);

                    if (Complex.Abs(z) > escape_radius)
                    {
                        break;
                    }

                    count++;
                }

                if (color_inside)
                {
                    color_inside_value = (float)Complex.Abs(z);
                }
                else
                {
                    color_inside_value = 1f;
                }

                tmp_r = count / (float)max_iteration * color_inside_value * percentage_r;
                tmp_g = count / (float)max_iteration * color_inside_value * percentage_g;
                tmp_b = count / (float)max_iteration * color_inside_value * percentage_b;

                r[i, j] = tmp_r;
                g[i, j] = tmp_g;
                b[i, j] = tmp_b;
            }
        }

        r = normalize(r);
        b = normalize(b);
        g = normalize(g);

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                // if(i < 10 & j < 10) print("r = " + r[i, j] + "g = " + g[i,j] + "b = " + b[i,j]);
                fractal.SetPixel(i, j, new Color(r[i, j], g[i, j], b[i, j]));
            }
        }

        return(fractal);
    }
 public void Abs_returns_correct_result()
 {
     NumericTestUtils.AssertAreEqual(Math.Sqrt(5), Complex.Abs(_c1));
 }