예제 #1
0
        static void getBounds2D(int[,] bounds, int tolerance, int[,] seed, uint xx, uint yy, int depth, int min, int max)
        {
            int[,] data = new int[3, 3];
            int[,] seeds = new int[3, 3];
            data[0, 0] = bounds[0, 0];
            data[2, 0] = bounds[1, 0];
            data[0, 2] = bounds[0, 1];
            data[2, 2] = bounds[1, 1];
            seeds[0, 0] = seed[0, 0];
            seeds[2, 0] = seed[1, 0];
            seeds[0, 2] = seed[0, 1];
            seeds[2, 2] = seed[1, 1];
            FastRandom r = new FastRandom();

            r.Reinitialise(seeds[2, 0] + depth);
            r.Next();
            r.Next();
            int l = seeds[2, 1] = r.Next();
            l = toggleMode((data[2, 0] + data[2, 2]) / 2, l, tolerance, min, max);
            data[2, 1] = l;

            r.Reinitialise(seeds[0, 2] + depth);
            r.Next();
            int u = seeds[1, 2] = r.Next();
            u = toggleMode((data[0, 2] + data[2, 2]) / 2, u, tolerance, min, max);
            data[1, 2] = u;

            r.Reinitialise(seeds[0, 0] + depth);
            int ul = data[0, 0];
            int ur = data[2, 0];
            int dl = data[0, 2];
            int dr = data[2, 2];
            int m = seeds[1, 1] = r.Next();
            u = seeds[1, 0] = r.Next();
            l = seeds[0, 1] = r.Next();
            m = toggleMode((ul + ur + dl + dr) / 4, m, tolerance, min, max);
            u = toggleMode((ul + ur) / 2, u, tolerance, min, max);
            l = toggleMode((ul + dl) / 2, l, tolerance, min, max);
            data[1, 1] = m;
            data[1, 0] = u;
            data[0, 1] = l;

            bounds[0, 0] = data[xx, yy];
            bounds[1, 0] = data[xx + 1, yy];
            bounds[0, 1] = data[xx, yy + 1];
            bounds[1, 1] = data[xx + 1, yy + 1];
            seed[0, 0] = seeds[xx, yy];
            seed[1, 0] = seeds[xx + 1, yy];
            seed[0, 1] = seeds[xx, yy + 1];
            seed[1, 1] = seeds[xx + 1, yy + 1];
            return;
        }
예제 #2
0
        static int[,] getData2D(int[,] bounds, int depth, int tolerance, int[,] seed, int sizeExp, int min, int max)
        {
            int totalSize, segmentSize, count = 1;
            totalSize = segmentSize = 1 << depth;
            int[,] data = new int[totalSize + 1, totalSize + 1];
            int[,] seeds = new int[totalSize + 1, totalSize + 1];
            data[0, 0] = bounds[0, 0];
            data[totalSize, 0] = bounds[1, 0];
            data[0, totalSize] = bounds[0, 1];
            data[totalSize, totalSize] = bounds[1, 1];
            seeds[0, 0] = seed[0, 0];
            seeds[totalSize, 0] = seed[1, 0];
            seeds[0, totalSize] = seed[0, 1];
            seeds[totalSize, totalSize] = seed[1, 1];
            FastRandom r = new FastRandom();
            while (segmentSize != 1)
            {
                for (int y = 0; y < count; y++)
                {
                    r.Reinitialise(seeds[totalSize, y * segmentSize] + sizeExp);

                    int ul = data[totalSize, y * segmentSize];
                    int dl = data[totalSize, (y + 1) * segmentSize];

                    r.Next();
                    r.Next();
                    int l = seeds[totalSize, y * segmentSize + segmentSize / 2] = r.Next();
                    l = toggleMode((ul + dl) / 2, l, tolerance, min, max);
                    data[totalSize, y * segmentSize + segmentSize / 2] = l;
                }
                for (int x = 0; x < count; x++)
                {
                    r.Reinitialise(seeds[x * segmentSize, totalSize] + sizeExp);

                    int ul = data[x * segmentSize, totalSize];
                    int ur = data[(x + 1) * segmentSize, totalSize];

                    r.Next();
                    int u = seeds[x * segmentSize + segmentSize / 2, totalSize] = r.Next();
                    u =  toggleMode((ul + ur) / 2 ,u, tolerance, min, max);
                    data[x * segmentSize + segmentSize / 2, totalSize] = u;
                }

                for (int y = 0; y < count; y++)
                    for (int x = 0; x < count; x++)
                    {
                        r.Reinitialise(seeds[x * segmentSize, y * segmentSize] + sizeExp);

                        int ul = data[x * segmentSize, y * segmentSize];
                        int ur = data[(x + 1) * segmentSize, y * segmentSize];
                        int dl = data[x * segmentSize, (y + 1) * segmentSize];
                        int dr = data[(x + 1) * segmentSize, (y + 1) * segmentSize];

                        int m = seeds[x * segmentSize + segmentSize / 2, y * segmentSize + segmentSize / 2] = r.Next();
                        int u = seeds[x * segmentSize + segmentSize / 2, y * segmentSize] = r.Next();
                        int l = seeds[x * segmentSize, y * segmentSize + segmentSize / 2] = r.Next();
                        m = toggleMode((ul + ur + dl + dr) / 4, m, tolerance, min, max);
                        u = toggleMode((ul + ur) / 2, u, tolerance, min, max);
                        l = toggleMode((ul + dl) / 2, l, tolerance, min, max);
                        data[x * segmentSize + segmentSize / 2, y * segmentSize + segmentSize / 2] = m;
                        data[x * segmentSize + segmentSize / 2, y * segmentSize] = u;
                        data[x * segmentSize, y * segmentSize + segmentSize / 2] = l;
                    }
                tolerance = getTolerance(tolerance);
                segmentSize /= 2;
                count *= 2;
                sizeExp--;
            }
            return data;
        }