Exemple #1
0
        private double Generate(double x)
        {
            int    i0 = SimplexUtil.Floor(x);
            int    i1 = i0 + 1;
            double x0 = x - i0;
            double x1 = x0 - 1.0d;

            double n0;
            double n1;

            double t0 = 1.0d - x0 * x0;

            t0 *= t0;
            n0  = t0 * t0 * SimplexUtil.Grad(perm[i0 & 0xff], x0);

            double t1 = 1.0d - x1 * x1;

            t1 *= t1;
            n1  = t1 * t1 * SimplexUtil.Grad(perm[i1 & 0xff], x1);
            return(0.395d * (n0 + n1));
        }
Exemple #2
0
        private double Generate(double x, double y)
        {
            double n0;
            double n1;
            double n2;

            double s  = (x + y) * F2;
            double xs = x + s;
            double ys = y + s;
            int    i  = SimplexUtil.Floor(xs);
            int    j  = SimplexUtil.Floor(ys);

            double t  = (i + j) * G2;
            double X0 = i - t;
            double Y0 = j - t;
            double x0 = x - X0;
            double y0 = y - Y0;

            int i1;
            int j1;

            if (x0 > y0)
            {
                i1 = 1;
                j1 = 0;
            }
            else
            {
                i1 = 0;
                j1 = 1;
            }

            double x1 = x0 - i1 + G2;
            double y1 = y0 - j1 + G2;
            double x2 = x0 - 1.0d + 2.0d * G2;
            double y2 = y0 - 1.0d + 2.0d * G2;

            int ii = SimplexUtil.Mod(i, 256);
            int jj = SimplexUtil.Mod(j, 256);

            double t0 = 0.5d - x0 * x0 - y0 * y0;

            if (t0 < 0.0d)
            {
                n0 = 0.0d;
            }
            else
            {
                t0 *= t0;
                n0  = t0 * t0 * SimplexUtil.Grad(perm[ii + perm[jj]], x0, y0);
            }

            double t1 = 0.5d - x1 * x1 - y1 * y1;

            if (t1 < 0.0d)
            {
                n1 = 0.0d;
            }
            else
            {
                t1 *= t1;
                n1  = t1 * t1 * SimplexUtil.Grad(perm[ii + i1 + perm[jj + j1]], x1, y1);
            }

            double t2 = 0.5d - x2 * x2 - y2 * y2;

            if (t2 < 0.0d)
            {
                n2 = 0.0d;
            }
            else
            {
                t2 *= t2;
                n2  = t2 * t2 * SimplexUtil.Grad(perm[ii + 1 + perm[jj + 1]], x2, y2);
            }

            return(40.0d * (n0 + n1 + n2));
        }