示例#1
0
        public virtual Bitmap generateImage(ProgressForm pf = null)
        {
            if (cop.variablesSet(Width, Height) == true)
            {
                retrieveVariables();
            }
            else
            {
                return(prevImage);
            }

            if (isRepeatedSetup())
            {
                return(prevImage);
            }
            else if (onlyDifferentColorScheme() && prevImage != null)
            {
                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        prevImage.SetPixel(i, j, ColorScheme.assignColorFromValue(pixels[i * Height + j].Height, ct, clarity));
                    }

                    if (pf != null)
                    {
                        pf.ProgressBarValue += Height;
                    }
                }

                return(prevImage);
            }
            else if (onlyDifferentElevation())
            {
                for (int i = 0; i < Width; i++)
                {
                    for (int j = 0; j < Height; j++)
                    {
                        pixels[i * Height + j].heightOffset = mapHeight * NORMALIZED_MAP_FOOT_REAL;
                        prevImage.SetPixel(i, j, ColorScheme.assignColorFromValue(pixels[i * Height + j].Height, ct, clarity));
                    }

                    if (pf != null)
                    {
                        pf.ProgressBarValue += Height;
                    }
                }

                return(prevImage);
            }

            string[,] nums = new string[Width, Height];

            if (seed < 0)
            {
                seed *= -1;
            }

            Bitmap bm = new Bitmap(Width, Height);

            pixels = new MapPixel[Width * Height];

            Graphics g = Graphics.FromImage(bm);

            g.FillRectangle(Brushes.Black, 0, 0, Width, Height);

            if (ng == null)
            {
                ng = new ImprovedNoise();
            }

            ng.setSeed(seed);

            double[,] noiseMap = new double[Width, Height];
            noiseMax           = Double.MinValue;
            noiseMin           = Double.MaxValue;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    // get the current x and y
                    double dx = (double)((i) + xOffset) * .999999999999999;
                    double dy = (double)((j) + yOffset) * .999999999999999;
                    double dz = (double)((dx / 2 + dy / 4)) * .999999999999999;

                    if (cop.usingWorleyNoise)
                    {
                        dx = i;
                        dy = j;
                        dz = 9;
                    }

                    // original method WORKS FINE
                    //double noise = ng.octaveNoise(dx * biomeVar, dy * biomeVar, .1996 * biomeVar, octaves, frequency,
                    //	lacunarity, amplitude, persistence, scale, seed);

                    double noise = ng.octaveNoise(dx, dy, dz, octaves, frequency,
                                                  lacunarity, amplitude, persistence, scale, seed);

                    noise *= biomeVar;

                    if (noise > noiseMax)
                    {
                        noiseMax = noise;
                    }
                    if (noise < noiseMin)
                    {
                        noiseMin = noise;
                    }

                    noiseMap[i, j] = noise;
                }

                if (pf != null)
                {
                    pf.ProgressBarValue += Height;
                }
            }

            heightNums = new string[Width * Height];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    // normalize the noisemap value
                    noiseMap[i, j] = normalize(noiseMap[i, j], noiseMin, noiseMax);

                    // after normalizing the noisemap value, adjust it to fit the biome
                    noiseMap[i, j] = biomeFunction(noiseMap[i, j], i, j);

                    pixels[i * Height + j] = new MapPixel(i, j, noiseMap[i, j], mapHeight * NORMALIZED_MAP_FOOT_REAL);

                    noiseMap[i, j] = pixels[i * Height + j].Height;

                    // set the pixel in the bitmap with the final value
                    bm.SetPixel(i, j, ColorScheme.assignColorFromValue(noiseMap[i, j], ct, clarity));

                    // save the final value of the pixel to print to log later
                    heightNums[i * Height + j] += noiseMap[i, j].ToString();
                }

                if (pf != null)
                {
                    pf.ProgressBarValue += Height;
                }
            }

            prevImage = bm;

            // set the newly created bitmap as the map image
            return(bm);
        }
示例#2
0
        public void distributeCellPoints()
        {
            points = new List <CellPoint>();

            Random rand = new Random();

            NoiseGenerator osn = new ImprovedNoise();

            osn.setSeed(seed);

            string str = "";

            //MessageBox.Show(numPoints.ToString());

            for (int i = 0; i < numPoints; i++)
            {
                double xPos = (seed * 42069.5 / 1996) * (i + 9);
                double yPos = (seed * 42069.5 / 1996) * (i + 9);
                double zPos = (seed * 42069.5 / 1996) * (i + 9);

                uint ux = (uint)xPos;
                uint uy = (uint)yPos;
                uint uz = (uint)zPos;

                ux = ux & 0xFFc;
                uy = uy & 0xFFa;
                uz = uz & 0xFFc;

                xPos = ux * 10000 / 9.3;
                yPos = uy * 10000 / 9.3;
                zPos = uz * 10000 / 9.3;

                xPos = (osn.octaveNoise((xPos), .1996, yPos, 1, 16, 2.0, .35, 33, 1, seed) * 1000000);
                yPos = (osn.octaveNoise((yPos), .1996, xPos, 1, 16, 2.0, .35, 33, 1, seed) * 1000000);
                zPos = (osn.octaveNoise((xPos), (yPos), .1996, 8, 16, 2.0, .35, 33, 1, seed) * 1000000);

                str += "prep: " + (new CellPoint((double)xPos, (double)yPos)).ToString() + "\n";

                int x = ((int)(xPos)) % mapWidth;
                int y = ((int)(yPos)) % mapHeight;
                int z = (int)(zPos);

                str += "pre: " + (new CellPoint((double)x, (double)y)).ToString() + "\n";

                if (x < 0)
                {
                    x *= -1;
                    x %= mapWidth;
                }

                if (y < 0)
                {
                    y *= -1;
                    y %= mapHeight;
                }

                str += (new CellPoint((double)x, (double)y)).ToString() + "\n";

                points.Add(new CellPoint((double)x, (double)y));
            }

            //MessageBox.Show(str);
        }