Пример #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
        private Bitmap combineBitmaps(ProgressForm pf)
        {
            double[] map1 = loadHeightValuesFromData(mcop.map1Path);
            double[] map2 = loadHeightValuesFromData(mcop.map2Path);

            double[] finalMap = new double[map1.Length];

            bool shouldNormalize = mcop.normalize;

            clarity = mcop.clarity;

            ct = mcop.colorTone;

            setComboFunc();

            Bitmap combinedBitmap = new Bitmap(Width, Height);

            double min = double.MaxValue;
            double max = double.MinValue;

            double map1OpacityFinal = mcop.map1UsingOpacity ? mcop.map1Opacity : 1;
            double map2OpacityFinal = mcop.map2UsingOpacity ? mcop.map2Opacity : 1;

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    double a = map1[i * Height + j] * map1OpacityFinal;
                    double b = map2[i * Height + j] * map2OpacityFinal;

                    finalMap[i * Height + j] = comboFunc(a, b);

                    if (finalMap[i * Height + j] < min)
                    {
                        min = finalMap[i * Height + j];
                    }
                    if (finalMap[i * Height + j] > max)
                    {
                        max = finalMap[i * Height + j];
                    }
                }

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

            pixels = new MapPixel[Width * Height];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (shouldNormalize)
                    {
                        finalMap[i * Height + j] = normalize(finalMap[i * Height + j], min, max);
                        pixels[i * Height + j]   = new MapPixel(i, j, finalMap[i * Height + j]);
                    }

                    combinedBitmap.SetPixel(i, j, ColorScheme.assignColorFromValue(finalMap[i * Height + j], ct, clarity));
                }

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

            return(combinedBitmap);
        }